Name | Type | Description |
metadata.name | string | PeerAuthentication name. |
metadata.namespace | string | PeerAuthentication namespace. |
spec.selector | map<string, string> | PeerAuthentication uses an entered label key-value pair and an entered namespace to match a scope of workloads to which configurations are to be delivered. If the entered namespace is istio-system and the selector field is left blank, the policy takes effect for the entire mesh. If the entered namespace is not istio-system and the selector field is left blank, the policy takes effect for the entered namespace. If the entered namespace is not istio-system and the selector field is set to a valid key-value pair, the policy takes effect for the workload that is matched based on the selector in the entered namespace. |
spec.mtls.mode | - | mTLS mode. Four modes are supported: UNSET |
spec.portLevelMtls | map<uint32, mTLS mode> | mTLS mode at the port level. |
curl http://product.base.svc.cluster.local:7000/product
to access the product service in the base namespace in plaintext mode.apiVersion: security.istio.io/v1beta1kind: PeerAuthenticationmetadata:name: base-strictnamespace: basespec:mtls:mode: STRICT
Name | Type | Description |
metadata.name | string | RequestAuthentication name. |
metadata.namespace | string | RequestAuthentication namespace. |
spec.selector | map<string, string> | RequestAuthentication uses an entered label key-value pair and an entered namespace to match a scope of workloads to which configurations are to be delivered. If the entered namespace is istio-system and the selector field is left blank, the policy takes effect for the entire mesh. If the entered namespace is not istio-system and the selector field is left blank, the policy takes effect for the entered namespace. If the entered namespace is not istio-system and the selector field is set to a valid key-value pair, the policy takes effect for the workload that is matched based on the selector in the entered namespace. |
spec.jwtRules.issuer | string | |
spec.jwtRules.audiences | string[] | List of JWT audiences that are allowed to access. The service name will be accepted if the audience list is empty. |
spec.jwtRules.jwksUri | string | Public key URL for verifying JWT signatures. For details, see OpenID Discovery. When both the jwksUri and jwks fields are configured, jwksUri is ignored. |
spec.jwtRules.jwks | string | Public key in a JSON Web Key Set used to verify JWT signatures. When both the jwksUri and jwks fields are configured, jwksUri is ignored. |
spec.jwtRules.fromHeaders | map<string,string>[] | List of locations in the header from which the JWT is extracted. |
spec.jwtRules.fromParams | string[] | Parameters in the header from which the JWT is extracted. For example, the JWT is extracted from the parameter mytoken ( /path?my_token= ). |
spec.jwtRules.outputPayloadToHeader | string | Header name output by a JWT payload in a case of successful verification. The forwarded data is base64_encoded(jwt_payload_in_JSON) . If this field is left blank, a JWT payload is not output by default. |
spec.jwtRules.forwardOriginalToken | bool | Whether to forward the raw JWT to upstream. The default value is false . |
httpbin.foo
and then configure this service to be exposed to the public network through an ingress gateway.apiVersion: v1kind: Namespacemetadata:name: foolabels:istio.io/rev: 1-6-9 # Enable automatic sidecar injection for the namespace (The Istio version is 1.6.9).spec:finalizers:- kubernetes---apiVersion: v1kind: ServiceAccountmetadata:name: httpbinnamespace: foo---apiVersion: v1kind: Servicemetadata:name: httpbinnamespace: foolabels:app: httpbinservice: httpbinspec:ports:- name: httpport: 8000targetPort: 80selector:app: httpbin---apiVersion: apps/v1kind: Deploymentmetadata:name: httpbinnamespace: foospec:replicas: 1selector:matchLabels:app: httpbinversion: v1template:metadata:labels:app: httpbinversion: v1spec:serviceAccountName: httpbincontainers:- image: docker.io/kennethreitz/httpbinimagePullPolicy: IfNotPresentname: httpbinports:- containerPort: 80
apiVersion: networking.istio.io/v1alpha3kind: Gatewaymetadata:name: httpbin-gatewaynamespace: foospec:selector:app: istio-ingressgatewayistio: ingressgatewayservers:- port:number: 80name: httpprotocol: HTTPhosts:- "*"---apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:name: httpbinnamespace: foospec:hosts:- "*"gateways:- httpbin-gatewayhttp:- route:- destination:port:number: 8000host: httpbin.foo.svc.cluster.local
curl "$INGRESS_IP:80/headers" -s -o /dev/null -w "%{http_code}\\n"
. Note that you need to replace $INGRESS_IP
in the statement with the IP address of your ingress gateway. In normal condition, a 200
return code is returned.apiVersion: "security.istio.io/v1beta1"kind: "RequestAuthentication"metadata:name: "jwt-example"namespace: istio-systemspec:selector:matchLabels:istio: ingressgatewayapp: istio-ingressgatewayjwtRules:- issuer: "testing@secure.istio.io"jwksUri: "https://raw.githubusercontent.com/istio/istio/release-1.9/security/tools/jwt/samples/jwks.json"
$INGRESS_IP
in the code with the IP address of your ingress gateway. The ingress gateway does not allow the request carrying the invalid JWT token and therefore returns a 401
return code.curl --header "Authorization: Bearer deadbeef" "$INGRESS_IP:80/headers" -s -o /dev/null -w "%{http_code}\\n"
$INGRESS_IP
in the code with the IP address of your ingress gateway. The ingress gateway allows the request carrying the illegal JWT token and therefore returns a 200
return code.TOKEN=$(curl https://raw.githubusercontent.com/istio/istio/release-1.9/security/tools/jwt/samples/demo.jwt -s)curl --header "Authorization: Bearer $TOKEN" "$INGRESS_IP:80/headers" -s -o /dev/null -w "%{http_code}\\n"
apiVersion: security.istio.io/v1beta1kind: AuthorizationPolicymetadata:name: frontend-ingressnamespace: istio-systemspec:selector:matchLabels:app: istio-ingressgatewayistio: ingressgatewayrules:- from:- source:notRequestPrincipals:- '*'action: DENY
curl "$INGRESS_IP:80/headers" -s -o /dev/null -w "%{http_code}\\n"
. It is found that the access fails and a 403
return code is returned, indicating that the AuthorizationPolicy policy has taken effect.
Was this page helpful?