I’m trying to setup a namespace such that any services exposed through an ingress gateway/virtual service require end user JWT authentication, but the same service when accessed from another internal service will use normal mTLS authentication.
Here is my general setup:
Gateway and Virtual Service
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "{{domain}}"
tls:
httpsRedirect: true
- port:
number: 443
name: https
protocol: HTTPS
tls:
mode: SIMPLE
credentialName: "{{certificate-secret-name}}"
hosts:
- "{{domain}}"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: ingress
spec:
hosts:
- "{{domain}}"
gateways:
- gateway
http:
- match:
- uri:
prefix: /auth/
- uri:
prefix: /auth
rewrite:
uri: "/"
route:
- destination:
host: auth
port:
number: 8000
- match:
- uri:
prefix: /api/
- uri:
prefix: /api
route:
- destination:
host: "api"
port:
number: 8000
Auth Policy
apiVersion: "authentication.istio.io/v1alpha1"
kind: "Policy"
metadata:
name: "auth"
spec:
targets:
- name: "api"
peers:
- mtls:
origins:
- jwt:
issuer: "{{domain}}"
jwksUri: "https://{{domain}}/.well-known/jwks.json"
principalBinding: USE_ORIGIN
With this setup external JWT auth works. Any incoming request to the ‘api’ service requires a JWT.
The problem I’m hitting, which I thought would be solved by the ‘peers’ section in the auth policy is that it looks like JWT auth is also required when another service (lets call that service ‘limits’) tries to make a request to the ‘api’ service.
This is the response:
server returned error: HTTP/1.1 401 Unauthorized
If I remove the auth policy, communication is allowed again.
I have to assume that a typical use to end user authentication is for requests that originate outside of the mesh and that the same services that ingress will communicate with should also be accessible by other internal services that live within the mesh without requiring end user authentication.
Is there an additional auth policy I need to add to inform the mesh to not require end user authentication for internal service-service communication?