- Notifications
You must be signed in to change notification settings - Fork928
chore: break down dbauthz.System into smaller roles#6218
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
603ec8e
3f16df7
28abbd6
c8bae4e
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -46,12 +46,12 @@ func logNotAuthorizedError(ctx context.Context, logger slog.Logger, err error) e | ||
iferr!=nil&&xerrors.As(err,&internalError) { | ||
e:=new(topdown.Error) | ||
ifxerrors.As(err,&e)||e.Code==topdown.CancelErr { | ||
// For some reason rego changes acanceled context to a topdown.CancelErr. We | ||
// expect to check forcanceled context errors if the user cancels the request, | ||
// so we should change the error to a context.Canceled error. | ||
// | ||
// NotAuthorizedError is == to sql.ErrNoRows, which is not correct | ||
// if it's actually acanceled context. | ||
internalError.SetInternal(context.Canceled) | ||
returninternalError | ||
} | ||
@@ -117,29 +117,73 @@ func ActorFromContext(ctx context.Context) (rbac.Subject, bool) { | ||
returna,ok | ||
} | ||
// AsProvisionerd returns a context with an actor that has permissions required | ||
// for provisionerd to function. | ||
funcAsProvisionerd(ctx context.Context) context.Context { | ||
returncontext.WithValue(ctx,authContextKey{}, rbac.Subject{ | ||
ID:uuid.Nil.String(), | ||
Roles:rbac.Roles([]rbac.Role{ | ||
{ | ||
Name:"provisionerd", | ||
DisplayName:"Provisioner Daemon", | ||
Site:rbac.Permissions(map[string][]rbac.Action{ | ||
rbac.ResourceFile.Type: {rbac.ActionRead}, | ||
rbac.ResourceTemplate.Type: {rbac.ActionRead,rbac.ActionUpdate}, | ||
rbac.ResourceUser.Type: {rbac.ActionRead}, | ||
rbac.ResourceWorkspace.Type: {rbac.ActionRead,rbac.ActionUpdate,rbac.ActionDelete}, | ||
}), | ||
Org:map[string][]rbac.Permission{}, | ||
User: []rbac.Permission{}, | ||
}, | ||
}), | ||
Scope:rbac.ScopeAll, | ||
}, | ||
) | ||
} | ||
// AsAutostart returns a context with an actor that has permissions required | ||
// for autostart to function. | ||
funcAsAutostart(ctx context.Context) context.Context { | ||
returncontext.WithValue(ctx,authContextKey{}, rbac.Subject{ | ||
ID:uuid.Nil.String(), | ||
Roles:rbac.Roles([]rbac.Role{ | ||
{ | ||
Name:"autostart", | ||
DisplayName:"Autostart Daemon", | ||
Site:rbac.Permissions(map[string][]rbac.Action{ | ||
rbac.ResourceTemplate.Type: {rbac.ActionRead,rbac.ActionUpdate}, | ||
rbac.ResourceWorkspace.Type: {rbac.ActionRead,rbac.ActionUpdate}, | ||
}), | ||
Org:map[string][]rbac.Permission{}, | ||
User: []rbac.Permission{}, | ||
}, | ||
}), | ||
Scope:rbac.ScopeAll, | ||
}, | ||
) | ||
} | ||
// AsSystemRestricted returns a context with an actor that has permissions | ||
// required for various system operations (login, logout, metrics cache). | ||
funcAsSystemRestricted(ctx context.Context) context.Context { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Do we plan on keeping this around? Or is it a catch all for the remaining stuff for now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This is a catch-all for the remaining stuff. It's mostly used for HTTP middleware. If we need to break it down further in future, we can do so. I think this is fine for now though. | ||
returncontext.WithValue(ctx,authContextKey{}, rbac.Subject{ | ||
ID:uuid.Nil.String(), | ||
Roles:rbac.Roles([]rbac.Role{ | ||
{ | ||
Name:"system", | ||
DisplayName:"Coder", | ||
Site:rbac.Permissions(map[string][]rbac.Action{ | ||
rbac.ResourceWildcard.Type: {rbac.ActionRead}, | ||
rbac.ResourceAPIKey.Type: {rbac.ActionCreate,rbac.ActionUpdate,rbac.ActionDelete}, | ||
rbac.ResourceGroup.Type: {rbac.ActionCreate,rbac.ActionUpdate}, | ||
rbac.ResourceRoleAssignment.Type: {rbac.ActionCreate}, | ||
rbac.ResourceOrganization.Type: {rbac.ActionCreate}, | ||
rbac.ResourceOrganizationMember.Type: {rbac.ActionCreate}, | ||
rbac.ResourceOrgRoleAssignment.Type: {rbac.ActionCreate}, | ||
rbac.ResourceUser.Type: {rbac.ActionCreate,rbac.ActionUpdate,rbac.ActionDelete}, | ||
rbac.ResourceUserData.Type: {rbac.ActionCreate,rbac.ActionUpdate}, | ||
rbac.ResourceWorkspace.Type: {rbac.ActionUpdate}, | ||
}), | ||
Org:map[string][]rbac.Permission{}, | ||
User: []rbac.Permission{}, | ||
}, | ||
Uh oh!
There was an error while loading.Please reload this page.