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.
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.
We have tried a few different options but are yet to have any luck.
We can get AuthenticationPolicy to work for pod to pod traffic using "from" and the source being the IP address of the pod in namespace x:
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: "request-jwt"
namespace: y
spec:
jwtRules:
- issuer: "https://keycloak.example.com/auth/realms/istio"
jwksUri: "https://keycloak.example.com/auth/realms/istio/protocol/openid-connect/certs"
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: "jwt-auth"
namespace: y
spec:
action: ALLOW
rules:
- from:
- source:
ipBlocks: ["10.43.5.175"]
When we add when block for jwt it doesn't work:
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: "request-jwt"
namespace: y
spec:
jwtRules:
- issuer: "https://keycloak.example.com/auth/realms/istio"
jwksUri: "https://keycloak.example.com/auth/realms/istio/protocol/openid-connect/certs"
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: "jwt-auth"
namespace: y
spec:
action: ALLOW
rules:
- from:
- source:
ipBlocks: ["10.43.5.175"]
when:
- key: request.auth.claims[iss]
values: ["https://keycloak.example.com/auth/realms/istio"]
Also tried this but doesn't seem to work either:
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: "request-jwt"
namespace: y
spec:
jwtRules:
- issuer: "https://keycloak.example.com/auth/realms/istio"
jwksUri: "https://keycloak.example.com/auth/realms/istio/protocol/openid-connect/certs"
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: "deny-invalid-jwt"
namespace: y
spec:
action: DENY
rules:
- from:
- source:
notRequestPrincipals: ["*"]
Thanks in advance!