Kubernetes SSO Github 多个应用程序的 OAuth
Kubernetes SSO Github OAuth for multiple applications
所以这是交易。我正在使用 Kubernetes,我想保护集群内部的应用程序。因此我添加了一个 oauth2-proxy,如果用户没有登录,它会被重定向到 GitHub。登录完成后,用户将被重定向到应用程序 (Login Diagram)。现在,我有两个 echo-http 服务器(echo1 和 echo2)和 Jenkins 的虚拟部署。我在本地用 minikube 做所有事情,所以请不要介意域名。
在 Jenkins 中,我安装了 Github OAuth 插件并按照我找到的多个帖子中的说明进行了配置(例如,Jenkins GitHub OAuth). Also created the GitHub OAuth application and set the callback. Since I want to have SSO for multiple applications besides Jenkins, I set the call back to https://auth.int.example.com/oauth2/callback instead of https://jenkins.int.example.com/securityRealm/finishLogin。因此,在 GitHub 上登录后,我被重定向到 Jenkins 网页,但作为访客。如果我尝试登录,我最终会遇到错误。
我使用 Helm 设置了 oauth2-proxy (k8s-at-home/oauth2-proxy)
我是不是漏掉了什么?
这些是我正在使用的 oauth2-proxy 和入口控制器的入口配置。
Nginx 入口
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: echo-ingress
annotations:
kubernetes.io/ingress.class: nginx
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/auth-url: "https://auth.int.example.com/oauth2/auth"
nginx.ingress.kubernetes.io/auth-signin: "https://auth.int.example.com/oauth2/start?rd=https%3A%2F%2F$host$request_uri"
spec:
tls:
- hosts:
- echo1.int.example.com
- echo2.int.example.com
- jenkins.int.example.com
secretName: letsencrypt-prod
rules:
- host: echo1.int.example.com
http:
paths:
- backend:
serviceName: echo1
servicePort: 80
- host: echo2.int.example.com
http:
paths:
- backend:
serviceName: echo2
servicePort: 80
- host: jenkins.int.example.com
http:
paths:
- path:
backend:
serviceName: jenkins-service
servicePort: 8080
- path: /securityRealm/finishLogin
backend:
serviceName: jenkins-service
servicePort: 8080
OAuth2-代理配置
config:
existingSecret: oauth2-proxy-creds
extraArgs:
whitelist-domain: .int.example.com
cookie-domain: .int.example.com
provider: github
authenticatedEmailsFile:
enabled: true
restricted_access: |-
my_email@my_email.com
ingress:
enabled: true
path: /
hosts:
- auth.int.example.com
annotations:
kubernetes.io/ingress.class: nginx
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
tls:
- secretName: oauth2-proxy-https-cert
hosts:
- auth.int.example.com
您在那里构建的身份验证架构不错!
我想说你可能忽略了 Jenkins 有自己的身份验证这一事实。您还需要 configure Jenkins itself to allow Oauth2 access via Github.
那么到底是怎么回事呢?您的 Oauth 代理解决方案很棒。您可以在您的 k8s 集群中构建应用程序,而不必担心直接从您的应用程序进行用户管理或身份验证。
但是,这仅对没有自己的身份验证机制的应用程序有用。
Oauth 代理只是保护对后端网络服务器的访问。一旦您被代理允许,您就可以直接与该应用程序交互,因此如果该应用程序需要身份验证,您作为最终用户也将如此。
我的建议是对没有用户管理机制的应用程序使用 Oauth 代理,并为具有身份验证机制的应用程序(如 Jenkins)保留开放访问权限。否则你可能会得到双重身份验证(在这种情况下代理 和 Jenkins),这不是很好。
然后,为了保持使用 Github 帐户访问集群的高级概念,您需要将这些基于用户的应用配置为也使用 Github Oauth2。这样,对集群的访问是同质的(您只需要您的 Github 帐户),但实际集成有两种不同的类型:不需要用户管理的应用程序(它们受 Oauth 代理保护),以及具有身份验证的应用程序,然后独立配置 Github 的 Oauth2。
所以这是交易。我正在使用 Kubernetes,我想保护集群内部的应用程序。因此我添加了一个 oauth2-proxy,如果用户没有登录,它会被重定向到 GitHub。登录完成后,用户将被重定向到应用程序 (Login Diagram)。现在,我有两个 echo-http 服务器(echo1 和 echo2)和 Jenkins 的虚拟部署。我在本地用 minikube 做所有事情,所以请不要介意域名。
在 Jenkins 中,我安装了 Github OAuth 插件并按照我找到的多个帖子中的说明进行了配置(例如,Jenkins GitHub OAuth). Also created the GitHub OAuth application and set the callback. Since I want to have SSO for multiple applications besides Jenkins, I set the call back to https://auth.int.example.com/oauth2/callback instead of https://jenkins.int.example.com/securityRealm/finishLogin。因此,在 GitHub 上登录后,我被重定向到 Jenkins 网页,但作为访客。如果我尝试登录,我最终会遇到错误。 我使用 Helm 设置了 oauth2-proxy (k8s-at-home/oauth2-proxy)
我是不是漏掉了什么?
这些是我正在使用的 oauth2-proxy 和入口控制器的入口配置。
Nginx 入口
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: echo-ingress
annotations:
kubernetes.io/ingress.class: nginx
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/auth-url: "https://auth.int.example.com/oauth2/auth"
nginx.ingress.kubernetes.io/auth-signin: "https://auth.int.example.com/oauth2/start?rd=https%3A%2F%2F$host$request_uri"
spec:
tls:
- hosts:
- echo1.int.example.com
- echo2.int.example.com
- jenkins.int.example.com
secretName: letsencrypt-prod
rules:
- host: echo1.int.example.com
http:
paths:
- backend:
serviceName: echo1
servicePort: 80
- host: echo2.int.example.com
http:
paths:
- backend:
serviceName: echo2
servicePort: 80
- host: jenkins.int.example.com
http:
paths:
- path:
backend:
serviceName: jenkins-service
servicePort: 8080
- path: /securityRealm/finishLogin
backend:
serviceName: jenkins-service
servicePort: 8080
OAuth2-代理配置
config:
existingSecret: oauth2-proxy-creds
extraArgs:
whitelist-domain: .int.example.com
cookie-domain: .int.example.com
provider: github
authenticatedEmailsFile:
enabled: true
restricted_access: |-
my_email@my_email.com
ingress:
enabled: true
path: /
hosts:
- auth.int.example.com
annotations:
kubernetes.io/ingress.class: nginx
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
tls:
- secretName: oauth2-proxy-https-cert
hosts:
- auth.int.example.com
您在那里构建的身份验证架构不错!
我想说你可能忽略了 Jenkins 有自己的身份验证这一事实。您还需要 configure Jenkins itself to allow Oauth2 access via Github.
那么到底是怎么回事呢?您的 Oauth 代理解决方案很棒。您可以在您的 k8s 集群中构建应用程序,而不必担心直接从您的应用程序进行用户管理或身份验证。 但是,这仅对没有自己的身份验证机制的应用程序有用。 Oauth 代理只是保护对后端网络服务器的访问。一旦您被代理允许,您就可以直接与该应用程序交互,因此如果该应用程序需要身份验证,您作为最终用户也将如此。
我的建议是对没有用户管理机制的应用程序使用 Oauth 代理,并为具有身份验证机制的应用程序(如 Jenkins)保留开放访问权限。否则你可能会得到双重身份验证(在这种情况下代理 和 Jenkins),这不是很好。
然后,为了保持使用 Github 帐户访问集群的高级概念,您需要将这些基于用户的应用配置为也使用 Github Oauth2。这样,对集群的访问是同质的(您只需要您的 Github 帐户),但实际集成有两种不同的类型:不需要用户管理的应用程序(它们受 Oauth 代理保护),以及具有身份验证的应用程序,然后独立配置 Github 的 Oauth2。