mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add organization scope for shared ports (#18314)
This commit is contained in:
@@ -258,7 +258,7 @@ func (p *DBTokenProvider) Issue(ctx context.Context, rw http.ResponseWriter, r *
|
||||
return &token, tokenStr, true
|
||||
}
|
||||
|
||||
// authorizeRequest returns true/false if the request is authorized. The returned []string
|
||||
// authorizeRequest returns true if the request is authorized. The returned []string
|
||||
// are warnings that aid in debugging. These messages do not prevent authorization,
|
||||
// but may indicate that the request is not configured correctly.
|
||||
// If an error is returned, the request should be aborted with a 500 error.
|
||||
@@ -310,7 +310,7 @@ func (p *DBTokenProvider) authorizeRequest(ctx context.Context, roles *rbac.Subj
|
||||
// This is not ideal to check for the 'owner' role, but we are only checking
|
||||
// to determine whether to show a warning for debugging reasons. This does
|
||||
// not do any authz checks, so it is ok.
|
||||
if roles != nil && slices.Contains(roles.Roles.Names(), rbac.RoleOwner()) {
|
||||
if slices.Contains(roles.Roles.Names(), rbac.RoleOwner()) {
|
||||
warnings = append(warnings, "path-based apps with \"owner\" share level are only accessible by the workspace owner (see --dangerous-allow-path-app-site-owner-access)")
|
||||
}
|
||||
return false, warnings, nil
|
||||
@@ -354,6 +354,27 @@ func (p *DBTokenProvider) authorizeRequest(ctx context.Context, roles *rbac.Subj
|
||||
if err == nil {
|
||||
return true, []string{}, nil
|
||||
}
|
||||
case database.AppSharingLevelOrganization:
|
||||
// Check if the user is a member of the same organization as the workspace
|
||||
// First check if they have permission to connect to their own workspace (enforces scopes)
|
||||
err := p.Authorizer.Authorize(ctx, *roles, rbacAction, rbacResourceOwned)
|
||||
if err != nil {
|
||||
return false, warnings, nil
|
||||
}
|
||||
|
||||
// Check if the user is a member of the workspace's organization
|
||||
workspaceOrgID := dbReq.Workspace.OrganizationID
|
||||
expandedRoles, err := roles.Roles.Expand()
|
||||
if err != nil {
|
||||
return false, warnings, xerrors.Errorf("expand roles: %w", err)
|
||||
}
|
||||
for _, role := range expandedRoles {
|
||||
if _, ok := role.Org[workspaceOrgID.String()]; ok {
|
||||
return true, []string{}, nil
|
||||
}
|
||||
}
|
||||
// User is not a member of the workspace's organization
|
||||
return false, warnings, nil
|
||||
case database.AppSharingLevelPublic:
|
||||
// We don't really care about scopes and stuff if it's public anyways.
|
||||
// Someone with a restricted-scope API key could just not submit the API
|
||||
|
||||
Reference in New Issue
Block a user