Skip to content

Commit 3e688cf

Browse files
authored
acl: add missing JWT auth method validation (#25757)
1 parent 32ca833 commit 3e688cf

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

nomad/structs/acl.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,11 @@ func (a *ACLAuthMethodConfig) Validate(methodType string) error {
11451145
}
11461146

11471147
case ACLAuthMethodTypeJWT:
1148-
// TODO: check JWT fields: https://hashicorp.atlassian.net/browse/NET-12309
1148+
if a.OIDCDiscoveryURL == "" && a.JWKSURL == "" && len(a.JWTValidationPubKeys) == 0 {
1149+
mErr = multierror.Append(mErr, errors.New(
1150+
"JWT auth method requires either OIDCDiscoveryURL, or JWKS URL, or JWTValidationPubKeys set"),
1151+
)
1152+
}
11491153
}
11501154

11511155
return helper.FlattenMultierror(mErr)

nomad/structs/acl_test.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -1416,12 +1416,20 @@ func TestACLAuthMethodConfig_Validate(t *testing.T) {
14161416
must.ErrorContains(t, err, "missing OIDCClientID")
14171417
am.OIDCClientAssertion = &OIDCClientAssertion{}
14181418
am.Canonicalize()
1419+
14191420
err = am.Validate("OIDC")
14201421
must.ErrorContains(t, err, "invalid client assertion config:")
1421-
1422-
// do not fail, because no JWT validation at the moment
14231422
err = am.Validate("JWT")
1424-
must.NoError(t, err)
1423+
must.ErrorContains(t, err, "either OIDCDiscoveryURL")
1424+
1425+
// valid OIDC method config
1426+
validOIDCclientAssertion := &OIDCClientAssertion{Audience: []string{"foo"}, KeySource: "nomad"}
1427+
validOIDC := &ACLAuthMethodConfig{OIDCDiscoveryURL: "http://example.com", OIDCClientID: "oidc", OIDCClientAssertion: validOIDCclientAssertion}
1428+
must.NoError(t, validOIDC.Validate(ACLAuthMethodTypeOIDC))
1429+
1430+
// valid JWT method config
1431+
validJWT := &ACLAuthMethodConfig{JWKSURL: "http://example.com"}
1432+
must.NoError(t, validJWT.Validate(ACLAuthMethodTypeJWT))
14251433
}
14261434

14271435
func TestACLAuthMethodConfig_Copy(t *testing.T) {

0 commit comments

Comments
 (0)