@@ -62,6 +62,10 @@ func IsNotAuthorizedError(err error) bool {
62
62
if err == nil {
63
63
return false
64
64
}
65
+ if xerrors .Is (err , NoActorError ) {
66
+ return true
67
+ }
68
+
65
69
return xerrors .As (err , & NotAuthorizedError {})
66
70
}
67
71
@@ -1338,7 +1342,7 @@ func (q *querier) GetTailnetTunnelPeerIDs(ctx context.Context, srcID uuid.UUID)
1338
1342
func (q * querier ) GetTemplateAppInsights (ctx context.Context , arg database.GetTemplateAppInsightsParams ) ([]database.GetTemplateAppInsightsRow , error ) {
1339
1343
// Used by TemplateAppInsights endpoint
1340
1344
// For auditors, check read template_insights, and fall back to update template.
1341
- if err := q .authorizeContext (ctx , rbac .ActionRead , rbac .ResourceTemplateInsights ); IsNotAuthorizedError ( err ) {
1345
+ if err := q .authorizeContext (ctx , rbac .ActionRead , rbac .ResourceTemplateInsights ); err != nil {
1342
1346
for _ , templateID := range arg .TemplateIDs {
1343
1347
template , err := q .db .GetTemplateByID (ctx , templateID )
1344
1348
if err != nil {
@@ -1393,7 +1397,7 @@ func (q *querier) GetTemplateDAUs(ctx context.Context, arg database.GetTemplateD
1393
1397
func (q * querier ) GetTemplateInsights (ctx context.Context , arg database.GetTemplateInsightsParams ) (database.GetTemplateInsightsRow , error ) {
1394
1398
// Used by TemplateInsights endpoint
1395
1399
// For auditors, check read template_insights, and fall back to update template.
1396
- if err := q .authorizeContext (ctx , rbac .ActionRead , rbac .ResourceTemplateInsights ); IsNotAuthorizedError ( err ) {
1400
+ if err := q .authorizeContext (ctx , rbac .ActionRead , rbac .ResourceTemplateInsights ); err != nil {
1397
1401
for _ , templateID := range arg .TemplateIDs {
1398
1402
template , err := q .db .GetTemplateByID (ctx , templateID )
1399
1403
if err != nil {
@@ -1416,7 +1420,7 @@ func (q *querier) GetTemplateInsights(ctx context.Context, arg database.GetTempl
1416
1420
func (q * querier ) GetTemplateInsightsByInterval (ctx context.Context , arg database.GetTemplateInsightsByIntervalParams ) ([]database.GetTemplateInsightsByIntervalRow , error ) {
1417
1421
// Used by TemplateInsights endpoint
1418
1422
// For auditors, check read template_insights, and fall back to update template.
1419
- if err := q .authorizeContext (ctx , rbac .ActionRead , rbac .ResourceTemplateInsights ); IsNotAuthorizedError ( err ) {
1423
+ if err := q .authorizeContext (ctx , rbac .ActionRead , rbac .ResourceTemplateInsights ); err != nil {
1420
1424
for _ , templateID := range arg .TemplateIDs {
1421
1425
template , err := q .db .GetTemplateByID (ctx , templateID )
1422
1426
if err != nil {
@@ -1447,7 +1451,7 @@ func (q *querier) GetTemplateInsightsByTemplate(ctx context.Context, arg databas
1447
1451
func (q * querier ) GetTemplateParameterInsights (ctx context.Context , arg database.GetTemplateParameterInsightsParams ) ([]database.GetTemplateParameterInsightsRow , error ) {
1448
1452
// Used by both insights endpoint and prometheus collector.
1449
1453
// For auditors, check read template_insights, and fall back to update template.
1450
- if err := q .authorizeContext (ctx , rbac .ActionRead , rbac .ResourceTemplateInsights ); IsNotAuthorizedError ( err ) {
1454
+ if err := q .authorizeContext (ctx , rbac .ActionRead , rbac .ResourceTemplateInsights ); err != nil {
1451
1455
for _ , templateID := range arg .TemplateIDs {
1452
1456
template , err := q .db .GetTemplateByID (ctx , templateID )
1453
1457
if err != nil {
@@ -1620,7 +1624,7 @@ func (q *querier) GetUnexpiredLicenses(ctx context.Context) ([]database.License,
1620
1624
1621
1625
func (q * querier ) GetUserActivityInsights (ctx context.Context , arg database.GetUserActivityInsightsParams ) ([]database.GetUserActivityInsightsRow , error ) {
1622
1626
// Used by insights endpoints. Need to check both for auditors and for regular users with template acl perms.
1623
- if err := q .authorizeContext (ctx , rbac .ActionRead , rbac .ResourceTemplateInsights ); IsNotAuthorizedError ( err ) {
1627
+ if err := q .authorizeContext (ctx , rbac .ActionRead , rbac .ResourceTemplateInsights ); err != nil {
1624
1628
for _ , templateID := range arg .TemplateIDs {
1625
1629
template , err := q .db .GetTemplateByID (ctx , templateID )
1626
1630
if err != nil {
@@ -1657,7 +1661,7 @@ func (q *querier) GetUserCount(ctx context.Context) (int64, error) {
1657
1661
1658
1662
func (q * querier ) GetUserLatencyInsights (ctx context.Context , arg database.GetUserLatencyInsightsParams ) ([]database.GetUserLatencyInsightsRow , error ) {
1659
1663
// Used by insights endpoints. Need to check both for auditors and for regular users with template acl perms.
1660
- if err := q .authorizeContext (ctx , rbac .ActionRead , rbac .ResourceTemplateInsights ); IsNotAuthorizedError ( err ) {
1664
+ if err := q .authorizeContext (ctx , rbac .ActionRead , rbac .ResourceTemplateInsights ); err != nil {
1661
1665
for _ , templateID := range arg .TemplateIDs {
1662
1666
template , err := q .db .GetTemplateByID (ctx , templateID )
1663
1667
if err != nil {
@@ -2266,10 +2270,12 @@ func (q *querier) InsertWorkspaceAgent(ctx context.Context, arg database.InsertW
2266
2270
}
2267
2271
2268
2272
func (q * querier ) InsertWorkspaceAgentLogSources (ctx context.Context , arg database.InsertWorkspaceAgentLogSourcesParams ) ([]database.WorkspaceAgentLogSource , error ) {
2273
+ // TODO: This is used by the agent, should we have an rbac check here?
2269
2274
return q .db .InsertWorkspaceAgentLogSources (ctx , arg )
2270
2275
}
2271
2276
2272
2277
func (q * querier ) InsertWorkspaceAgentLogs (ctx context.Context , arg database.InsertWorkspaceAgentLogsParams ) ([]database.WorkspaceAgentLog , error ) {
2278
+ // TODO: This is used by the agent, should we have an rbac check here?
2273
2279
return q .db .InsertWorkspaceAgentLogs (ctx , arg )
2274
2280
}
2275
2281
0 commit comments