KeycloakClient strips realm path when realm URL lacks trailing slash
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 88/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- go
调研方向
从pkg/connectors/keycloak_client.go开始,重点查看NewKeycloakClientWithContext,然后检查pkg/connectors/keycloak_client_test.go。运行 connector 测试,并确认不带尾部斜杠的 realm URL 在 token 和 OIDC 配置请求中仍保留其 realm 路径;该输入对应的回归测试通过后即完成。
由索引模型根据 Issue 内容生成。
描述
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?
-
Initialize a
KeycloakClientwith a realm URL that omits the trailing slash:kc, err := connectors.NewKeycloakClientWithContext( context.Background(), "http://keycloak.example.com/realms/microcks", "client-id", "client-secret", ) -
Call
kc.ConnectAndGetToken()orkc.GetOIDCConfig(). -
Inspect the resolved request URL. The realm segment
/microckswill 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.
- 主要语言
- Go
- 星标
- 59
- 派生
- 74
- 平均合并
- 4 天 8 小时
- 30 天内合并 PR
- 23
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microcks/microcks-cli 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
microcks/microcks-cli#608 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
microcks/microcks-cli#601 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
microcks/microcks-cli#598 · 1 条评论 ·
维护者通常 1 天内回复
-
bug: microcks login ignores the --config flag and always modifies default config可能已有人在做 @aryarathoree 于 3 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
microcks/microcks-cli#594 · 5 条评论 ·
维护者通常 1 天内回复
-
Wrong link to test results可能已有人在做 @SajanBisht 于 4 天前认领。 未关闭component/cli keep-open kind/bug
难度 2/5 1-3 小时 新手友好度 62/100
microcks/microcks-cli#589 · 4 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 microcks/microcks-cli 的全部 Issue
相似的 Issue
-
Headerless responses block while skipping duplicate status lines可能已有人在做 @mynhe 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 73/100
projectdiscovery/rawhttp#554 ·
-
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
lognorman20/monaco#7428 ·
-
docs(prompts): IF BLOCKED workflow-scope branch says to comment on the issue on jira/local trackers未关闭agent-butler-finding bug
难度 2/5 1-3 小时 新手友好度 77/100
jordansmall/spindrift#6238 ·
维护者通常 1 天内回复