<p>We have recently setup istio on our kubernetes cluster and are trying to see if we can use RequestAuthentication and AuthenticationPolicy to enable us to only allow a pod in namespace x to communicate with a pod in namespace y when it has a valid jwt token.</p>
<p>All the examples I have seen online seem to only apply for end user authentication via the gateway rather than internal pod to pod communication.</p>
<p>We have tried a few different options but are yet to have any luck.</p>
<p>We can get AuthenticationPolicy to work for pod to pod traffic using &quot;from&quot; and the source being the IP address of the pod in namespace x:</p>
<pre><code>apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
 name: &quot;request-jwt&quot;
 namespace: y
spec:
  jwtRules:
  - issuer: &quot;https://keycloak.example.com/auth/realms/istio&quot;
    jwksUri: &quot;https://keycloak.example.com/auth/realms/istio/protocol/openid-connect/certs&quot;
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
  name: &quot;jwt-auth&quot;
  namespace: y
spec:
  action: ALLOW
  rules:
  - from:
    - source:
        ipBlocks: [&quot;10.43.5.175&quot;]
</code></pre>
<p>When we add when block for jwt it doesn't work:</p>
<pre><code>apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
 name: &quot;request-jwt&quot;
 namespace: y
spec:
  jwtRules:
  - issuer: &quot;https://keycloak.example.com/auth/realms/istio&quot;
    jwksUri: &quot;https://keycloak.example.com/auth/realms/istio/protocol/openid-connect/certs&quot;
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
  name: &quot;jwt-auth&quot;
  namespace: y
spec:
  action: ALLOW
  rules:
  - from:
    - source:
        ipBlocks: [&quot;10.43.5.175&quot;]
    when:
     - key: request.auth.claims[iss]
       values: [&quot;https://keycloak.example.com/auth/realms/istio&quot;]
</code></pre>
<p>Also tried this but doesn't seem to work either:</p>
<pre><code>apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
 name: &quot;request-jwt&quot;
 namespace: y
spec:
  jwtRules:
  - issuer: &quot;https://keycloak.example.com/auth/realms/istio&quot;
    jwksUri: &quot;https://keycloak.example.com/auth/realms/istio/protocol/openid-connect/certs&quot;
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
  name: &quot;deny-invalid-jwt&quot;
  namespace: y
spec:
  action: DENY
  rules:
  - from:
    - source:
        notRequestPrincipals: [&quot;*&quot;]
</code></pre>
<p>Thanks in advance!</p>

gdix0n
<p>Yes, it is possible to use both Authorization Policies and Request Authentications.</p>
<p>But debugging is quite difficult because a lot is based on your environment and the JWT that is being used, and so on.</p>
<p>To troubleshoot these kinds of issues I'd start by setting the rbac scoped logs to debug for the services envoy proxy.
In the rbac debug logs you'll see the data extracted from the JWT and stored into filter metadata.
What you'll frequently find is that:</p>
<ul>
<li>The issuer in the filter metadata might not match the one in the RequestAuthentication resource, etc.</li>
</ul>
<p>Learn more about logging scopes here <a href="https://istio.io/v1.12/docs/ops/diagnostic-tools/component-logging/#logging-scopes" rel="nofollow noreferrer">https://istio.io/v1.12/docs/ops/diagnostic-tools/component-logging/#logging-scopes</a></p>
