@@ -46,12 +46,12 @@ func logNotAuthorizedError(ctx context.Context, logger slog.Logger, err error) e
46
46
if err != nil && xerrors .As (err , & internalError ) {
47
47
e := new (topdown.Error )
48
48
if xerrors .As (err , & e ) || e .Code == topdown .CancelErr {
49
- // For some reason rego changes a cancelled context to a topdown.CancelErr. We
50
- // expect to check for cancelled context errors if the user cancels the request,
49
+ // For some reason rego changes a canceled context to a topdown.CancelErr. We
50
+ // expect to check for canceled context errors if the user cancels the request,
51
51
// so we should change the error to a context.Canceled error.
52
52
//
53
53
// NotAuthorizedError is == to sql.ErrNoRows, which is not correct
54
- // if it's actually a cancelled context.
54
+ // if it's actually a canceled context.
55
55
internalError .SetInternal (context .Canceled )
56
56
return internalError
57
57
}
@@ -117,29 +117,73 @@ func ActorFromContext(ctx context.Context) (rbac.Subject, bool) {
117
117
return a , ok
118
118
}
119
119
120
- // AsSystem returns a context with a system actor. This is used for internal
121
- // system operations that are not tied to any particular actor.
122
- // When you use this function, be sure to add a //nolint comment
123
- // explaining why it is necessary.
124
- //
125
- // We trust you have received the usual lecture from the local System
126
- // Administrator. It usually boils down to these three things:
127
- // #1) Respect the privacy of others.
128
- // #2) Think before you type.
129
- // #3) With great power comes great responsibility.
130
- func AsSystem (ctx context.Context ) context.Context {
120
+ // AsProvisionerd returns a context with an actor that has permissions required
121
+ // for provisionerd to function.
122
+ func AsProvisionerd (ctx context.Context ) context.Context {
123
+ return context .WithValue (ctx , authContextKey {}, rbac.Subject {
124
+ ID : uuid .Nil .String (),
125
+ Roles : rbac .Roles ([]rbac.Role {
126
+ {
127
+ Name : "provisionerd" ,
128
+ DisplayName : "Provisioner Daemon" ,
129
+ Site : rbac .Permissions (map [string ][]rbac.Action {
130
+ rbac .ResourceFile .Type : {rbac .ActionRead },
131
+ rbac .ResourceTemplate .Type : {rbac .ActionRead , rbac .ActionUpdate },
132
+ rbac .ResourceUser .Type : {rbac .ActionRead },
133
+ rbac .ResourceWorkspace .Type : {rbac .ActionRead , rbac .ActionUpdate , rbac .ActionDelete },
134
+ }),
135
+ Org : map [string ][]rbac.Permission {},
136
+ User : []rbac.Permission {},
137
+ },
138
+ }),
139
+ Scope : rbac .ScopeAll ,
140
+ },
141
+ )
142
+ }
143
+
144
+ // AsAutostart returns a context with an actor that has permissions required
145
+ // for autostart to function.
146
+ func AsAutostart (ctx context.Context ) context.Context {
147
+ return context .WithValue (ctx , authContextKey {}, rbac.Subject {
148
+ ID : uuid .Nil .String (),
149
+ Roles : rbac .Roles ([]rbac.Role {
150
+ {
151
+ Name : "autostart" ,
152
+ DisplayName : "Autostart Daemon" ,
153
+ Site : rbac .Permissions (map [string ][]rbac.Action {
154
+ rbac .ResourceTemplate .Type : {rbac .ActionRead , rbac .ActionUpdate },
155
+ rbac .ResourceWorkspace .Type : {rbac .ActionRead , rbac .ActionUpdate },
156
+ }),
157
+ Org : map [string ][]rbac.Permission {},
158
+ User : []rbac.Permission {},
159
+ },
160
+ }),
161
+ Scope : rbac .ScopeAll ,
162
+ },
163
+ )
164
+ }
165
+
166
+ // AsSystemRestricted returns a context with an actor that has permissions
167
+ // required for various system operations (login, logout, metrics cache).
168
+ func AsSystemRestricted (ctx context.Context ) context.Context {
131
169
return context .WithValue (ctx , authContextKey {}, rbac.Subject {
132
170
ID : uuid .Nil .String (),
133
171
Roles : rbac .Roles ([]rbac.Role {
134
172
{
135
173
Name : "system" ,
136
- DisplayName : "System" ,
137
- Site : []rbac.Permission {
138
- {
139
- ResourceType : rbac .ResourceWildcard .Type ,
140
- Action : rbac .WildcardSymbol ,
141
- },
142
- },
174
+ DisplayName : "Coder" ,
175
+ Site : rbac .Permissions (map [string ][]rbac.Action {
176
+ rbac .ResourceWildcard .Type : {rbac .ActionRead },
177
+ rbac .ResourceAPIKey .Type : {rbac .ActionCreate , rbac .ActionUpdate , rbac .ActionDelete },
178
+ rbac .ResourceGroup .Type : {rbac .ActionCreate , rbac .ActionUpdate },
179
+ rbac .ResourceRoleAssignment .Type : {rbac .ActionCreate },
180
+ rbac .ResourceOrganization .Type : {rbac .ActionCreate },
181
+ rbac .ResourceOrganizationMember .Type : {rbac .ActionCreate },
182
+ rbac .ResourceOrgRoleAssignment .Type : {rbac .ActionCreate },
183
+ rbac .ResourceUser .Type : {rbac .ActionCreate , rbac .ActionUpdate , rbac .ActionDelete },
184
+ rbac .ResourceUserData .Type : {rbac .ActionCreate , rbac .ActionUpdate },
185
+ rbac .ResourceWorkspace .Type : {rbac .ActionUpdate },
186
+ }),
143
187
Org : map [string ][]rbac.Permission {},
144
188
User : []rbac.Permission {},
145
189
},
0 commit comments