Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Add initial AuthzQuerier implementation#5919

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

Merged
johnstcn merged 384 commits intomainfromauthzquerier_layer
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
384 commits
Select commitHold shift + click to select a range
7d0fad4
Fix typo
EmyrkJan 27, 2023
efe7f93
Merge remote-tracking branch 'origin/main' into authzquerier_layer
johnstcnJan 30, 2023
923219a
make RecordingAuthorizer wrap another rbac.Authorizer
johnstcnJan 30, 2023
f97ca2a
fix FakeAuthorizer
johnstcnJan 30, 2023
ad6ff52
skip TestAuthorizeAllEndpoints if authz_querier experiment is enabled
johnstcnJan 30, 2023
0e3b9ff
lock more things
johnstcnJan 30, 2023
feb7689
Merge remote-tracking branch 'origin/main' into authzquerier_layer
johnstcnJan 30, 2023
083bcf2
rbac/builtin.go: remove consts
johnstcnJan 30, 2023
161842d
extract getAgentSubject()
johnstcnJan 30, 2023
11983ab
Merge remote-tracking branch 'origin/main' into authzquerier_layer
johnstcnJan 31, 2023
ab9c049
use systemCtx in API.oauthLogin()
johnstcnJan 31, 2023
04e32bc
workspaceagents: fetch request ctx after httpmw.WorkspaceAgent sets a…
johnstcnJan 31, 2023
21d0f97
httpmw: pass systemCtx to getAgentSubject, add OwnerID to workspace a…
johnstcnJan 31, 2023
76a490e
authzquery: workspace: fix GetWorkspaceAppByAgentIDAndSlug and GetWor…
johnstcnJan 31, 2023
fa399d6
steven said its ok to remove this
johnstcnJan 31, 2023
cb9a2c5
Fix recursive test
EmyrkJan 31, 2023
9aa7835
Move experiment init below authz init
EmyrkJan 31, 2023
8f6265b
add httpmw.SystemAuthCtx to api.handleSubdomainApplications
johnstcnJan 31, 2023
bfa91c1
REVERT THIS COMMIT BEFORE MERGING !!!!
johnstcnJan 31, 2023
13710c6
ALSO DO NOT MERGE THIS COMMIT
johnstcnJan 31, 2023
467646d
authzquery: fix InsertAgentStat
johnstcnJan 31, 2023
32c8af1
activitybump: use systemCtx for activityBumpWorkspace
johnstcnJan 31, 2023
11ef507
Merge remote-tracking branch 'origin/main' into authzquerier_layer
EmyrkJan 31, 2023
b08fc44
remove unused function
EmyrkJan 31, 2023
69a6346
authzquery: fixes to templates and parameters
johnstcnFeb 1, 2023
4967fe6
Fix fetch dry run template version from job id
EmyrkFeb 1, 2023
6a7b053
Pass actor to follow logs for subscriber listen
EmyrkFeb 1, 2023
fc992cd
gerge remote-tracking branch 'origin/main' into authzquerier_layer
johnstcnFeb 2, 2023
d599753
rbac: add IsUnauthorizedError, return 404 if UnauthorizedError in org…
johnstcnFeb 2, 2023
0ce75c6
goimports
johnstcnFeb 2, 2023
357b05d
Implemented first draft testing framework
EmyrkFeb 2, 2023
6bb2e1c
authzquery: fixes in workspaces.go
johnstcnFeb 2, 2023
8a8ce06
Merge remote-tracking branch 'origin/authzquerier_layer' into authzqu…
johnstcnFeb 2, 2023
300f6dc
Add test method accounting to ensure all functions are called
EmyrkFeb 2, 2023
9f7d276
fixup! authzquery: fixes in workspaces.go
johnstcnFeb 2, 2023
d37379d
Merge remote-tracking branch 'origin/authzquerier_layer' into authzqu…
johnstcnFeb 2, 2023
6cc14b4
Add rbac checks
EmyrkFeb 2, 2023
2107b74
Fix scim unit tests
EmyrkFeb 2, 2023
53f7a5d
authzquery: update UpdateTemplateDeletedByID to call SoftDeleteTempla…
johnstcnFeb 2, 2023
44ca906
Merge remote-tracking branch 'origin/authzquerier_layer' into authzqu…
johnstcnFeb 2, 2023
73655ab
Fix scim and workspace agent unit tests
EmyrkFeb 2, 2023
0d6f6a0
Fix getTemplateVersionsByID
EmyrkFeb 2, 2023
32a9e12
Fix more unit tests
EmyrkFeb 2, 2023
85ff5f1
Fix license unit test
EmyrkFeb 2, 2023
e152d5f
authzquery: add some more convenience methods, comments etc.
johnstcnFeb 2, 2023
ef1deb5
Merge remote-tracking branch 'origin/authzquerier_layer' into authzqu…
johnstcnFeb 2, 2023
4848481
Add sentinel errors for unauth authz errors
EmyrkFeb 2, 2023
b583a1e
Use sentinal error that returns a 404
EmyrkFeb 2, 2023
75747f5
Use sentinel error always
EmyrkFeb 2, 2023
add77c6
add slice.New util function
johnstcnFeb 2, 2023
4357a3c
RecordingAuthorizer: AllAsserted: provide more information on missed …
johnstcnFeb 2, 2023
9dbc6bf
Merge remote-tracking branch 'origin/authzquerier_layer' into authzqu…
johnstcnFeb 2, 2023
c285f6f
skip GetAuthorizedWorkspaces
johnstcnFeb 2, 2023
58261fe
Add admin context to provisonerd
EmyrkFeb 2, 2023
a4a2994
Merge remote-tracking branch 'origin/main' into authzquerier_layer
EmyrkFeb 2, 2023
874e9da
Fix Delte group
EmyrkFeb 2, 2023
d878e71
remove excess comments
EmyrkFeb 2, 2023
10ac765
typos and lint
EmyrkFeb 2, 2023
e353c4d
Fix template admin permissions
EmyrkFeb 2, 2023
db647ba
Fix rbac unit test
EmyrkFeb 2, 2023
f45a170
Call compileToSQL in getWorkspaces
EmyrkFeb 2, 2023
b4beb38
Call compileToSQL in getWorkspaces
EmyrkFeb 2, 2023
d9d23b6
Fix compile issue
EmyrkFeb 2, 2023
8780e4e
Handle nil prepared case
EmyrkFeb 2, 2023
e6d5c2f
Linting
EmyrkFeb 2, 2023
672b2e0
fix GetLatestWorkspaceBuildsByWorkspaceIDs
johnstcnFeb 2, 2023
5a0e5a2
add existing workspace tests
johnstcnFeb 2, 2023
016c56d
Check returned error from db call
EmyrkFeb 2, 2023
e086e51
Fix build number to be 1 indexed
EmyrkFeb 2, 2023
390a284
more tests
johnstcnFeb 2, 2023
53fcf79
generate random AuthInstanceID, more unit tests
johnstcnFeb 2, 2023
0add01a
Test all api key methods
EmyrkFeb 2, 2023
6191561
Test audit methods
EmyrkFeb 2, 2023
e8ab762
Add group and file unit tests
EmyrkFeb 2, 2023
837f66a
Add template unit test
EmyrkFeb 2, 2023
88d422f
Add system functions
EmyrkFeb 2, 2023
a32b4f3
Merge remote-tracking branch 'origin/main' into authzquerier_layer
EmyrkFeb 2, 2023
d3affdc
Fix merge compile issues
EmyrkFeb 2, 2023
338e300
Jobs, orgs, and extra methods implemented
EmyrkFeb 2, 2023
f5c4040
Merge remote-tracking branch 'origin/main' into authzquerier_layer
EmyrkFeb 3, 2023
a7899cf
:
EmyrkFeb 3, 2023
0da03c6
Implement parameters tests
EmyrkFeb 3, 2023
4415b6b
Start license unit tests
EmyrkFeb 3, 2023
fb8973c
Merge remote-tracking branch 'origin/main' into authzquerier_layer
EmyrkFeb 3, 2023
6763fbf
Finish license tests
EmyrkFeb 3, 2023
d1b948d
Add workspace tests
EmyrkFeb 3, 2023
13a4fab
chore: Add WorkspaceApps to dbgen
EmyrkFeb 3, 2023
607e428
Add user unit tests
EmyrkFeb 3, 2023
592a62b
GitSSHKey, UserLink, GitAuthLink
EmyrkFeb 3, 2023
102af8a
Fix user unit tests
EmyrkFeb 3, 2023
d2b1f41
Merge remote-tracking branch 'origin/main' into authzquerier_layer
johnstcnFeb 3, 2023
b6afc2a
rm unused-import
johnstcnFeb 3, 2023
d1cfa73
authzquery: implement group and system methods
johnstcnFeb 3, 2023
b7cd5a5
fixup! authzquery: implement group and system methods
johnstcnFeb 3, 2023
f34c61b
fixup! authzquery: implement group and system methods
johnstcnFeb 3, 2023
e53d709
ineffasign
johnstcnFeb 3, 2023
cb4d92f
unshadow, unused-reciever
johnstcnFeb 3, 2023
13a8445
unused-param
johnstcnFeb 3, 2023
e1ce04e
finish testing template methods
johnstcnFeb 3, 2023
7fde8fb
Rename logger-> log, database->db, authorizer->auth, remove "authoriz…
EmyrkFeb 3, 2023
7ba3482
Rename fetchSet to fetchWithPostFilter
EmyrkFeb 3, 2023
cf763cb
Verify the correct error is returned on disallow auth
EmyrkFeb 3, 2023
64e80fb
Linting
EmyrkFeb 3, 2023
432a261
database: add missing argument to GetAuthorizedWorkspaces
johnstcnFeb 3, 2023
8134d1b
Refactor recording authorizer
EmyrkFeb 3, 2023
29e7c46
Address incorrect errors
EmyrkFeb 3, 2023
a37fead
Support asserting outputs in authzquery test
EmyrkFeb 3, 2023
2e435cf
Require outputs to be asserted
EmyrkFeb 3, 2023
792cbb6
Fix comment
EmyrkFeb 3, 2023
1336e28
allow skipping outputs
EmyrkFeb 3, 2023
0923780
Fix user tests to expect outputs
EmyrkFeb 3, 2023
92f89ec
fix api key unit tests to expect outputs
EmyrkFeb 3, 2023
acae52b
values audit_test.go
johnstcnFeb 3, 2023
764b0a0
Implement outputs for workspace tests
EmyrkFeb 3, 2023
0cee453
Some system outputs
EmyrkFeb 3, 2023
d1e3214
values file_test.go
johnstcnFeb 3, 2023
e799713
values group_test.go
johnstcnFeb 3, 2023
cbb4502
Template outputs
EmyrkFeb 3, 2023
83a31cb
System outputs
EmyrkFeb 3, 2023
9010ad7
values job_test.go, methods_test.go
johnstcnFeb 3, 2023
912c97a
Add organization output
EmyrkFeb 3, 2023
a3f67bb
values license_test.go
johnstcnFeb 3, 2023
7d31209
Merge remote-tracking branch 'origin/authzquerier_layer' into authzqu…
johnstcnFeb 3, 2023
2c906e5
Add parameters ooutput
EmyrkFeb 3, 2023
5e92648
Api key and audit fix
EmyrkFeb 3, 2023
04cce68
Fix file outputs
EmyrkFeb 3, 2023
712c0f4
Fix groups
EmyrkFeb 3, 2023
8f92a77
Fix job, license, and org
EmyrkFeb 3, 2023
3df9848
System done
EmyrkFeb 3, 2023
90a9d87
Fix templates
EmyrkFeb 3, 2023
8b39d7e
Fix most users
EmyrkFeb 3, 2023
a621743
Linting
EmyrkFeb 3, 2023
2c002bd
workspace_test.go values fix
johnstcnFeb 3, 2023
cbd5cb4
nolint unreachable
johnstcnFeb 3, 2023
6fed479
Fix all user method tests
EmyrkFeb 3, 2023
5928c37
Add unit tests for InTx and Ping
EmyrkFeb 3, 2023
46b8366
Add AuthorizedXX tests
EmyrkFeb 3, 2023
21a6f6a
api: skip Authorize if codersdk.ExperimentAuthzQuerier enabled
johnstcnFeb 3, 2023
d6810de
Merge remote-tracking branch 'origin/authzquerier_layer' into authzqu…
johnstcnFeb 3, 2023
889b650
Only abort early on checks that should be removed
EmyrkFeb 3, 2023
72ed503
remove authorizedQuery
EmyrkFeb 3, 2023
94ff5ef
authzquery: use GetProvisionerJobById to auth GetWorkspaceResourceByID
johnstcnFeb 3, 2023
38a90de
Merge remote-tracking branch 'origin/authzquerier_layer' into authzqu…
johnstcnFeb 3, 2023
c962897
All insert generic functions use rbac.ActionCreate
EmyrkFeb 3, 2023
62e3fa0
Fix unit tests that use create over update
EmyrkFeb 3, 2023
a0725b9
un-skip TestAuthorizeAllEndpoints and remove always-true conditional …
johnstcnFeb 3, 2023
a4c4489
Merge remote-tracking branch 'origin/authzquerier_layer' into authzqu…
johnstcnFeb 3, 2023
567cfa4
Merge remote-tracking branch 'origin/main' into authzquerier_layer
johnstcnFeb 3, 2023
91910af
fixup! un-skip TestAuthorizeAllEndpoints and remove always-true condi…
johnstcnFeb 3, 2023
dce10b5
where my members at yo
johnstcnFeb 3, 2023
58b71f9
Allow out of order slicing
EmyrkFeb 3, 2023
833bbc2
Use slice.New()
EmyrkFeb 3, 2023
fcfdb4e
paralalalaleleleel
johnstcnFeb 3, 2023
8858fd3
Ordering of users in fetch
EmyrkFeb 3, 2023
64e0f8c
Add actual scope to workspace agent ctx
EmyrkFeb 6, 2023
9d6ab90
Merge remote-tracking branch 'origin/main' into authzquerier_layer
EmyrkFeb 6, 2023
1821dcb
RBAC UserData should use the correct rbac resource
EmyrkFeb 7, 2023
7c9f686
Remove workspace IDs filter arg
EmyrkFeb 7, 2023
eda4e0a
rename authzquery.NewAuthzQuerier to authzquery.New
johnstcnFeb 7, 2023
073aa2c
Start removing QueryByRelated
EmyrkFeb 7, 2023
4fe26e9
Start removing QueryByRelated
EmyrkFeb 7, 2023
13f1c9f
remove queryWithRelated
johnstcnFeb 7, 2023
ba172ea
Fixup generic func comments
EmyrkFeb 7, 2023
509ebdc
fixup! remove queryWithRelated
johnstcnFeb 7, 2023
802272b
remove todo
EmyrkFeb 7, 2023
57cde94
Improve readability of generics and arguments
EmyrkFeb 7, 2023
4daa878
Update fetchAndQuery comment
EmyrkFeb 7, 2023
4608462
Fix comment about system functions
EmyrkFeb 7, 2023
2767264
remove insert() function
johnstcnFeb 7, 2023
fc3ae4b
insertWithReturn is the new insert
johnstcnFeb 7, 2023
bf653b6
Merge remote-tracking branch 'origin/authzquerier_layer' into authzqu…
johnstcnFeb 7, 2023
ca68db2
Remove duplicate workspace agent scope
EmyrkFeb 7, 2023
f1f05cc
Pass agent ctx into activityBumpWorkspace
EmyrkFeb 7, 2023
eb38c0d
remove panic
johnstcnFeb 7, 2023
b96bb21
Merge remote-tracking branch 'origin/authzquerier_layer' into authzqu…
johnstcnFeb 7, 2023
0a061be
Remove uneeded comments
EmyrkFeb 7, 2023
8295eb3
Use 's' for all suite methods
EmyrkFeb 7, 2023
c2bc20e
Reduce LoC by using setup and teardown test
EmyrkFeb 7, 2023
3bd3e89
Remove nested "RunMethodTest", use new assertions
EmyrkFeb 7, 2023
052c531
Start converting tests to the new format
EmyrkFeb 7, 2023
6aa55ac
refactor out error test
EmyrkFeb 7, 2023
72d0a4e
Update unit test teardown to include NoActorError
EmyrkFeb 7, 2023
4c68562
Attempt a new style of subtest
EmyrkFeb 7, 2023
fdfdd73
Fix user tests to use new subtest strategy
EmyrkFeb 7, 2023
c902715
Fix unit tests names
EmyrkFeb 7, 2023
f5dbd3e
Convert more tests to new format
EmyrkFeb 7, 2023
97ad3df
Convert all unit tests
EmyrkFeb 7, 2023
b369c99
Add comments
EmyrkFeb 7, 2023
03d42d3
remove unused code
EmyrkFeb 7, 2023
69d1aa3
rename MethodCase to expects
EmyrkFeb 7, 2023
3861a43
Merge remote-tracking branch 'origin/main' into authzquerier_layer
EmyrkFeb 7, 2023
9e7ff9a
DB function was renamed/changed
EmyrkFeb 7, 2023
9dc357e
imports
johnstcnFeb 8, 2023
ad6ad36
authzquery -> database/dbauthz
johnstcnFeb 8, 2023
0985060
conditionally skip TestAuthorizeAllEndpoints
johnstcnFeb 8, 2023
d4e1124
userauth: use systemCtx when setting user groups
johnstcnFeb 8, 2023
4e6b43f
Merge branch 'cj/dbauthz' into authzquerier_layer
johnstcnFeb 8, 2023
22e1057
fixup! authzquery -> database/dbauthz
johnstcnFeb 8, 2023
c5346ad
rm todo
johnstcnFeb 8, 2023
7a14b64
Condense into 1 file
EmyrkFeb 8, 2023
b89b430
doc.go
EmyrkFeb 8, 2023
21532a6
Update coderd/database/dbauthz/doc.go
EmyrkFeb 8, 2023
6a7970f
Move files around, consolidate to dbauthz.go
EmyrkFeb 8, 2023
399241a
Merge remote-tracking branch 'origin/main' into authzquerier_layer
EmyrkFeb 8, 2023
924ef9c
fix unit test to work with dbauthz
EmyrkFeb 8, 2023
2cf0fb2
Consolidate files
EmyrkFeb 8, 2023
d1bb7cf
goimports
johnstcnFeb 9, 2023
ef97e4b
rename methods.go -> querier.go
johnstcnFeb 9, 2023
951d74f
Do not export the authzQuerier
EmyrkFeb 9, 2023
2cf1cad
Rename to "querier", add unit test for double wrap protection
EmyrkFeb 9, 2023
a9f2581
remove duplicate dbauthz init
johnstcnFeb 10, 2023
832d91a
use codersdk experiment value instead of hard-coded string
johnstcnFeb 10, 2023
0ddee07
Merge remote-tracking branch 'origin/main' into authzquerier_layer
johnstcnFeb 10, 2023
cc76887
Merge remote-tracking branch 'origin/main' into authzquerier_layer
johnstcnFeb 10, 2023
002f354
Remove rbac ctx from provisionerd
EmyrkFeb 10, 2023
039e1e2
fixup! Remove rbac ctx from provisionerd
EmyrkFeb 10, 2023
b509b8f
wip: dbauthz.WithAuthorizeSystemContext -> dbauthz.AsSystem()
johnstcnFeb 10, 2023
524394f
Add lint rule to prevent system ctx abuse
EmyrkFeb 10, 2023
f666e13
fixup! wip: dbauthz.WithAuthorizeSystemContext -> dbauthz.AsSystem()
johnstcnFeb 10, 2023
1a97843
Merge remote-tracking branch 'origin/authzquerier_layer' into authzqu…
johnstcnFeb 10, 2023
4b292e2
fix autobuild/executor unit tests
johnstcnFeb 10, 2023
bebe638
Add middleware for using system ctx in middlewares
EmyrkFeb 10, 2023
f99c778
fix compile errors
johnstcnFeb 10, 2023
84bc12f
set system ctx in provisionerdserver
johnstcnFeb 10, 2023
c5e69fa
Unit test the AsAuthzSystem mw
EmyrkFeb 10, 2023
a93c2d5
Update unit tests to cover the no actor case
EmyrkFeb 10, 2023
f7023a4
Typo
EmyrkFeb 10, 2023
035609b
remove todo
EmyrkFeb 10, 2023
bbe4f18
User proper rbac errors in unit test
EmyrkFeb 10, 2023
f0bbaaf
Add unit test to cover prepareSQL error case
EmyrkFeb 10, 2023
51a2dae
NullUUID is empty, so takeFirst fails
EmyrkFeb 10, 2023
00955e0
Add AsSystem
EmyrkFeb 10, 2023
2289f4d
Fix internal error logging
EmyrkFeb 10, 2023
106d58b
Remove error noise in unit tests
EmyrkFeb 10, 2023
2724dfd
Use AsSystem for decrypting encrypted api keys
EmyrkFeb 10, 2023
2c34f6d
fix linter errors
johnstcnFeb 13, 2023
c54afc5
userauth: create API key as user instead of as system
johnstcnFeb 13, 2023
d282e9c
Merge remote-tracking branch 'origin/main' into authzquerier_layer
johnstcnFeb 13, 2023
7334046
Remove unused file
EmyrkFeb 13, 2023
3dbbc71
Use system context to set a disconnected agent
EmyrkFeb 13, 2023
cd6096f
Log error on failed agent disconnect update
EmyrkFeb 13, 2023
eb2497a
Merge remote-tracking branch 'origin/main' into authzquerier_layer
EmyrkFeb 14, 2023
d2c7a1f
Unit tests do not handle error log well
EmyrkFeb 14, 2023
99fa810
Merge remote-tracking branch 'origin/main' into authzquerier_layer
EmyrkFeb 14, 2023
1dfa287
Fix license uuid in merge
EmyrkFeb 14, 2023
57ab200
Fix unit test error logging
EmyrkFeb 14, 2023
306c591
Correct the returned error from not authorized
EmyrkFeb 14, 2023
f39cee0
Fix if/else logic
EmyrkFeb 14, 2023
2ed5588
fixup! Fix if/else logic
EmyrkFeb 14, 2023
c09b077
Merge remote-tracking branch 'origin/main' into authzquerier_layer
johnstcnFeb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletionscoderd/activitybump.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,10 +15,10 @@ import (

// activityBumpWorkspace automatically bumps the workspace's auto-off timer
// if it is set to expire soon.
func activityBumpWorkspace(log slog.Logger, db database.Store, workspaceID uuid.UUID) {
func activityBumpWorkspace(ctx context.Context,log slog.Logger, db database.Store, workspaceID uuid.UUID) {
// We set a short timeout so if the app is under load, these
// low priority operations fail first.
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
ctx, cancel := context.WithTimeout(ctx, time.Second*15)
defer cancel()

err := db.InTx(func(s database.Store) error {
Expand DownExpand Up@@ -82,9 +82,12 @@ func activityBumpWorkspace(log slog.Logger, db database.Store, workspaceID uuid.
return nil
}, nil)
if err != nil {
log.Error(ctx, "bump failed", slog.Error(err),
slog.F("workspace_id", workspaceID),
)
if !xerrors.Is(err, context.Canceled) {
// Bump will fail if the context is cancelled, but this is ok.
log.Error(ctx, "bump failed", slog.Error(err),
slog.F("workspace_id", workspaceID),
)
}
return
}

Expand Down
22 changes: 22 additions & 0 deletionscoderd/authorize.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,6 +51,28 @@ type HTTPAuthorizer struct {
//return
//}
func (api *API) Authorize(r *http.Request, action rbac.Action, object rbac.Objecter) bool {
// The experiment does not replace ALL rbac checks, but does replace most.
// This statement aborts early on the checks that will be removed in the
// future when this experiment is default.
if api.Experiments.Enabled(codersdk.ExperimentAuthzQuerier) {
// Some resource types do not interact with the persistent layer and
// we need to keep these checks happening in the API layer.
switch object.RBACObject().Type {
case rbac.ResourceWorkspaceExecution.Type:
// This is not a db resource, always in API layer
case rbac.ResourceDeploymentConfig.Type:
// For metric cache items like DAU, we do not hit the DB.
// Some db actions are in asserted in the authz layer.
case rbac.ResourceReplicas.Type:
// Replica rbac is checked for adding and removing replicas.
case rbac.ResourceProvisionerDaemon.Type:
// Provisioner rbac is checked for adding and removing provisioners.
case rbac.ResourceDebugInfo.Type:
// This is not a db resource, always in API layer.
default:
return true
}
}
return api.HTTPAuth.Authorize(r, action, object)
}

Expand Down
4 changes: 3 additions & 1 deletioncoderd/autobuild/executor/lifecycle_executor.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ import (
"cdr.dev/slog"
"github.com/coder/coder/coderd/autobuild/schedule"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/dbauthz"
)

// Executor automatically starts or stops workspaces.
Expand All@@ -33,7 +34,8 @@ type Stats struct {
// New returns a new autobuild executor.
func New(ctx context.Context, db database.Store, log slog.Logger, tick <-chan time.Time) *Executor {
le := &Executor{
ctx: ctx,
//nolint:gocritic // TODO: make an autostart role instead of using System
ctx: dbauthz.AsSystem(ctx),
db: db,
tick: tick,
log: log,
Expand Down
34 changes: 20 additions & 14 deletionscoderd/coderd.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,6 +42,7 @@ import (
"github.com/coder/coder/coderd/audit"
"github.com/coder/coder/coderd/awsidentity"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/dbauthz"
"github.com/coder/coder/coderd/database/dbtype"
"github.com/coder/coder/coderd/gitauth"
"github.com/coder/coder/coderd/gitsshkey"
Expand DownExpand Up@@ -157,13 +158,6 @@ func New(options *Options) *API {
options = &Options{}
}
experiments := initExperiments(options.Logger, options.DeploymentConfig.Experiments.Value, options.DeploymentConfig.Experimental.Value)
// TODO: remove this once we promote authz_querier out of experiments.
if experiments.Enabled(codersdk.ExperimentAuthzQuerier) {
panic("Coming soon!")
// if _, ok := (options.Database).(*authzquery.AuthzQuerier); !ok {
// options.Database = authzquery.NewAuthzQuerier(options.Database, options.Authorizer)
// }
}
if options.AppHostname != "" && options.AppHostnameRegex == nil || options.AppHostname == "" && options.AppHostnameRegex != nil {
panic("coderd: both AppHostname and AppHostnameRegex must be set or unset")
}
Expand DownExpand Up@@ -204,6 +198,14 @@ func New(options *Options) *API {
if options.Auditor == nil {
options.Auditor = audit.NewNop()
}
// TODO: remove this once we promote authz_querier out of experiments.
if experiments.Enabled(codersdk.ExperimentAuthzQuerier) {
options.Database = dbauthz.New(
options.Database,
options.Authorizer,
options.Logger.Named("authz_querier"),
)
}
if options.SetUserGroups == nil {
options.SetUserGroups = func(context.Context, database.Store, uuid.UUID, []string) error { return nil }
}
Expand DownExpand Up@@ -304,8 +306,10 @@ func New(options *Options) *API {
DisableSessionExpiryRefresh: options.DeploymentConfig.DisableSessionExpiryRefresh.Value,
Optional: true,
}),
httpmw.ExtractUserParam(api.Database, false),
httpmw.ExtractWorkspaceAndAgentParam(api.Database),
httpmw.AsAuthzSystem(
httpmw.ExtractUserParam(api.Database, false),
httpmw.ExtractWorkspaceAndAgentParam(api.Database),
),
),
// Build-Version is helpful for debugging.
func(next http.Handler) http.Handler {
Expand All@@ -332,11 +336,13 @@ func New(options *Options) *API {
DisableSessionExpiryRefresh: options.DeploymentConfig.DisableSessionExpiryRefresh.Value,
Optional: true,
}),
// Redirect to the login page if the user tries to open an app with
// "me" as the username and they are not logged in.
httpmw.ExtractUserParam(api.Database, true),
// Extracts the <workspace.agent> from the url
httpmw.ExtractWorkspaceAndAgentParam(api.Database),
httpmw.AsAuthzSystem(
// Redirect to the login page if the user tries to open an app with
// "me" as the username and they are not logged in.
httpmw.ExtractUserParam(api.Database, true),
// Extracts the <workspace.agent> from the url
httpmw.ExtractWorkspaceAndAgentParam(api.Database),
),
)
r.HandleFunc("/*", api.workspaceAppsProxyPath)
}
Expand Down
17 changes: 6 additions & 11 deletionscoderd/coderdtest/authorize.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,16 +12,16 @@ import (
"testing"
"time"

"github.com/coder/coder/cryptorand"
"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"github.com/moby/moby/pkg/namesgenerator"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/xerrors"

"github.com/coder/coder/cryptorand"

"github.com/coder/coder/coderd"
"github.com/coder/coder/coderd/database/dbfake"
"github.com/coder/coder/coderd/rbac"
"github.com/coder/coder/coderd/rbac/regosql"
"github.com/coder/coder/codersdk"
Expand All@@ -30,12 +30,6 @@ import (
)

func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
// For any route using SQL filters, we need to know if the database is an
// in memory fake. This is because the in memory fake does not use SQL, and
// still uses rego. So this boolean indicates how to assert the expected
// behavior.
_, isMemoryDB := a.api.Database.(dbfake.FakeDatabase)

// Some quick reused objects
workspaceRBACObj := rbac.ResourceWorkspace.WithID(a.Workspace.ID).InOrg(a.Organization.ID).WithOwner(a.Workspace.OwnerID.String())
workspaceExecObj := rbac.ResourceWorkspaceExecution.WithID(a.Workspace.ID).InOrg(a.Organization.ID).WithOwner(a.Workspace.OwnerID.String())
Expand DownExpand Up@@ -269,16 +263,17 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
"POST:/api/v2/workspaces/{workspace}/builds": {StatusCode: http.StatusBadRequest, NoAuthorize: true},
"POST:/api/v2/organizations/{organization}/templateversions": {StatusCode: http.StatusBadRequest, NoAuthorize: true},

// Endpoints that use the SQLQuery filter.
// For any route using SQL filters, we do not check authorization.
// This is because the in memory fake does not use SQL.
"GET:/api/v2/workspaces/": {
StatusCode: http.StatusOK,
NoAuthorize:!isMemoryDB,
NoAuthorize:true,
AssertAction: rbac.ActionRead,
AssertObject: rbac.ResourceWorkspace,
},
"GET:/api/v2/organizations/{organization}/templates": {
StatusCode: http.StatusOK,
NoAuthorize:!isMemoryDB,
NoAuthorize:true,
AssertAction: rbac.ActionRead,
AssertObject: rbac.ResourceTemplate,
},
Expand Down
6 changes: 6 additions & 0 deletionscoderd/coderdtest/authorize_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,15 +2,21 @@ package coderdtest_test

import (
"context"
"os"
"strings"
"testing"

"github.com/stretchr/testify/require"

"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/coderd/rbac"
"github.com/coder/coder/codersdk"
)

func TestAuthorizeAllEndpoints(t *testing.T) {
if strings.Contains(os.Getenv("CODER_EXPERIMENTS_TEST"), string(codersdk.ExperimentAuthzQuerier)) {
t.Skip("Skipping TestAuthorizeAllEndpoints for authz_querier experiment")
}
t.Parallel()
client, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{
// Required for any subdomain-based proxy tests to pass.
Expand Down
15 changes: 9 additions & 6 deletionscoderd/coderdtest/coderdtest.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,7 @@ import (
"github.com/golang-jwt/jwt"
"github.com/google/uuid"
"github.com/moby/moby/pkg/namesgenerator"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/afero"
"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
Expand All@@ -58,6 +59,7 @@ import (
"github.com/coder/coder/coderd/autobuild/executor"
"github.com/coder/coder/coderd/awsidentity"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/dbauthz"
"github.com/coder/coder/coderd/database/dbtestutil"
"github.com/coder/coder/coderd/gitauth"
"github.com/coder/coder/coderd/gitsshkey"
Expand DownExpand Up@@ -179,12 +181,13 @@ func NewOptions(t *testing.T, options *Options) (func(http.Handler), context.Can
options.Database, options.Pubsub = dbtestutil.NewDB(t)
}
// TODO: remove this once we're ready to enable authz querier by default.
if strings.Contains(os.Getenv("CODER_EXPERIMENTS_TEST"), "authz_querier") {
panic("Coming soon!")
// if options.Authorizer != nil {
// options.Authorizer = &RecordingAuthorizer{}
// }
// options.Database = authzquery.NewAuthzQuerier(options.Database, options.Authorizer)
if strings.Contains(os.Getenv("CODER_EXPERIMENTS_TEST"), string(codersdk.ExperimentAuthzQuerier)) {
if options.Authorizer == nil {
options.Authorizer = &RecordingAuthorizer{
Wrapped: rbac.NewAuthorizer(prometheus.NewRegistry()),
}
}
options.Database = dbauthz.New(options.Database, options.Authorizer, slogtest.Make(t, nil).Leveled(slog.LevelDebug))
}
if options.DeploymentConfig == nil {
options.DeploymentConfig = DeploymentConfig(t)
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp