GKE 使用 IAP 访问加固
使用IAP帮你的GKE应用加固的话,必须确实使用的是gce ingress, 如果是使用nginx ingress就无法用到了。
设置 OAuth consent screen
去到API and services 页面当中,然后在menu上找 OAuth consent screen

创建OAuth credentials
- 去到API and services 页面当中,然后在menu上找 credentials, 接着就是create credentials

2. 创建 credentials


4. 自行根据client id 组装好 authorise redirect url , 然后edit 刚刚创建的OAuth client 并且把它给保存。
https://iap.googleapis.com/v1/oauth/clientIds/CLIENT_ID:handleRedirect

K8s设定
- 根据获得的client id和 client secret 在k8s集群当中创建 secret
kubectl create secret generic my-secret --from-literal=client_id=client_id_key \
--from-literal=client_secret=client_secret_key
2. 把刚刚创建好的secret 映射入backend config 内
apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
name: config-default
namespace: my-namespace
spec:
iap:
enabled: true
oauthclientCredentials:
secretName: my-secret
3. 在你的k8s 应用service当中需要加入这个annotation,把backend config pointing到你的应用中
metadata:
annotations:
beta.cloud.google.com/backend-config: '{"default": "config-default"}'
IAP的设定
只要你是使用gce ingress的话在IAP list当中就会看到你的service了,如果使用的是nginx ingress就完全无法看到,所以能够确定的是nginx ingress在k8s当中是无法用到iap
- 选择你的service加入账号授权,就是按add principal的按钮

2. 设定你想授权的账号

3. 如果登入的google户口是未授权的就会报错并且无法浏览

参考文档:
https://cloud.google.com/iap/docs/enabling-kubernetes-howto
https://bravenewgeek.com/using-google-managed-certificates-and-identity-aware-proxy-with-gke/
Facebook评论