Skip to content
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

Fix: removed issuer validation #128

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type KeycloakRealmInfo struct {
RealmId string // RealmId is the realm name that is passed to services via env vars
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
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
tokenIssuer string
}

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

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

i.tokenIssuer = authUrl.JoinPath("/realms/" + i.RealmId).String()

return nil
}

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

if claims.RegisteredClaims.Issuer != a.realmInfo.tokenIssuer {
return UserContext{}, fmt.Errorf("invalid domain of issuer of token %q", claims.RegisteredClaims.Issuer)
}

if _, _, err := a.client.DecodeAccessToken(ctx, token, a.realmInfo.RealmId); err != nil {
return UserContext{}, fmt.Errorf("validation of token failed: %w", err)
}
Expand Down
21 changes: 0 additions & 21 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ func TestParseJWT(t *testing.T) {

FakeCertResponse(t, authorizer)

t.Run("No realm info", func(t *testing.T) {
userContext, err := authorizer.ParseJWT(context.Background(), noRealmToken)

assert.ErrorContains(t, err, "invalid domain of issuer")
assert.Zero(t, userContext)
})

t.Run("Wrong algorithm", func(t *testing.T) {
userContext, err := authorizer.ParseJWT(context.Background(), invalidAlgorithmToken)

Expand Down Expand Up @@ -125,20 +118,6 @@ func TestParseJWT(t *testing.T) {
assert.Zero(t, userContext)
})

t.Run("Invalid issuer", func(t *testing.T) {
userContext, err := authorizer.ParseJWT(context.Background(), invalidIssuerToken)

assert.ErrorContains(t, err, "invalid domain of issuer")
assert.Zero(t, userContext)
})

t.Run("Invalid realm", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should have a working realm validity check?

userContext, err := authorizer.ParseJWT(context.Background(), invalidRealmToken)

assert.ErrorContains(t, err, "invalid domain of issuer")
assert.Zero(t, userContext)
})

t.Run("OK", func(t *testing.T) {
userContext, err := authorizer.ParseJWT(context.Background(), validToken)

Expand Down