-
Notifications
You must be signed in to change notification settings - Fork 889
feat: add --key flag to provisionerd start #14002
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f4f1b1b
feat: add --key flag to provisionerd start
f0ssel 47aa9c4
tests
f0ssel aa314a3
fix test
f0ssel 7b83b7e
more tests
f0ssel 727abcd
restrict route
f0ssel e54e662
fix tags with key flag
f0ssel 10b09ed
fix tags with key flag
f0ssel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import ( | |
"github.com/hashicorp/yamux" | ||
"github.com/moby/moby/pkg/namesgenerator" | ||
"go.opentelemetry.io/otel/trace" | ||
"golang.org/x/exp/maps" | ||
"golang.org/x/xerrors" | ||
"nhooyr.io/websocket" | ||
"storj.io/drpc/drpcmux" | ||
|
@@ -97,39 +98,43 @@ func (p *provisionerDaemonAuth) authorize(r *http.Request, orgID uuid.UUID, tags | |
return nil, xerrors.New("Both API key and provisioner key authentication provided. Only one is allowed.") | ||
} | ||
|
||
if apiKeyOK { | ||
tags = provisionersdk.MutateTags(apiKey.UserID, tags) | ||
if tags[provisionersdk.TagScope] == provisionersdk.ScopeUser { | ||
// Any authenticated user can create provisioner daemons scoped | ||
// for jobs that they own, | ||
return tags, nil | ||
// Provisioner Key Auth | ||
if pkOK { | ||
if pk.OrganizationID != orgID { | ||
return nil, xerrors.New("provisioner key unauthorized") | ||
} | ||
ua := httpmw.UserAuthorization(r) | ||
err := p.authorizer.Authorize(ctx, ua, policy.ActionCreate, rbac.ResourceProvisionerDaemon.InOrg(orgID)) | ||
if err != nil { | ||
if !provAuth { | ||
return nil, xerrors.New("user unauthorized") | ||
} | ||
|
||
// Allow fallback to PSK auth if the user is not allowed to create provisioner daemons. | ||
// This is to preserve backwards compatibility with existing user provisioner daemons. | ||
// If using PSK auth, the daemon is, by definition, scoped to the organization. | ||
tags = provisionersdk.MutateTags(uuid.Nil, tags) | ||
return tags, nil | ||
if tags != nil && !maps.Equal(tags, map[string]string{}) { | ||
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. TIL |
||
return nil, xerrors.New("tags are not allowed when using a provisioner key") | ||
} | ||
|
||
// User is allowed to create provisioner daemons | ||
// If using provisioner key / PSK auth, the daemon is, by definition, scoped to the organization. | ||
// Use the provisioner key tags here. | ||
tags = provisionersdk.MutateTags(uuid.Nil, pk.Tags) | ||
return tags, nil | ||
} | ||
|
||
if pkOK { | ||
if pk.OrganizationID != orgID { | ||
return nil, xerrors.New("provisioner key unauthorized") | ||
// User Auth | ||
tags = provisionersdk.MutateTags(apiKey.UserID, tags) | ||
if tags[provisionersdk.TagScope] == provisionersdk.ScopeUser { | ||
// Any authenticated user can create provisioner daemons scoped | ||
// for jobs that they own, | ||
return tags, nil | ||
} | ||
ua := httpmw.UserAuthorization(r) | ||
err := p.authorizer.Authorize(ctx, ua, policy.ActionCreate, rbac.ResourceProvisionerDaemon.InOrg(orgID)) | ||
if err != nil { | ||
if !provAuth { | ||
return nil, xerrors.New("user unauthorized") | ||
} | ||
|
||
// Allow fallback to PSK auth if the user is not allowed to create provisioner daemons. | ||
// This is to preserve backwards compatibility with existing user provisioner daemons. | ||
// If using PSK auth, the daemon is, by definition, scoped to the organization. | ||
tags = provisionersdk.MutateTags(uuid.Nil, tags) | ||
return tags, nil | ||
} | ||
|
||
// If using provisioner key / PSK auth, the daemon is, by definition, scoped to the organization. | ||
tags = provisionersdk.MutateTags(uuid.Nil, tags) | ||
// User is allowed to create provisioner daemons | ||
return tags, nil | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this because it's all done on coderd? And we should be passing no tags into the provisioner daemon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, the API will actually fail if you pass any tags + a provisioner key. I felt this was a good opportunity to break that behavior altogether.