Skip to content

feat: Allow admins to access member workspace terminals #2114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 10, 2022

Conversation

AbhineetJain
Copy link
Contributor

@AbhineetJain AbhineetJain commented Jun 7, 2022

This PR allows the terminal/app access links shown on the workspace page to be used by the admin. Currently, the admins can open the link but the terminal opens with a web socket failure due to forbidden access.

Subtasks

  • allow admins (or members with workspace update access) to open and use terminal/app links from all organization workspaces.
  • do not show the terminal/app links to users without access.
  • add a story
  • update backend unit tests that check for access.

Fixes #1988

Screenshots

Other user

Screen Shot 2022-06-07 at 1 39 15 AM

Same user

Screen Shot 2022-06-07 at 1 39 24 AM

@AbhineetJain AbhineetJain requested a review from a team as a code owner June 7, 2022 05:34
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be wiser for us to actually allow administrators to access a developer terminal instead of this approach. Right now, the backend allows admins to delete workspaces for other users, so it seems silly they couldn't access them too.

Any thoughts here @bpmct? Curious for yours too @AbhineetJain!

@bpmct
Copy link
Member

bpmct commented Jun 7, 2022

There are cases for both. For now, I think it is best to keep this option enabled for admins. In Coder classic, many admins have built internal tooling to exec into workspaces and reproduce bugs. Having this as a first-class feature (when the agent works, of course) is a helpful utility.

Down the road, fine-grained permissions can be used to restrict this to 1 or 2 users or disable it entirely.

@kylecarbs
Copy link
Member

@AbhineetJain we may want to adjust the reconnecting PTY route to allow access in that case, then it all should just work.

@AbhineetJain
Copy link
Contributor Author

@AbhineetJain we may want to adjust the reconnecting PTY route to allow access in that case, then it all should just work.

@kylecarbs sounds good, I'll update the PR to do that.

@Emyrk
Copy link
Member

Emyrk commented Jun 7, 2022

Do we want to implement this as admins connecting to a user's workspace, or have admins "impersonate" the user, then access?

We talked about masquerading/impersonation as a feature before. That avenue seems to accomplish the same thing in a more general way? Keeping the codepath as "the owner" accessing. Once we get audit logs, it will show who actually is connecting.

@AbhineetJain AbhineetJain force-pushed the abhineetjain/1988-restrict-app-terminal-access branch from 08c4fd4 to 4ecfd7f Compare June 7, 2022 21:30
@AbhineetJain
Copy link
Contributor Author

@kylecarbs: @Emyrk and I worked together to set up the RBAC check for allowing terminal (or workspace agent) access to users with workspace update permissions. I am planning to block the access links in the UI for users without the workspace update permission, if this looks like a good approach. Alternatively, we might need to create a new resource for workspace agents and its own set of permissions.

@ammario
Copy link
Member

ammario commented Jun 7, 2022

This seems highly related to #2135 issue.

I don't understand why we would restrict it to the owner instead of relying on RBAC. RBAC is a lot more configurable. Also, we want to minimize assumptions about access in the frontend to avoid future bugs due to misalignment between backend and frontend. (Edit: I see we're aligned here)

I'm in favor of keeping the behavior as it is in main. The superadmin/root has full access to everyone's workspace, and we create a lesser admin role that is RBAC-restricted from workspace exec.

@ammario
Copy link
Member

ammario commented Jun 7, 2022

Another reason to have a user that can literally do anything is limitless automation.

@AbhineetJain AbhineetJain changed the title feat: Restrict access links to workspace owner feat: Allow admins to access member workspace terminals Jun 8, 2022
@AbhineetJain
Copy link
Contributor Author

@ammario The PR evolved and the original description was outdated. I've now updated the description.

In main, we are showing Open terminal links to admin users for member workspaces, but clicking on the link opens the terminal in a failed/disconnected state due to their access being forbidden.

We're now allowing users with the workspace update access as per RBAC to see the link and use the terminal, and hide the link for users without access.

@ammario
Copy link
Member

ammario commented Jun 8, 2022

@ammario The PR evolved and the original description was outdated. I've now updated the description.

