我有一个 Kubernetes v1.26 自我管理集群。我有多个通过 Nginx-ingress 代理公开的应用程序。
我想通过身份验证来保护对这些应用程序的访问,我找到了 Keycloak 并使用 bitnami 图表,版本
docker.io/bitnami/keycloak:20.0.5-debian-11-r4
部署了它。我在这个领域创建了一个领域services
和一个客户端nginx
。 (我对这代表什么并不完全有信心)
现在我一直在更新我的入口规则以在访问我的应用程序时强制进行身份验证。 我找到了here一个带有oauth的示例来添加以下注释:
annotations:
nginx.ingress.kubernetes.io/auth-url: "https://$host/oauth2/auth"
nginx.ingress.kubernetes.io/auth-signin: "https://$host/oauth2/start?rd=$escaped_request_uri"
我尝试了
$host
、/auth
/realms/services
的多种组合,到目前为止我找不到正确的端点,所有请求都被重定向到404。
在Keycloak的客户端页面上,有Client id和secret,但我没有找到任何nginx注释来使用它们。
谢谢!
愿这对处于这种情况的任何人有帮助:
我发现了这个类似的问题。据我了解,Nginx 无法直接与 Keycloak 通信,oauth2 代理无法替代 nginx 功能来管理 kubernetes 入口。
我让它与以下内容一起工作:
oauth2-proxy已部署。我没有找到任何部署示例,这就是我所做的:
apiVersion: apps/v1
kind: Deployment
metadata:
name: oauth2-proxy
spec:
replicas: 1
selector:
matchLabels:
app: oauth2-proxy
template:
metadata:
labels:
app: oauth2-proxy
spec:
containers:
- name: oauth2-proxy
image: quay.io/oauth2-proxy/oauth2-proxy:latest
ports:
- containerPort: 8091
args:
- --provider=keycloak-oidc
- --client-id=nginx
- --client-secret=###
- --cookie-secret=###=
- --oidc-issuer-url=https://###/realms/test
- --oidc-extra-audience=account
- --scope=openid
- --pass-authorization-header=true
- --pass-access-token=true
- --pass-user-headers=true
- --set-authorization-header=true
- --set-xauthrequest=true
- --cookie-refresh=1m
- --cookie-expire=30m
- --http-address=0.0.0.0:8091
- --code-challenge-method=S256
---
apiVersion: v1
kind: Service
metadata:
name: oauth2-proxy
namespace: kc
labels:
name: oauth2-proxy
spec:
type: NodePort
ports:
- name: http
port: 8091
selector:
app: oauth2-proxy
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/proxy-buffer-size: "16k"
name: oauth2-proxy
namespace: kc
spec:
rules:
- host: ###
http:
paths:
- path: /oauth2
pathType: Prefix
backend:
service:
name: oauth2-proxy
port:
number: 8091
以及要保护的资源的 Nginx 入口注释:
nginx.ingress.kubernetes.io/auth-url: "https://###/oauth2/auth"
nginx.ingress.kubernetes.io/auth-signin: "https://###/oauth2/start?rd=$escaped_request_uri"
我几乎做了你所做的所有事情。但我的入口不会调用 auth-url、auth-signin 端点。您知道为什么会发生这种情况吗?