-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Jwt runner auth 2 #3978
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
Open
fiftin
wants to merge
21
commits into
develop
Choose a base branch
from
jwt-runner-auth-2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Jwt runner auth 2 #3978
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7834ffb
feat(jwt): very basic jwt implementation
jon4hz 40de7b0
feat(jwt): store per jwt options per template in db
jon4hz 095421f
feat(jwt): multiple aud and ttl per template
jon4hz 272d73a
feat(jwt): jwt options in task template page
jon4hz 4ff3a9d
fix(jwt): only IDs in claims
jon4hz e818991
feat(jwt): improve wording, use ecdsa instead of rsa
jon4hz 83c7100
chore(jwt): add some unit tests
jon4hz 9ee2759
refactor(jwt): move duplicated crypto functions to utils
jon4hz 7d944e3
chore(jwt): dont rename imports
jon4hz b6cfb2b
chore(jwt): revert changes to package-lock.json
jon4hz e0a8b3c
chore(jwt): update config schema
jon4hz f0c6481
chore(jwt): simple option key
jon4hz 64e6036
chore(jwt): revert unwanted formatting changes in config schema
jon4hz adbde92
refactor(jwt): change config structure
fiftin a95ac48
feat(templates): use dropdown card for jwt and schedule
fiftin 14f5d72
test(jwt): fix config
fiftin 5f644c0
refactor(jwt): remove global variable
fiftin 5fb0e5d
Update devcontainer.json
fiftin 1e4fb26
refactor(jwt): remove global variable
fiftin bbacd8b
fix: merge conflict
fiftin 7d6c0d1
agents(jwt): add plan for new encryption key configs
fiftin 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ func TestApiPing(t *testing.T) { | |
| nil, | ||
| nil, | ||
| nil, | ||
| nil, | ||
| ) | ||
|
|
||
| r.ServeHTTP(rr, req) | ||
|
|
||
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,40 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/semaphoreui/semaphore/pkg/jwt" | ||
| "github.com/semaphoreui/semaphore/util" | ||
| log "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| type JwksController struct { | ||
| signer jwt.Signer | ||
| } | ||
|
|
||
| func NewJwksController(signer jwt.Signer) *JwksController { | ||
| return &JwksController{signer: signer} | ||
| } | ||
|
|
||
| // GetJWKS serves the JSON Web Key Set. | ||
| func (c *JwksController) GetJWKS(w http.ResponseWriter, _ *http.Request) { | ||
| if util.Config == nil || util.Config.JWT == nil || !util.Config.JWT.Enabled { | ||
| http.NotFound(w, nil) | ||
| return | ||
| } | ||
|
|
||
| if c.signer == nil { | ||
| http.NotFound(w, nil) | ||
| return | ||
| } | ||
|
|
||
| body, err := c.signer.JWKS() | ||
| if err != nil { | ||
| log.WithError(err).WithField("context", "jwt").Error("failed to marshal JWKS") | ||
| http.Error(w, "internal error", http.StatusInternalServerError) | ||
| return | ||
| } | ||
|
|
||
| w.Header().Set("Content-Type", "application/json") | ||
| _, _ = w.Write(body) | ||
| } |
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,57 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/semaphoreui/semaphore/pkg/jwt" | ||
| "github.com/semaphoreui/semaphore/util" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestJwksController_GetJWKS(t *testing.T) { | ||
| signer := newTestSigner(t) | ||
| controller := NewJwksController(signer) | ||
|
|
||
| t.Run("enabled", func(t *testing.T) { | ||
| util.Config = &util.ConfigType{ | ||
| JWT: &util.JWTConfig{Enabled: true}, | ||
| } | ||
|
|
||
| req := httptest.NewRequest(http.MethodGet, "/.well-known/jwks.json", nil) | ||
| rr := httptest.NewRecorder() | ||
|
|
||
| controller.GetJWKS(rr, req) | ||
|
|
||
| require.Equal(t, http.StatusOK, rr.Code) | ||
| assert.Equal(t, "application/json", rr.Header().Get("Content-Type")) | ||
| assert.Contains(t, rr.Body.String(), signer.KeyID()) | ||
| }) | ||
|
|
||
| t.Run("disabled", func(t *testing.T) { | ||
| util.Config = &util.ConfigType{ | ||
| JWT: &util.JWTConfig{Enabled: false}, | ||
| } | ||
|
|
||
| req := httptest.NewRequest(http.MethodGet, "/.well-known/jwks.json", nil) | ||
| rr := httptest.NewRecorder() | ||
|
|
||
| controller.GetJWKS(rr, req) | ||
|
|
||
| assert.Equal(t, http.StatusNotFound, rr.Code) | ||
| }) | ||
| } | ||
|
|
||
| func newTestSigner(t *testing.T) jwt.Signer { | ||
| t.Helper() | ||
|
|
||
| pemBytes, err := jwt.GenerateKeyPEM() | ||
| require.NoError(t, err) | ||
|
|
||
| signer, err := jwt.NewECDSASignerFromPEM(pemBytes, jwt.SignerOptions{}) | ||
| require.NoError(t, err) | ||
|
|
||
| return signer | ||
| } |
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
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.
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.
jwtobjectThese schema properties are top-level
jwt_enabled/jwt_issuerkeys, but the new config field isJWT *JWTConfigwith JSON namejwt, so the runtime expectsjwt: { enabled, issuer, default_ttl, max_ttl }. Users following this schema can create a validating config that is silently ignored byConfigInit, leaving JWT disabled and the UI hidden.Useful? React with 👍 / 👎.