我正在尝试在个人 api 中使用 keycloak + keycloak-gatekeeper 进行授权:api.mydomain.com
.到目前为止,我已经完成了:
MY-REALM
在keycloak中,keycloak的URL是https://auth.mydomain.com confidential client
与 Authorization Enabled
在同一领域开启 和 Valid redirect URIS
:https://api.mydomain.com/ * client-id: <MY-API-CLIENT-ID>
client-secret: <SECRET>
discovery-url: https://auth.mydomain.com/auth/realms/<MY-REALM>
enable-default-deny: true
listen: 127.0.0.1:5000
upstream-url: http://127.0.0.1:5001
verbose: true
enable-logging: true
enable-security-filter: true
enable-json-logging: true
现在,如果我在浏览器中访问 https://api.mydomain.com我被重定向到 https://auth.mydomain.com要求用户和密码。我提供了在第 3 点创建的用户,并按预期再次重定向到 https://api.mydomain.com .到目前为止,一切都很好。
问题在于Authorization部分的配置:
在 key 斗篷中 ->
Clients
-> <MY-API-CLIENT-ID>
-> Authorization
-> Resources
我将默认策略编辑为 拒绝 resource
中的每个请求/* 但我可以访问 https://api.mydomain.com 中的每个资源(URL)就像以前一样。我试过了:
当然,我已经在
Evaluate
中尝试了上述所有组合。选择 keycloak 并在此处有效地模拟策略显示 拒绝 .那么我做错了什么?顺便说一下,在每次请求之后,这是来自 keycloak-gatekeeper 的日志:
{"level":"debug","ts":1554936731.4022436,"caller":"keycloak-gatekeeper/middleware.go:337","msg":"access permitted to resource","access":"permitted","email":"testmail@mail.com","expires":201.59779997,"resource":"/*"}
任何想法将不胜感激。
最佳答案
网守不使用 Keycloak -> Clients -> <MY-API-CLIENT-ID> -> Authorization -> Resources
.
它有自己的资源配置,例如:
resources:
- uri: /admin/*
methods:
- GET
roles:
- openvpn:vpn-user
- openvpn:commons-prod-vpn
文件:https://www.keycloak.org/docs/latest/securing_apps/index.html#configuration-options
关于keycloak 看门人不会阻止任何请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55622843/