Istio:RequestAuthentication jwksUri无法解析内部服务名称 [英] Istio: RequestAuthentication jwksUri does not resolve internal services names

查看:115
本文介绍了Istio:RequestAuthentication jwksUri无法解析内部服务名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题的根本原因与

The root cause of this is the same than Istio: Health check / sidecar fails when I enable the JWT RequestAuthentication, but after further diagnose, I have reworded to simply (trying to get help)

我正在尝试在Istio网格中配置RequestAuthentication(和AuthorizationPolicy).我的JWK令牌是由内部OAUTH服务器(基于CloudFoundry)提供的,该服务器可以正常使用其他服务.当我配置uri以获取签名密钥并链接到内部Pod时,就会出现我的问题.目前, Istio不会解析内部窗格的名称.我很困惑,因为微服务能够连接到我的所有内部Pod(mongodb,mysql,rabbitmq),包括uaa.为什么RequestAuthentication无法执行相同的操作?

I'm trying to configure RequestAuthentication (and AuthorizationPolicy) in an Istio mesh. My JWK tokens are provided by an internal OAUTH server (based in CloudFoundry) that is working fine for other services. My problem comes when I configure the uri for getting the signing key, linking to the internal pod. In this moment, Istio is not resolving the name of the internal pod. I'm getting confused because the microservices are able to connect to all my internal pods (mongodb, mysql, rabbitmq) including the uaa. Why the RequestAuthentication is not able to do the same?

UAA服务配置(注意:我也在创建用于外部访问的虚拟服务,并且工作正常)

UAA Service configuration (notice: I'm also creating a virtual service for external access, and this is working fine)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: uaa
spec:
  replicas: 1
  selector:
    matchLabels:
      app: uaa
  template:
    metadata:
      labels:
        app: uaa
    spec:
      containers:
      - name: uaa
        image: example/uaa
        imagePullPolicy: Never
        env:
        - name: LOGGING_LEVEL_ROOT
          value: DEBUG
        ports:
        - containerPort: 8090
        resources:
          limits:
            memory: 350Mi
---
apiVersion: v1
kind: Service
metadata:
  name: uaa
spec:
  selector:
    app: uaa
  ports:
    - port: 8090
      name: http
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: vs-auth
spec:
  hosts:
  - "kubernetes.example.com"
  gateways:
  - gw-ingress
  http:
  - match:
    - uri:
        prefix: /oauth
    rewrite:
      uri: "/uaa/oauth"
    route:
    - destination:
        port:
          number: 8090
        host: uaa
  - match:
    - uri:
        prefix: /uaa
    rewrite:
      uri: "/uaa"
    route:
    - destination:
        port:
          number: 8090
        host: uaa        

RequestAuthentication:注意参数jwksUri,查找 uaa 主机名.

RequestAuthentication: Notice the parameter jwksUri, looking for uaa hostname.

apiVersion: "security.istio.io/v1beta1"
kind: "RequestAuthentication"
metadata:
  name: "ra-product-composite"
spec:
  selector:
    matchLabels:
      app: "product-composite"
  jwtRules:
  - issuer: "http://uaa:8090/uaa/oauth/token"
    jwksUri: "http://uaa:8090/uaa/token_keys"
    forwardOriginalToken: true
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
  name: "ap-product-composite"
spec:
  selector:
    matchLabels:
      app: "product-composite"
  action: ALLOW
  rules:
  - to:
    - operation: 
        methods: ["GET","POST","DELETE","HEAD","PUT"]
        paths: ["*"]

错误日志(在istiod窗格中)

Error log (in istiod pod)

2021-03-17T09:56:18.833731Z     error   Failed to fetch jwt public key from "http://uaa:8090/uaa/token_keys": Get "http://uaa:8090/uaa/token_keys": dial tcp: lookup uaa on 10.96.0.10:53: no such host
2021-03-17T09:56:18.838233Z     info    ads     LDS: PUSH for node:product-composite-5cbf8498c7-nhxtj.chp18 resources:29 size:134.8kB
2021-03-17T09:56:18.856277Z     warn    ads     ADS:LDS: ACK ERROR sidecar~10.1.4.2~product-composite-5cbf8498c7-nhxtj.chp18~chp18.svc.cluster.local-8 Internal:Error adding/updating listener(s) virtualInbound: Provider 'origins-0' in jwt_authn config has invalid local jwks: Jwks RSA [n] or [e] field is missing or has a parse error

解决方法

目前,我已将OAUTH服务器声明为外部服务器,并重定向了该请求,但这是完全无效的.

Workaround

For the moment, I have declared the OAUTH server as external, and redirected the request, but this is totally inefficient.

apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: se-auth
spec:
  hosts:
  - "host.docker.internal"
  ports:
  - number: 8090
    name: http
    protocol: HTTP
  resolution: DNS
  location: MESH_EXTERNAL
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: vs-auth
spec:
  hosts:
  - "kubernetes.example.com"
  gateways:
  - gw-ingress
  http:
  - match:
    - uri:
        prefix: /oauth
    rewrite:
      uri: "/uaa/oauth"
    route:
    - destination:
        port:
          number: 8090
        host: "host.docker.internal"
  - match:
    - uri:
        prefix: /uaa
    rewrite:
      uri: "/uaa"
    route:
    - destination:
        port:
          number: 8090
        host: "host.docker.internal"        
---
apiVersion: "security.istio.io/v1beta1"
kind: "RequestAuthentication"
metadata:
  name: "ra-product-composite"
spec:
  selector:
    matchLabels:
      app: "product-composite"
  jwtRules:
  - issuer: "http://uaa:8090/uaa/oauth/token"
    jwksUri: "http://host.docker.internal:8090/uaa/token_keys"
    forwardOriginalToken: true

解决方法2:

我已经解决了在主机名中使用FQDN(全限定名)的问题.但这不能解决我的问题,因为将配置文件链接到名称空间(我使用多个名称空间,并且只需要一个配置文件)无论如何,我当前的行是:

Workaround 2:

I have workarounded using the FQDN (the fully qualified name) in the host name. But this does not solve my problem, because links the configuration file to the namespace (I use multiple namespaces and I need to have only one configuration file) In any case, my current line is:

    jwksUri: "http://uaa.mynamespace.svc.cluster.local:8090/uaa/token_keys"

我完全确定这是一个愚蠢的配置参数,但是我找不到它!预先感谢

I'm totally sure that is a silly configuration parameter, but I'm not able to find it! Thanks in advance

推荐答案

jwksUri:"http://uaa:8090/uaa/token_keys" 在istiod上不起作用,因为http://uaa 将解释为 http://uaa.istio-system.svc.cluster.local .这就是您的解决方法能够解决问题的原因.

jwksUri: "http://uaa:8090/uaa/token_keys" will not work from istiod, because http://uaa will be interpreted as http://uaa.istio-system.svc.cluster.local. That's why your workaround are solving the problem.

我不明白为什么您的解决方法2不足以解决问题.假设您的uaa服务在名称空间 auth 中运行.如果您将 jwksUri 配置为 uaa.auth.svc.cluster.local ,则每个kubernetes pod都可以调用它,而不管其名称空间是什么.

I don't understand why your workaround 2 is not a sufficient solution. Let's say your uaa service runs in namespace auth. If you configure the jwksUri with uaa.auth.svc.cluster.local, every kubernetes pod is able to call it, regardless of it's namespace.

这篇关于Istio:RequestAuthentication jwksUri无法解析内部服务名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