<h3>Notice</h3>
<p>The root cause of this is the same than <a href="https://stackoverflow.com/questions/66446178/istio-health-check-sidecar-fails-when-i-enable-the-jwt-requestauthentication">Istio: Health check / sidecar fails when I enable the JWT RequestAuthentication</a>, but after further diagnose, I have reworded to simply (trying to get help)</p>
<h3>Problem</h3>
<p>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, <strong>Istio is not resolving the name of the internal pod</strong>. 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?</p>
<p>UAA Service configuration (notice: I'm also creating a virtual service for external access, and this is working fine)</p>
<pre><code>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:
  - &quot;kubernetes.example.com&quot;
  gateways:
  - gw-ingress
  http:
  - match:
    - uri:
        prefix: /oauth
    rewrite:
      uri: &quot;/uaa/oauth&quot;
    route:
    - destination:
        port:
          number: 8090
        host: uaa
  - match:
    - uri:
        prefix: /uaa
    rewrite:
      uri: &quot;/uaa&quot;
    route:
    - destination:
        port:
          number: 8090
        host: uaa        

</code></pre>
<p>RequestAuthentication: Notice the parameter jwksUri, looking for <code>uaa</code> hostname.</p>
<pre><code>apiVersion: &quot;security.istio.io/v1beta1&quot;
kind: &quot;RequestAuthentication&quot;
metadata:
  name: &quot;ra-product-composite&quot;
spec:
  selector:
    matchLabels:
      app: &quot;product-composite&quot;
  jwtRules:
  - issuer: &quot;http://uaa:8090/uaa/oauth/token&quot;
    jwksUri: &quot;http://uaa:8090/uaa/token_keys&quot;
    forwardOriginalToken: true
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
  name: &quot;ap-product-composite&quot;
spec:
  selector:
    matchLabels:
      app: &quot;product-composite&quot;
  action: ALLOW
  rules:
  - to:
    - operation: 
        methods: [&quot;GET&quot;,&quot;POST&quot;,&quot;DELETE&quot;,&quot;HEAD&quot;,&quot;PUT&quot;]
        paths: [&quot;*&quot;]
</code></pre>
<p>Error log (in istiod pod)</p>
<pre><code>2021-03-17T09:56:18.833731Z     error   Failed to fetch jwt public key from &quot;http://uaa:8090/uaa/token_keys&quot;: Get &quot;http://uaa:8090/uaa/token_keys&quot;: 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
</code></pre>
<h3>Workaround</h3>
<p>For the moment, I have declared the OAUTH server as external, and redirected the request, but this is totally inefficient.</p>
<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: se-auth
spec:
  hosts:
  - &quot;host.docker.internal&quot;
  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:
  - &quot;kubernetes.example.com&quot;
  gateways:
  - gw-ingress
  http:
  - match:
    - uri:
        prefix: /oauth
    rewrite:
      uri: &quot;/uaa/oauth&quot;
    route:
    - destination:
        port:
          number: 8090
        host: &quot;host.docker.internal&quot;
  - match:
    - uri:
        prefix: /uaa
    rewrite:
      uri: &quot;/uaa&quot;
    route:
    - destination:
        port:
          number: 8090
        host: &quot;host.docker.internal&quot;        
---
apiVersion: &quot;security.istio.io/v1beta1&quot;
kind: &quot;RequestAuthentication&quot;
metadata:
  name: &quot;ra-product-composite&quot;
spec:
  selector:
    matchLabels:
      app: &quot;product-composite&quot;
  jwtRules:
  - issuer: &quot;http://uaa:8090/uaa/oauth/token&quot;
    jwksUri: &quot;http://host.docker.internal:8090/uaa/token_keys&quot;
    forwardOriginalToken: true

</code></pre>
<h3>Workaround 2:</h3>
<p>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:</p>
<pre><code>    jwksUri: &quot;http://uaa.mynamespace.svc.cluster.local:8090/uaa/token_keys&quot;
</code></pre>
<p>I'm totally sure that is a silly configuration parameter, but I'm not able to find it! Thanks in advance</p>

Sourcerer
<p><code>jwksUri: &quot;http://uaa:8090/uaa/token_keys&quot;</code> will not work from istiod, because <code>http://uaa</code> will be interpreted as <code>http://uaa.istio-system.svc.cluster.local</code>. That's why your workaround are solving the problem.</p>
<p>I don't understand why your workaround 2 is not a sufficient solution. Let's say your uaa service runs in namespace <code>auth</code>. If you configure the <code>jwksUri</code> with <code>uaa.auth.svc.cluster.local</code>, every kubernetes pod is able to call it, regardless of it's namespace.</p>
