@@ -193,11 +193,10 @@ var (
193
193
Name : "autostart" ,
194
194
DisplayName : "Autostart Daemon" ,
195
195
Site : rbac .Permissions (map [string ][]policy.Action {
196
- rbac .ResourceSystem .Type : {rbac .WildcardSymbol },
197
- rbac .ResourceTemplate .Type : {policy .ActionRead , policy .ActionUpdate },
198
- rbac .ResourceWorkspace .Type : {policy .ActionRead , policy .ActionUpdate },
199
- rbac .ResourceWorkspaceBuild .Type : {policy .ActionRead , policy .ActionUpdate , policy .ActionDelete },
200
- rbac .ResourceUser .Type : {policy .ActionRead },
196
+ rbac .ResourceSystem .Type : {rbac .WildcardSymbol },
197
+ rbac .ResourceTemplate .Type : {policy .ActionRead , policy .ActionUpdate },
198
+ rbac .ResourceWorkspace .Type : {policy .ActionRead , policy .ActionUpdate , policy .ActionWorkspaceBuild },
199
+ rbac .ResourceUser .Type : {policy .ActionRead },
201
200
}),
202
201
Org : map [string ][]rbac.Permission {},
203
202
User : []rbac.Permission {},
@@ -316,6 +315,20 @@ func insert[
316
315
authorizer rbac.Authorizer ,
317
316
object rbac.Objecter ,
318
317
insertFunc Insert ,
318
+ ) Insert {
319
+ return insertWithAction (logger , authorizer , object , policy .ActionCreate , insertFunc )
320
+ }
321
+
322
+ func insertWithAction [
323
+ ObjectType any ,
324
+ ArgumentType any ,
325
+ Insert func (ctx context.Context , arg ArgumentType ) (ObjectType , error ),
326
+ ](
327
+ logger slog.Logger ,
328
+ authorizer rbac.Authorizer ,
329
+ object rbac.Objecter ,
330
+ action policy.Action ,
331
+ insertFunc Insert ,
319
332
) Insert {
320
333
return func (ctx context.Context , arg ArgumentType ) (empty ObjectType , err error ) {
321
334
// Fetch the rbac subject
@@ -325,7 +338,7 @@ func insert[
325
338
}
326
339
327
340
// Authorize the action
328
- err = authorizer .Authorize (ctx , act , policy . ActionCreate , object .RBACObject ())
341
+ err = authorizer .Authorize (ctx , act , action , object .RBACObject ())
329
342
if err != nil {
330
343
return empty , logNotAuthorizedError (ctx , logger , err )
331
344
}
@@ -1804,19 +1817,19 @@ func (q *querier) GetUnexpiredLicenses(ctx context.Context) ([]database.License,
1804
1817
1805
1818
func (q * querier ) GetUserActivityInsights (ctx context.Context , arg database.GetUserActivityInsightsParams ) ([]database.GetUserActivityInsightsRow , error ) {
1806
1819
// Used by insights endpoints. Need to check both for auditors and for regular users with template acl perms.
1807
- if err := q .authorizeContext (ctx , policy .ActionRead , rbac .ResourceTemplateInsights ); err != nil {
1820
+ if err := q .authorizeContext (ctx , policy .ActionViewInsights , rbac .ResourceTemplate ); err != nil {
1808
1821
for _ , templateID := range arg .TemplateIDs {
1809
1822
template , err := q .db .GetTemplateByID (ctx , templateID )
1810
1823
if err != nil {
1811
1824
return nil , err
1812
1825
}
1813
1826
1814
- if err := q .authorizeContext (ctx , policy .ActionUpdate , template ); err != nil {
1827
+ if err := q .authorizeContext (ctx , policy .ActionViewInsights , template . RBACObject () ); err != nil {
1815
1828
return nil , err
1816
1829
}
1817
1830
}
1818
1831
if len (arg .TemplateIDs ) == 0 {
1819
- if err := q .authorizeContext (ctx , policy .ActionUpdate , rbac .ResourceTemplate .All ()); err != nil {
1832
+ if err := q .authorizeContext (ctx , policy .ActionViewInsights , rbac .ResourceTemplate .All ()); err != nil {
1820
1833
return nil , err
1821
1834
}
1822
1835
}
@@ -1841,19 +1854,19 @@ func (q *querier) GetUserCount(ctx context.Context) (int64, error) {
1841
1854
1842
1855
func (q * querier ) GetUserLatencyInsights (ctx context.Context , arg database.GetUserLatencyInsightsParams ) ([]database.GetUserLatencyInsightsRow , error ) {
1843
1856
// Used by insights endpoints. Need to check both for auditors and for regular users with template acl perms.
1844
- if err := q .authorizeContext (ctx , policy .ActionRead , rbac .ResourceTemplateInsights ); err != nil {
1857
+ if err := q .authorizeContext (ctx , policy .ActionViewInsights , rbac .ResourceTemplate ); err != nil {
1845
1858
for _ , templateID := range arg .TemplateIDs {
1846
1859
template , err := q .db .GetTemplateByID (ctx , templateID )
1847
1860
if err != nil {
1848
1861
return nil , err
1849
1862
}
1850
1863
1851
- if err := q .authorizeContext (ctx , policy .ActionUpdate , template ); err != nil {
1864
+ if err := q .authorizeContext (ctx , policy .ActionViewInsights , template ); err != nil {
1852
1865
return nil , err
1853
1866
}
1854
1867
}
1855
1868
if len (arg .TemplateIDs ) == 0 {
1856
- if err := q .authorizeContext (ctx , policy .ActionUpdate , rbac .ResourceTemplate .All ()); err != nil {
1869
+ if err := q .authorizeContext (ctx , policy .ActionViewInsights , rbac .ResourceTemplate .All ()); err != nil {
1857
1870
return nil , err
1858
1871
}
1859
1872
}
@@ -2313,15 +2326,15 @@ func (q *querier) InsertDeploymentID(ctx context.Context, value string) error {
2313
2326
}
2314
2327
2315
2328
func (q * querier ) InsertExternalAuthLink (ctx context.Context , arg database.InsertExternalAuthLinkParams ) (database.ExternalAuthLink , error ) {
2316
- return insert (q .log , q .auth , rbac .ResourceUserData . WithOwner (arg .UserID . String ()). WithID (arg .UserID ) , q .db .InsertExternalAuthLink )(ctx , arg )
2329
+ return insertWithAction (q .log , q .auth , rbac .ResourceUser . WithID (arg .UserID ). WithOwner (arg .UserID . String ()), policy . ActionUpdatePersonal , q .db .InsertExternalAuthLink )(ctx , arg )
2317
2330
}
2318
2331
2319
2332
func (q * querier ) InsertFile (ctx context.Context , arg database.InsertFileParams ) (database.File , error ) {
2320
2333
return insert (q .log , q .auth , rbac .ResourceFile .WithOwner (arg .CreatedBy .String ()), q .db .InsertFile )(ctx , arg )
2321
2334
}
2322
2335
2323
2336
func (q * querier ) InsertGitSSHKey (ctx context.Context , arg database.InsertGitSSHKeyParams ) (database.GitSSHKey , error ) {
2324
- return insert (q .log , q .auth , rbac .ResourceUserData .WithOwner (arg .UserID .String ()).WithID (arg .UserID ), q .db .InsertGitSSHKey )(ctx , arg )
2337
+ return insertWithAction (q .log , q .auth , rbac .ResourceUser .WithOwner (arg .UserID .String ()).WithID (arg .UserID ), policy . ActionUpdatePersonal , q .db .InsertGitSSHKey )(ctx , arg )
2325
2338
}
2326
2339
2327
2340
func (q * querier ) InsertGroup (ctx context.Context , arg database.InsertGroupParams ) (database.Group , error ) {
@@ -2997,7 +3010,7 @@ func (q *querier) UpdateUserAppearanceSettings(ctx context.Context, arg database
2997
3010
if err != nil {
2998
3011
return database.User {}, err
2999
3012
}
3000
- if err := q .authorizeContext (ctx , policy .ActionUpdate , u . UserDataRBACObject () ); err != nil {
3013
+ if err := q .authorizeContext (ctx , policy .ActionUpdatePersonal , u ); err != nil {
3001
3014
return database.User {}, err
3002
3015
}
3003
3016
return q .db .UpdateUserAppearanceSettings (ctx , arg )
@@ -3013,10 +3026,10 @@ func (q *querier) UpdateUserHashedPassword(ctx context.Context, arg database.Upd
3013
3026
return err
3014
3027
}
3015
3028
3016
- err = q .authorizeContext (ctx , policy .ActionUpdate , user . UserDataRBACObject () )
3029
+ err = q .authorizeContext (ctx , policy .ActionUpdatePersonal , user )
3017
3030
if err != nil {
3018
3031
// Admins can update passwords for other users.
3019
- err = q .authorizeContext (ctx , policy .ActionUpdate , user . RBACObject () )
3032
+ err = q .authorizeContext (ctx , policy .ActionUpdate , user )
3020
3033
if err != nil {
3021
3034
return err
3022
3035
}
0 commit comments