Request Authentication
Request Authentication specifies the methods that a workload supports for request identity verification. A gateway or sidecar authenticates requests based on the configured authentication rules. If a request contains invalid authentication information, the request is rejected. A request without authentication information is also authenticated, but it is not assigned a legitimate identity. To allow only authenticated requests, you can use an AuthorizationPolicy. This topic describes the configuration examples and field descriptions for Request Authentication.
Configuration examples
Example 1: Require all requests to httpbin workloads to carry a JWT
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: httpbin
namespace: foo
spec:
selector:
matchLabels:
app: httpbin
jwtRules:
- issuer: "issuer-foo"
jwksUri: https://example.com/.well-known/jwks.json
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: httpbin
namespace: foo
spec:
selector:
matchLabels:
app: httpbin
rules:
- from:
- source:
requestPrincipals: ["*"]Example 2: Require all requests to workloads in the default namespace to carry a JWT
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: req-authn-for-all
namespace: default
spec:
jwtRules:
- issuer: "issuer-foo"
jwksUri: https://example.com/.well-known/jwks.json
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: require-jwt-for-all
namespace: default
spec:
rules:
- from:
- source:
requestPrincipals: ["*"]Example 3: Allow different JWTs for different hosts
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: httpbin
namespace: foo
spec:
selector:
matchLabels:
app: httpbin
jwtRules:
- issuer: "issuer-foo"
- issuer: "issuer-bar"
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: httpbin
namespace: foo
spec:
selector:
matchLabels:
app: httpbin
rules:
- from:
- source:
requestPrincipals: ["issuer-foo/*"]
to:
- operation:
hosts: ["example.com"]
- from:
- source:
requestPrincipals: ["issuer-bar/*"]
to:
- operation:
hosts: ["another-host.com"]Example 4: Extract a JWT payload and add it to a request header
This example extracts the foo claim from the JWT payload and adds it to the x-jwt-claim-foo request header.
apiVersion: security.istio.io/v1
kind: RequestAuthentication
metadata:
name: "jwt-example"
namespace: foo
spec:
selector:
matchLabels:
app: httpbin
jwtRules:
- issuer: "issuer-foo"
jwksUri: "https://example.com/.well-known/jwks.json"
outputClaimToHeaders:
- header: "x-jwt-claim-foo"
claim: "foo"Field descriptions
RequestAuthentication
Field | Type | Required | Description |
selector | No | Defines the workloads in the current namespace to which this configuration applies. If this configuration is in the root namespace (istio-system), the selector matches workloads in all namespaces. If you do not configure this field, the selector matches all workloads. | |
jwtRules | No | Defines a list of JSON Web Token (JWT) rules to authenticate requests on specified workloads. The valid identity of subsequent requests is fetched from the JWT. A rule is triggered only when the JWT appears in the specified location in the request. If a JWT fails authentication based on the configuration in the JWTRule, the request is rejected. Important A request cannot carry different tokens in multiple locations. The identity of such a request is undefined. |
JWTRule
A JWT is used for identity verification and is defined in RFC 7519. For more information about how to use JWTs in an authentication flow, see OAuth 2.0 and OIDC 1.0.
JWT example | Description |
| The JWT must be issued by |
| Indicates a token that is not in the default location. In this example, the token is in the |
Field | Type | Required | Description |
| string | Yes | Specifies the issuer of the JWT. JWTs with a different issuer are rejected. |
| string[] | No | A list of audiences for the JWT. These audiences are allowed to access applications in the grid. Otherwise, the request is rejected. If audiences is empty, the audiences for the request are not restricted. |
| string | Yes | The JWKS used for the JWT. |
| No | The headers where the JWT is expected. The following example shows that the JWT is expected to be fetched from the | |
| string | No | The request parameters where the JWT is expected. The following example shows that the JWT is expected to be passed through the Important A request cannot carry different JWTs in different locations. Otherwise, the principal of the request is undefined. |
| string | No | Specifies a header name. If a JWT is successfully authenticated, the verified information is passed to the upstream service. The forwarded data is the Base64-encoded JWT payload in JSON format. If you do not specify a header name, this header is not added. |
| bool | No | The default value is
|
| No | This field specifies a series of operations to copy a JWT claim to an HTTP header after the JWT is successfully authenticated. Unlike output_payload_to_header, it lets you output a single JWT claim instead of the entire JWT payload. The HTTP header specified for each operation in the list must be unique. Nested claims of the string, integer, or Boolean type are also supported. |
ClaimToHeader
This struct specifies the rules for copying a JWT claim to a request header.
Field | Type | Required | Description |
| string | Yes | The name of the request header to create. If the header already exists in the request, it is overwritten. |
| string | Yes | The name of the JWT claim to copy. Only claims of the String, Int, or Bool type are supported. If the claim does not exist or the claim type is not supported, the header is not created. |
JWTHeader
Specifies the header where the JWT is located.
Field | Type | Required | Description |
| string | Yes | The name of the HTTP header. |
| string | No | The prefix used to find the token in the request. Before decoding the token, the gateway or sidecar removes this prefix. For example, for the header
|