In main, we are showing Open terminal links to admin users for member workspaces, but clicking on the link opens the terminal in a failed/disconnected state due to their access being forbidden.

We're now allowing users with the workspace update access as per RBAC to see the link and use the terminal, and hide the link for users without access.

Ah ok. Makes a lot of sense.

@Emyrk
Copy link
Member

Emyrk commented Jun 8, 2022

I want to mention the RBAC perm of "update workspace" is being used for now. If we have reason too, we can break this out into a new resource. Keeping the number of RBAC unique resources as few as possible at the moment.

@AbhineetJain AbhineetJain force-pushed the abhineetjain/1988-restrict-app-terminal-access branch 2 times, most recently from c05da12 to 158dd56 Compare June 9, 2022 18:20
@AbhineetJain
Copy link
Contributor Author

This should be almost ready. I am seeing this error in the console on the Workspace page though:

Machine given to `useMachine` has changed between renders. This is not supported and might lead to unexpected results.
Please make sure that you pass the same Machine as argument each time.

I am not sure what caused it, so can use some help there. @coder/frontend Any ideas?

if !ok {
panic("developer error: user roles middleware not provided")
}
return apiKey
return userRoles
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing previous debt!


ctx := context.WithValue(r.Context(), workspaceAgentParamContextKey{}, agent)
chi.RouteContext(ctx).URLParams.Add("workspace", build.WorkspaceID.String())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the workspace param here to check RBAC in the actual call.

@AbhineetJain AbhineetJain requested a review from a team June 9, 2022 18:34
appIcon={app.icon}
appName={app.name}
userName={workspace.owner_name}
{canUpdateWorkspace && (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see this living in its own component given the length of the file.

@Kira-Pilot
Copy link
Member

This should be almost ready. I am seeing this error in the console on the Workspace page though:

Machine given to `useMachine` has changed between renders. This is not supported and might lead to unexpected results.
Please make sure that you pass the same Machine as argument each time.

I am not sure what caused it, so can use some help there. @coder/frontend Any ideas?

@AbhineetJain I think maybe it is complaining because we are modifying workspace as we pass it in to the useMachine hook.
When we use that hook, could we try:

  const [workspaceState, workspaceSend] = useMachine(workspaceMachine, {
    context: {
      userId: me?.id,
    },
  })

That seems to clear out the warning on my end while still passing in the userId.

@AbhineetJain
Copy link
Contributor Author

This should be almost ready. I am seeing this error in the console on the Workspace page though:

Machine given to `useMachine` has changed between renders. This is not supported and might lead to unexpected results.
Please make sure that you pass the same Machine as argument each time.

I am not sure what caused it, so can use some help there. @coder/frontend Any ideas?

@AbhineetJain I think maybe it is complaining because we are modifying workspace as we pass it in to the useMachine hook. When we use that hook, could we try:

  const [workspaceState, workspaceSend] = useMachine(workspaceMachine, {
    context: {
      userId: me?.id,
    },
  })

That seems to clear out the warning on my end while still passing in the userId.

@Kira-Pilot It does indeed! Thank you so much. How'd you figure this out? 😄

@AbhineetJain AbhineetJain force-pushed the abhineetjain/1988-restrict-app-terminal-access branch from 08d1c34 to 252a6df Compare June 9, 2022 22:28
@Kira-Pilot
Copy link
Member

@AbhineetJain I found this example in the XState docs. They should really update the context section you and I looked at earlier. Glad it worked out!

@AbhineetJain AbhineetJain force-pushed the abhineetjain/1988-restrict-app-terminal-access branch from 252a6df to 4e69393 Compare June 10, 2022 13:59
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RBAC looks good. Perms should be good for admins and users

@AbhineetJain AbhineetJain merged commit 953e8c8 into main Jun 10, 2022
@AbhineetJain AbhineetJain deleted the abhineetjain/1988-restrict-app-terminal-access branch June 10, 2022 14:46
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
* allow workspace update permissions to access agents

* do not show app links to users without workspace update access

* address CR comments

* initialize machine context in the hook

* revert scoped connected status check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants