-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for multiple keysets configured
- Loading branch information
Showing
4 changed files
with
87 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
|
||
"github.com/hashicorp/cap/jwt" | ||
Check failure on line 12 in backend.go
|
||
"github.com/hashicorp/cap/oidc" | ||
Check failure on line 13 in backend.go
|
||
"github.com/hashicorp/go-multierror" | ||
"github.com/hashicorp/vault/sdk/framework" | ||
"github.com/hashicorp/vault/sdk/logical" | ||
"github.com/patrickmn/go-cache" | ||
|
@@ -144,16 +145,31 @@ func (b *jwtAuthBackend) jwtValidator(config *jwtConfig) (*jwt.Validator, error) | |
} | ||
|
||
var err error | ||
var keySet jwt.KeySet | ||
var keySets []jwt.KeySet | ||
|
||
// Configure the key set for the validator | ||
switch config.authType() { | ||
case JWKS: | ||
keySet, err = jwt.NewJSONWebKeySet(b.providerCtx, config.JWKSURL, config.JWKSCAPEM) | ||
keySet, err2 := jwt.NewJSONWebKeySet(b.providerCtx, config.JWKSURL, config.JWKSCAPEM) | ||
keySets = []jwt.KeySet{keySet} | ||
err = err2 | ||
case MultiJWKS: | ||
for k, v := range config.JWKSPairs { | ||
// TODO (@johnlanda): read this in as map[string]string in config so we don't need type conversion. | ||
keySet, err2 := jwt.NewJSONWebKeySet(b.providerCtx, k, v.(string)) | ||
if err2 != nil { | ||
err = multierror.Append(err, fmt.Errorf("keyset configuration error: %w", err2)) | ||
} | ||
keySets = append(keySets, keySet) | ||
} | ||
case StaticKeys: | ||
keySet, err = jwt.NewStaticKeySet(config.ParsedJWTPubKeys) | ||
keySet, err2 := jwt.NewStaticKeySet(config.ParsedJWTPubKeys) | ||
keySets = []jwt.KeySet{keySet} | ||
err = err2 | ||
case OIDCDiscovery: | ||
keySet, err = jwt.NewOIDCDiscoveryKeySet(b.providerCtx, config.OIDCDiscoveryURL, config.OIDCDiscoveryCAPEM) | ||
keySet, err2 := jwt.NewOIDCDiscoveryKeySet(b.providerCtx, config.OIDCDiscoveryURL, config.OIDCDiscoveryCAPEM) | ||
keySets = []jwt.KeySet{keySet} | ||
err = err2 | ||
default: | ||
return nil, errors.New("unsupported config type") | ||
} | ||
|
@@ -162,7 +178,7 @@ func (b *jwtAuthBackend) jwtValidator(config *jwtConfig) (*jwt.Validator, error) | |
return nil, fmt.Errorf("keyset configuration error: %w", err) | ||
} | ||
|
||
validator, err := jwt.NewValidator(keySet) | ||
validator, err := jwt.NewValidator(keySets...) | ||
if err != nil { | ||
return nil, fmt.Errorf("JWT validator configuration error: %w", err) | ||
} | ||
|
This file contains 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 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 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