dex-k8s-ingress-watcher

Dex K8s Ingress Watcher Docker 镜像

自动构建

监控Kubernetes Ingress、ConfigMap或Secret资源,通过gRPC自动配置CoreOS Dex的staticClient条目,简化Dex客户端管理流程。

下载次数: 0状态:自动构建维护者:mintel仓库类型:镜像最近更新:
下载命令
点击查看

dex-k8s-ingress-watcher 镜像文档

概述

在集群中部署内部服务并通过Ingress暴露是常见场景,这些服务通常通过Dex进行认证,但添加新的staticClients需手动操作。本工具旨在自动配置https://github.com/dexidp/dex的`staticClient`条目,通过在集群内运行,监控Ingress、ConfigMap或Secret资源的注解,并通过gRPC对Dex进行修改。

默认仅监控Ingress资源(最常见场景),可选择监控ConfigMap和/或Secret资源。使用Secret存储staticClient的client-secret更为安全,尤其结合https://github.com/bitnami-labs/sealed-secrets等工具时。

核心功能和特性

  • 自动配置Dex客户端:通过监控Kubernetes资源注解,自动创建/删除Dex的staticClient条目
  • 多资源类型支持:默认监控Ingress,可选监控ConfigMap和Secret
  • 灵活的资源筛选:ConfigMap和Secret需通过特定标签(mintel.com/dex-k8s-ingress-watcher: enabled)筛选,避免无差别监控
  • 集群内外运行:支持在集群内(使用集群内配置)和集群外(使用$HOME/.kube/config)运行
  • gRPC通信:通过gRPC与Dex交互,实现高效配置更新

使用场景和适用范围

  • 需要频繁添加/删除Dex客户端的Kubernetes集群环境
  • 希望通过Kubernetes资源注解管理Dex客户端配置的场景
  • 需将Dex客户端密钥(client-secret)安全存储的场景

使用方法和配置说明

构建

bash
make build

运行

集群内外运行模式

  • 集群内运行:自动使用集群内Kubernetes配置
  • 集群外运行:使用$HOME/.kube/config配置

运行示例

默认仅Ingress监控

bash
./bin/dex-k8s-ingress-watcher serve --dex-grpc-address localhost:5557

带ConfigMap和Secret监控

bash
./bin/dex-k8s-ingress-watcher serve --dex-grpc-address localhost:5557 --ingress-controller --configmap-controller --secret-controller

禁用Ingress监控

bash
./bin/dex-k8s-ingress-watcher serve --dex-grpc-address localhost:5557 --no-ingress-controller --configmap-controller --secret-controller

RBAC注意事项

https://github.com/mintel/dex-k8s-ingress-watcher/blob/master/hack/deployment/clusterrole.yaml中的ClusterRole配置支持所有控制器(Ingress、ConfigMap和Secret)。建议移除不需要的控制器以限制资源访问权限,尤其是Secret资源。

资源配置

监控规则

  • Ingress:监控所有命名空间的Ingress资源,当存在指定注解时创建/删除Dex客户端
  • ConfigMap/Secret:监控所有命名空间中带有标签mintel.com/dex-k8s-ingress-watcher: enabled的资源,当存在指定注解时创建/删除Dex客户端(此标签用于减少监控范围)

注解说明

所有资源类型使用相同的注解,用于定义staticClient属性:

注解键说明是否必填
mintel.com/dex-k8s-ingress-watcher-client-id客户端ID是
mintel.com/dex-k8s-ingress-watcher-client-name客户端名称(默认与client-id相同)否
mintel.com/dex-k8s-ingress-watcher-secret客户端密钥是
mintel.com/dex-k8s-ingress-watcher-redirect-uri重定向URI(多个URI用逗号分隔)是

注解示例(Ingress)

yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    mintel.com/dex-k8s-ingress-watcher-client-id: my-app
    mintel.com/dex-k8s-ingress-watcher-client-name: My Application
    mintel.com/dex-k8s-ingress-watcher-secret: a-secret
    mintel.com/dex-k8s-ingress-watcher-redirect-uri: https://myapp.example.com/oauth/callback,https://myapp.example.com/oauth/callbackV2

生成的Dex staticClient

yaml
staticClients:
- id: my-app
  name: My Application
  secret: a-secret
  redirectURIs:
  - 'https://myapp.example.com/oauth/callback'
  - 'https://myapp.example.com/oauth/callbackV2'

在Kubernetes中部署

示例部署清单

示例清单位于https://github.com/mintel/dex-k8s-ingress-watcher/blob/master/hack/deployment/,**注意**:

  • 未启用Dex SSL
  • 服务账户被授予集群内所有ConfigMap和Secret的访问权限(可能不符合实际需求)

作为Dex Sidecar运行

推荐将本工具作为Dex的sidecar运行,通过localhost进行gRPC通信。假设Dex运行在127.0.0.1,gRPC端口为5557。

Sidecar配置示例

yaml
- name: dex-k8s-ingress-watcher
  command:
  - /app/bin/dex-k8s-ingress-watcher
  - serve
  - --incluster
  - --ingress-controller
  - --configmap-controller
  - --secret-controller
  - --dex-grpc-address
  - 127.0.0.1:5557
  image: docker.xuanyuan.run/mintel/dex-k8s-ingress-watcher:latest
  imagePullPolicy: IfNotPresent
  resources:
    limits:
      cpu: 50m
      memory: 64Mi
    requests:
      cpu: 20m
      memory: 32Mi

认证客户端应用配置

通过Dex认证的应用通常可运行OpenID代理服务作为sidecar,例如https://github.com/gambol99/keycloak-proxy。

keycloak-proxy Sidecar配置示例

yaml
- name: proxy
  image: ***-quay.xuanyuan.run/gambol99/keycloak-proxy:v2.1.1
  imagePullPolicy: Always
  resources:
    limits:
      cpu: 100m
      memory: 128Mi 
    requests:
      cpu: 50m
      memory: 64Mi
  args:
    - --verbose=true
    - --listen=:3000
    - --upstream-url=http://0.0.0.0:8000
    - --discovery-url=https://dex.example.com/.well-known/openid-configuration
    - --client-id=my-app
    - --skip-upstream-tls-verify
    - --redirection-url=https://myapp.example.com
    - --secure-cookie=false
    - --client-secret=a-secret
    - --enable-authorization-header
    - --skip-openid-provider-tls-verify
    - --add-claims=groups
    - --scopes=groups
    - --resources=uri=/*

关键配置说明

  • Ingress和Service需指向keycloak-proxy端口(示例中为3000)
  • upstream-url指向需要保护的应用(同一主机,不同端口)
  • client-secret必须与mintel.com/dex-k8s-ingress-watcher-secret注解值匹配
  • client-id必须与mintel.com/dex-k8s-ingress-watcher-client-id注解值匹配
  • 通过resources=uri选项限制访问,可结合Dex返回的groups进行权限控制

TODO

  • 应实现为CRD(自定义资源定义)以提供更原生的Kubernetes管理体验。

镜像拉取方式

您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。

轩辕镜像加速拉取命令点我查看更多 dex-k8s-ingress-watcher 镜像标签

docker pull docker.xuanyuan.run/mintel/dex-k8s-ingress-watcher:<标签>

DockerHub 原生拉取命令

docker pull mintel/dex-k8s-ingress-watcher:<标签>
专业版 · 高速稳定拉取镜像
50GB 仅 ¥8/年
高速镜像下载在线技术支持专业版保障服务可用付费会员免广告