我已经建立了一个kubernetes集群,并且想要保护bitly/oauth2_proxy (在example.com/oauth2上的镜像a5huynh/oauth2_proxy:latest上运行)后面的仪表板(在kube.example.com上运行),因为我想为我将要运行的其他服务重用OAuth代理。身份验证工作正常,但在用户登录后,即回调返回后,它们将被发送到example.com,而不是应该发送到发起流的原始主机kube.example.com。我该怎么做呢?(我使用的是nginx-ingress controller)。
OAuth2代理上的注释:
kubernetes.io/ingress.class: "nginx",
nginx.ingress.kubernetes.io/force-ssl-redirect: "true",
nginx.ingress.kubernetes.io/secure-backends: "true",
nginx.ingress.kubernetes.io/ssl-passthrough: "true"仪表板上的注释:
kubernetes.io/ingress.class: "nginx",
nginx.ingress.kubernetes.io/auth-signin: "https://example.com/oauth2/start",
nginx.ingress.kubernetes.io/auth-url: "https://example.com/oauth2/auth",
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS",
nginx.ingress.kubernetes.io/force-ssl-redirect: "true",
nginx.ingress.kubernetes.io/secure-backends: "true",
nginx.ingress.kubernetes.io/ssl-passthrough: "true",
nginx.ingress.kubernetes.io/ssl-redirect: "true"我希望在OAuth流完成后重定向到原始主机kube.example.com,但正在将其发送回OAuth2主机example.com
发布于 2019-04-21 07:01:03
在搜索了一下之后,我发现了一个关于在一个超级简单的庄园中执行此操作的blog post。不幸的是,我发现提供的yaml不能正常工作,因为由于nginx截取所有请求,oauth2_proxy从来没有被命中(我不确定我的是不是因为我希望oauth-proxy url是example.com/oauth2而不是oauth2.example.com)。为了解决这个问题,我将oauth2-proxy路径添加回代理的Ingress,即
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: oauth2-proxy
namespace: default
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: example.com
http:
paths:
- backend:
serviceName: oauth2-proxy
servicePort: 80
path: /
- backend:
serviceName: oauth2-proxy
servicePort: 4180
path: /oauth2并确保服务仍然是公开的,即
apiVersion: v1
kind: Service
metadata:
labels:
k8s-app: oauth2-proxy
name: oauth2-proxy
namespace: default
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
- name: http-proxy
port: 4180
protocol: TCP
targetPort: 4180
selector:
k8s-app: oauth2-proxy然后,为了保护oauth代理后面的服务,我只需要在Ingress注释中放置以下内容:
nginx.ingress.kubernetes.io/auth-url: "https://example.com/oauth2/auth"
nginx.ingress.kubernetes.io/auth-signin: "https://example.com/oauth2/start?rd=/redirect/$http_host$request_uri"https://stackoverflow.com/questions/55770138
复制相似问题