将一个 oauth2_proxy 个实例与多个入口路径一起使用?
Use one oauth2_proxy instance with many ingress paths?
我正在 运行在 Azure 上的 kubernetes 服务中安装一个应用程序,并使用 NGINX 入口控制器和带有 FQDN 的 public IP 地址对其进行设置。一切正常。
然后我想通过使用 oauth2-proxy 进行第三方登录来增加安全性。我想将我的设置保持为一个入口控制器和每个命名空间一个 oauth2_proxy,多个应用程序 运行 结合在一起。由于 Azure 不支持为此使用子域,因此我一直在使用路径路由到正确的应用程序。我看过示例 like this,关于如何将一个 oauth2_proxy 用于多个子域,但是否有可能让它与多个路径一起使用?
设置
这是只有一个应用程序的当前工作设置,位于根 /
上。我想切换到特定于应用程序的路径以及 运行 不同路径上的多个应用程序的能力。例如。 /my-app
、/another-app
等
oauth2-proxy-config.yaml
config:
existingSecret: oauth2-proxy-creds
extraArgs:
whitelist-domain: my-fqdn.uksouth.cloudapp.azure.com
cookie-domain: my-fqdn.uksouth.cloudapp.azure.com
email-domain: example.com
provider: github
ingress:
enabled: true
path: /oauth2
hosts:
- my-fqdn.uksouth.cloudapp.azure.com
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-prod # cert-manager cluster issuer set up for Let's Encrypt
tls:
- secretName: my-fqdn-tls # TLS generated by letsencrypt-prod
hosts:
- my-fqdn.uksouth.cloudapp.azure.com
这是使用以下 helm 命令安装的
helm upgrade oauth2-proxy --install stable/oauth2-proxy --namespace $NAMESPACE --reuse-values --values oauth2-proxy-config.yaml
app-ingress.yaml
apiVersion: networking.k8s.io/v1beta1 # for versions before 1.14 use extensions/v1beta1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-prod
# nginx.ingress.kubernetes.io/rewrite-target: / # Not working with the /oauth2 path and not needed when using root path for the app
nginx.ingress.kubernetes.io/auth-url: "https://my-fqdn.uksouth.cloudapp.azure.com/oauth2/auth"
nginx.ingress.kubernetes.io/auth-signin: "https://my-fqdn.uksouth.cloudapp.azure.com/oauth2/start?rd=https%3A%2F%2F$host$request_uri"
spec:
tls:
- secretName: my-fqdn-tls
hosts:
- my-fqdn.uksouth.cloudapp.azure.com
rules:
- host: my-fqdn.uksouth.cloudapp.azure.com
http:
paths:
- path: / # I would like to be able to use something like '/path1(/|$)(.*)' instead of root.
backend:
serviceName: my-app
servicePort: 80
当然,在单个 Ingress 资源定义中使用多个入口路径是可行的,请检查这个工作示例:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
labels:
app: hello-worlds
name: hello-wrolds
annotations:
cert-manager.io/issuer: selfsigned-issuer
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/auth-signin: "https://my-fqdn.uksouth.cloudapp.azure.com/oauth2/start?rd=$escaped_request_uri"
nginx.ingress.kubernetes.io/auth-url: "https://my-fqdn.uksouth.cloudapp.azure.com/oauth2/auth"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: my-fqdn.uksouth.cloudapp.azure.com
http:
paths:
- path: /my-app/(.*)
backend:
serviceName: my-app
servicePort: 5000
- path: /another-app/(.*)
backend:
serviceName: another-app
servicePort: 5000
tls:
- hosts:
- my-fqdn.uksouth.cloudapp.azure.com
secretName: certmgr-selfsign-tls-requires-ouath
在我的例子中,对于两个后端应用程序根文件夹都是'/hello',所以请求的URL分别是:
https://my-fqdn.uksouth.cloudapp.azure.com/my-app/hello
https://my-fqdn.uksouth.cloudapp.azure.com/another-app/hello
我正在 运行在 Azure 上的 kubernetes 服务中安装一个应用程序,并使用 NGINX 入口控制器和带有 FQDN 的 public IP 地址对其进行设置。一切正常。
然后我想通过使用 oauth2-proxy 进行第三方登录来增加安全性。我想将我的设置保持为一个入口控制器和每个命名空间一个 oauth2_proxy,多个应用程序 运行 结合在一起。由于 Azure 不支持为此使用子域,因此我一直在使用路径路由到正确的应用程序。我看过示例 like this,关于如何将一个 oauth2_proxy 用于多个子域,但是否有可能让它与多个路径一起使用?
设置
这是只有一个应用程序的当前工作设置,位于根 /
上。我想切换到特定于应用程序的路径以及 运行 不同路径上的多个应用程序的能力。例如。 /my-app
、/another-app
等
oauth2-proxy-config.yaml
config:
existingSecret: oauth2-proxy-creds
extraArgs:
whitelist-domain: my-fqdn.uksouth.cloudapp.azure.com
cookie-domain: my-fqdn.uksouth.cloudapp.azure.com
email-domain: example.com
provider: github
ingress:
enabled: true
path: /oauth2
hosts:
- my-fqdn.uksouth.cloudapp.azure.com
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-prod # cert-manager cluster issuer set up for Let's Encrypt
tls:
- secretName: my-fqdn-tls # TLS generated by letsencrypt-prod
hosts:
- my-fqdn.uksouth.cloudapp.azure.com
这是使用以下 helm 命令安装的
helm upgrade oauth2-proxy --install stable/oauth2-proxy --namespace $NAMESPACE --reuse-values --values oauth2-proxy-config.yaml
app-ingress.yaml
apiVersion: networking.k8s.io/v1beta1 # for versions before 1.14 use extensions/v1beta1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-prod
# nginx.ingress.kubernetes.io/rewrite-target: / # Not working with the /oauth2 path and not needed when using root path for the app
nginx.ingress.kubernetes.io/auth-url: "https://my-fqdn.uksouth.cloudapp.azure.com/oauth2/auth"
nginx.ingress.kubernetes.io/auth-signin: "https://my-fqdn.uksouth.cloudapp.azure.com/oauth2/start?rd=https%3A%2F%2F$host$request_uri"
spec:
tls:
- secretName: my-fqdn-tls
hosts:
- my-fqdn.uksouth.cloudapp.azure.com
rules:
- host: my-fqdn.uksouth.cloudapp.azure.com
http:
paths:
- path: / # I would like to be able to use something like '/path1(/|$)(.*)' instead of root.
backend:
serviceName: my-app
servicePort: 80
当然,在单个 Ingress 资源定义中使用多个入口路径是可行的,请检查这个工作示例:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
labels:
app: hello-worlds
name: hello-wrolds
annotations:
cert-manager.io/issuer: selfsigned-issuer
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/auth-signin: "https://my-fqdn.uksouth.cloudapp.azure.com/oauth2/start?rd=$escaped_request_uri"
nginx.ingress.kubernetes.io/auth-url: "https://my-fqdn.uksouth.cloudapp.azure.com/oauth2/auth"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: my-fqdn.uksouth.cloudapp.azure.com
http:
paths:
- path: /my-app/(.*)
backend:
serviceName: my-app
servicePort: 5000
- path: /another-app/(.*)
backend:
serviceName: another-app
servicePort: 5000
tls:
- hosts:
- my-fqdn.uksouth.cloudapp.azure.com
secretName: certmgr-selfsign-tls-requires-ouath
在我的例子中,对于两个后端应用程序根文件夹都是'/hello',所以请求的URL分别是:
https://my-fqdn.uksouth.cloudapp.azure.com/my-app/hello
https://my-fqdn.uksouth.cloudapp.azure.com/another-app/hello