KeycloakClient strips realm path when realm URL lacks trailing slash

Đang mở Phù hợp với người mới
#606 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
88/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
authentication

Hướng nghiên cứu

Bắt đầu với pkg/connectors/keycloak_client.go, đặc biệt là NewKeycloakClientWithContext, sau đó xem lại pkg/connectors/keycloak_client_test.go. Chạy các bài kiểm tra connector và xác minh rằng URL realm không có dấu gạch chéo ở cuối vẫn giữ đường dẫn realm trong các yêu cầu cấu hình token và OIDC; hoàn thành khi bài kiểm tra hồi quy cho đầu vào đó vượt qua.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Describe the bug

When initializing a KeycloakClient using connectors.NewKeycloakClient or connectors.NewKeycloakClientWithContext, if the provided realmURL does not include a trailing slash (e.g., http://keycloak.example.com/realms/microcks), subsequent requests to obtain tokens or fetch OIDC configuration fail with HTTP 404.

This happens because relative endpoints (protocol/openid-connect/token and .well-known/openid-configuration) are resolved against kc.BaseURL using c.BaseURL.ResolveReference(rel).

Under RFC 3986 relative URL resolution rules, resolving a relative path against a base URL without a trailing slash strips the final path segment (microcks).

As a result, the request resolves to:

http://keycloak.example.com/realms/protocol/openid-connect/token

instead of:

http://keycloak.example.com/realms/microcks/protocol/openid-connect/token

In comparison, MicrocksClient in pkg/connectors/microcks_client.go defensively normalizes its incoming base URL, but KeycloakClient does not.

Expected behavior

NewKeycloakClient and NewKeycloakClientWithContext should ensure that kc.BaseURL.Path ends with a trailing /, so relative endpoints always resolve under the specified realm.

For example:

http://keycloak.example.com/realms/microcks/protocol/openid-connect/token

This should work regardless of whether the input URL includes a trailing slash.

Actual behavior

The realm name is stripped from the URL path.

  • Configured URL: http://keycloak.example.com/realms/microcks
  • Resolved Token URL: http://keycloak.example.com/realms/protocol/openid-connect/token (HTTP 404)
How to Reproduce?
  1. Initialize a KeycloakClient with a realm URL that omits the trailing slash:

    kc, err := connectors.NewKeycloakClientWithContext(
        context.Background(),
        "http://keycloak.example.com/realms/microcks",
        "client-id",
        "client-secret",
    )
    
    
  2. Call kc.ConnectAndGetToken() or kc.GetOIDCConfig().

  3. Inspect the resolved request URL. The realm segment /microcks will be stripped from the path.

Microcks version or git rev

master

Install method (docker-compose, helm chart, operator, docker-desktop extension,...)

No response

Additional information

This can be addressed in pkg/connectors/keycloak_client.go, inside NewKeycloakClientWithContext, by ensuring that the URL path always ends with a trailing slash:

if !strings.HasSuffix(u.Path, "/") {
    u.Path += "/"
}

Along with a unit test in pkg/connectors/keycloak_client_test.go covering a realm URL with a subpath.

Ngôn ngữ chính
Go
Star
59
Fork
74
Merge trung bình
4 ngày 5 giờ
Pull request đã merge (30 ngày)
15

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microcks/microcks-cli

Tất cả issue của microcks/microcks-cli

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.