-
Notifications
You must be signed in to change notification settings - Fork 30
feat(auth): server side changes for new worker auth flow #790
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
25 commits
Select commit
Hold shift + click to select a range
b339c4c
initial work
ecrupper 746b399
Merge branch 'main' into worker-auth/complete
ecrupper 8bf613c
adding symmetric token handling
ecrupper c1f1463
incorporating constants
ecrupper 1da6bdd
convert admin register token endpoint to be POST
ecrupper 4d7b735
pulling in types update
ecrupper e925301
Merge branch 'main' into worker-auth/complete
ecrupper e620fa3
add server mocks and json tags to check in resp
ecrupper febb17d
handle symmetric token in worker endpoints
ecrupper 4a12e25
appease linter overlord
ecrupper 25118c9
return properly when met with server worker token
ecrupper ad7db54
add proper return to update worker too
ecrupper 467b47f
add back actually updating the worker
ecrupper f6dea85
add comments to create and update worker api func
ecrupper 85c0efd
add new endpoint for refresh, remove plat admin access to worker auth…
ecrupper 75d4c1f
mocks mocks mocks
ecrupper fa8ba2c
Merge branch 'main' into worker-auth/complete
ecrupper bbdcfc5
fix mock, fix status returns, move check in update to refresh
ecrupper 2f49e8e
Merge branch 'worker-auth/complete' of github.com:go-vela/server into…
ecrupper 7bc1b5c
update mock validate http method
ecrupper 0014ccd
use authorization not token in mock
ecrupper 077c267
retrieve plat admin for logging in register token + swagger updates
ecrupper 66e3642
change return type of validate token
ecrupper b140651
getting mocked by mock
ecrupper 05b7cd2
update validate token mock comment
ecrupper 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Copyright (c) 2023 Target Brands, Inc. All rights reserved. | ||
| // | ||
| // Use of this source code is governed by the LICENSE file in this repository. | ||
|
|
||
| package admin | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| "github.com/go-vela/server/internal/token" | ||
| "github.com/go-vela/server/router/middleware/user" | ||
| "github.com/go-vela/server/util" | ||
| "github.com/go-vela/types/constants" | ||
| "github.com/go-vela/types/library" | ||
|
|
||
| "github.com/gin-gonic/gin" | ||
| "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| // swagger:operation POST /api/v1/admin/workers/{worker}/register-token admin RegisterToken | ||
| // | ||
| // Get a worker registration token | ||
| // | ||
| // --- | ||
| // produces: | ||
| // - application/json | ||
| // parameters: | ||
| // - in: path | ||
| // name: worker | ||
| // description: Hostname of the worker | ||
| // required: true | ||
| // type: string | ||
| // security: | ||
| // - ApiKeyAuth: [] | ||
| // responses: | ||
| // '200': | ||
| // description: Successfully generated registration token | ||
| // schema: | ||
| // "$ref": "#/definitions/Token" | ||
| // '401': | ||
| // description: Unauthorized | ||
| // schema: | ||
| // "$ref": "#/definitions/Error" | ||
|
|
||
| // RegisterToken represents the API handler to | ||
| // generate a registration token for onboarding a worker. | ||
| func RegisterToken(c *gin.Context) { | ||
| // retrieve user from context | ||
| u := user.Retrieve(c) | ||
|
|
||
| logrus.Infof("Platform admin %s: generating registration token", u.GetName()) | ||
|
|
||
| host := util.PathParameter(c, "worker") | ||
|
|
||
| tm := c.MustGet("token-manager").(*token.Manager) | ||
| rmto := &token.MintTokenOpts{ | ||
| Hostname: host, | ||
| TokenType: constants.WorkerRegisterTokenType, | ||
ecrupper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| TokenDuration: tm.WorkerRegisterTokenDuration, | ||
| } | ||
|
|
||
| rt, err := tm.MintToken(rmto) | ||
| if err != nil { | ||
| retErr := fmt.Errorf("unable to generate registration token: %w", err) | ||
|
|
||
| util.HandleError(c, http.StatusInternalServerError, retErr) | ||
|
|
||
| return | ||
| } | ||
|
|
||
| c.JSON(http.StatusOK, library.Token{Token: &rt}) | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.