nginx ingress 使用 k8s secret 作为 HTTP header
nginx ingress use k8s secret as HTTP header
我正在使用 nginx ingress,设置如下:
nginx.ingress.kubernetes.io/auth-url: http://api/v1/introspect
nginx.ingress.kubernetes.io/auth-method: POST
nginx.ingress.kubernetes.io/auth-response-headers: X-User-Auth
nginx.ingress.kubernetes.io/auth-snippet: |
proxy_set_header auth-header "authheaderhere==";
我的问题很简单但不确定答案是否是:
如何在入口定义中不硬编码 auth-header
的情况下定义入口?
自省端点(解码 JWT 令牌并将其附加到代理到其他微服务的原始请求)不会暴露在集群外部,但我希望知道端点即使在集群中也能更加安心,仅响应经过身份验证的请求(auth-header 是一个 base64 编码的字符串,其中包含客户端密码和客户端 ID)
how can I define the ingress without hardcoding the auth-header in the ingress definition?
开发自己的控制器。如何做到这一点的一个例子是 here.
如果您不想将其附加到 Ingress 实体 - 必须有人附加。
自己的控制器可以监视现有的入口(由您的一些标签过滤)并更新入口清单:附加您想要的注释。
The introspect endpoint (decodes JWT token and attaches it to original request that is proxied to other microservices) is not exposed outside of the cluster but I want the extra peace of mind knowing that the endpoint, even in the cluster, only responds to authenticated requests (auth-header is a base64 encoded string which contains a client secret and client id)
如果你想将你的 JWT 令牌隐藏到 Secret - 使用普通的 Nginx IngressController 没有简单的方法来做到这一点。 The source 说:
nginx.ingress.kubernetes.io/auth-snippet
: <Auth_Snippet>
to specify a custom snippet to use with external authentication, e.g.
即只是您可以包含的 nginx 配置示例,无需其他转换。
但是如果你可以部署额外的 IngressController 实例,你可以在那里使用 global-auth-snippet
参数。
将您的代码段添加到 Nginx 的 ConfigMap。然后为集群创建一些IngressClass and add kubernetes.io/ingress.class=my_ingress_class_name
annotation to your Ingresses (or even make the class Default)
您可以使用注释 nginx.ingress.kubernetes.io/auth-proxy-set-headers
https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#external-authentication 引用包含 headers.
的 ConfigMap
在这里你可以找到一个例子https://kubernetes.github.io/ingress-nginx/examples/customization/custom-headers
我正在使用 nginx ingress,设置如下:
nginx.ingress.kubernetes.io/auth-url: http://api/v1/introspect
nginx.ingress.kubernetes.io/auth-method: POST
nginx.ingress.kubernetes.io/auth-response-headers: X-User-Auth
nginx.ingress.kubernetes.io/auth-snippet: |
proxy_set_header auth-header "authheaderhere==";
我的问题很简单但不确定答案是否是:
如何在入口定义中不硬编码 auth-header
的情况下定义入口?
自省端点(解码 JWT 令牌并将其附加到代理到其他微服务的原始请求)不会暴露在集群外部,但我希望知道端点即使在集群中也能更加安心,仅响应经过身份验证的请求(auth-header 是一个 base64 编码的字符串,其中包含客户端密码和客户端 ID)
how can I define the ingress without hardcoding the auth-header in the ingress definition?
开发自己的控制器。如何做到这一点的一个例子是 here.
如果您不想将其附加到 Ingress 实体 - 必须有人附加。
自己的控制器可以监视现有的入口(由您的一些标签过滤)并更新入口清单:附加您想要的注释。
The introspect endpoint (decodes JWT token and attaches it to original request that is proxied to other microservices) is not exposed outside of the cluster but I want the extra peace of mind knowing that the endpoint, even in the cluster, only responds to authenticated requests (auth-header is a base64 encoded string which contains a client secret and client id)
如果你想将你的 JWT 令牌隐藏到 Secret - 使用普通的 Nginx IngressController 没有简单的方法来做到这一点。 The source 说:
nginx.ingress.kubernetes.io/auth-snippet
:<Auth_Snippet>
to specify a custom snippet to use with external authentication, e.g.
即只是您可以包含的 nginx 配置示例,无需其他转换。
但是如果你可以部署额外的 IngressController 实例,你可以在那里使用 global-auth-snippet
参数。
将您的代码段添加到 Nginx 的 ConfigMap。然后为集群创建一些IngressClass and add kubernetes.io/ingress.class=my_ingress_class_name
annotation to your Ingresses (or even make the class Default)
您可以使用注释 nginx.ingress.kubernetes.io/auth-proxy-set-headers
https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#external-authentication 引用包含 headers.
ConfigMap
在这里你可以找到一个例子https://kubernetes.github.io/ingress-nginx/examples/customization/custom-headers