Skip to content

Commit 21171a9

Browse files
authored
Merge pull request #128 from greenbone/AT-1102-remove-issuer-check-from-keycloak-client-golang
Fix: removed issuer validation
2 parents 734cbaa + 74f782d commit 21171a9

File tree

2 files changed

+1
-29
lines changed

2 files changed

+1
-29
lines changed

auth/auth.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type KeycloakRealmInfo struct {
2626
RealmId string // RealmId is the realm name that is passed to services via env vars
2727
AuthServerInternalUrl string // AuthServerInternalUrl should point to keycloak auth server on internal (not public) network, e.g. http://keycloak:8080/auth; used for contacting keycloak for realm certificate for JWT
2828
AuthServerPublicUrl string // AuthServerPublicUrl should point to keycloak auth server on public (not internal) network, e.g. http://localhost:28080/auth; used to validate issuer field in JWT
29-
tokenIssuer string
3029
}
3130

3231
func (i *KeycloakRealmInfo) validate() error {
@@ -41,7 +40,7 @@ func (i *KeycloakRealmInfo) validate() error {
4140
errs = append(errs, fmt.Errorf("couldn't parse auth server internal url: %w", err))
4241
}
4342

44-
authUrl, err := url.ParseRequestURI(i.AuthServerPublicUrl)
43+
_, err = url.ParseRequestURI(i.AuthServerPublicUrl)
4544
if err != nil {
4645
errs = append(errs, fmt.Errorf("couldn't parse auth server public url: %w", err))
4746
}
@@ -50,8 +49,6 @@ func (i *KeycloakRealmInfo) validate() error {
5049
return fmt.Errorf("\n%w", errors.Join(errs...))
5150
}
5251

53-
i.tokenIssuer = authUrl.JoinPath("/realms/" + i.RealmId).String()
54-
5552
return nil
5653
}
5754

@@ -154,10 +151,6 @@ func (a *KeycloakAuthorizer) ParseJWT(ctx context.Context, token string) (UserCo
154151
}
155152
claims := jwtToken.Claims.(*customClaims)
156153

157-
if claims.RegisteredClaims.Issuer != a.realmInfo.tokenIssuer {
158-
return UserContext{}, fmt.Errorf("invalid domain of issuer of token %q", claims.RegisteredClaims.Issuer)
159-
}
160-
161154
if _, _, err := a.client.DecodeAccessToken(ctx, token, a.realmInfo.RealmId); err != nil {
162155
return UserContext{}, fmt.Errorf("validation of token failed: %w", err)
163156
}

auth/auth_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,6 @@ func TestParseJWT(t *testing.T) {
8686

8787
FakeCertResponse(t, authorizer)
8888

89-
t.Run("No realm info", func(t *testing.T) {
90-
userContext, err := authorizer.ParseJWT(context.Background(), noRealmToken)
91-
92-
assert.ErrorContains(t, err, "invalid domain of issuer")
93-
assert.Zero(t, userContext)
94-
})
95-
9689
t.Run("Wrong algorithm", func(t *testing.T) {
9790
userContext, err := authorizer.ParseJWT(context.Background(), invalidAlgorithmToken)
9891

@@ -125,20 +118,6 @@ func TestParseJWT(t *testing.T) {
125118
assert.Zero(t, userContext)
126119
})
127120

128-
t.Run("Invalid issuer", func(t *testing.T) {
129-
userContext, err := authorizer.ParseJWT(context.Background(), invalidIssuerToken)
130-
131-
assert.ErrorContains(t, err, "invalid domain of issuer")
132-
assert.Zero(t, userContext)
133-
})
134-
135-
t.Run("Invalid realm", func(t *testing.T) {
136-
userContext, err := authorizer.ParseJWT(context.Background(), invalidRealmToken)
137-
138-
assert.ErrorContains(t, err, "invalid domain of issuer")
139-
assert.Zero(t, userContext)
140-
})
141-
142121
t.Run("OK", func(t *testing.T) {
143122
userContext, err := authorizer.ParseJWT(context.Background(), validToken)
144123

0 commit comments

Comments
 (0)