When multiple services share an ingress gateway, each service typically implements its own token validation. This duplicates logic and creates inconsistent security enforcement. JSON Web Token (JWT) authentication on an Alibaba Cloud Service Mesh (ASM) ingress gateway centralizes token validation at the gateway level -- only requests with valid JWTs reach backend services.
How JWT authentication works on the gateway
JWT authentication on an ingress gateway relies on two Istio security resources that work together:
| Resource | Role | What happens without it |
|---|---|---|
| RequestAuthentication | Defines how the gateway validates tokens: the trusted issuer and the JSON Web Key Set (JWKS) used to verify signatures | Requests are not validated at all |
| AuthorizationPolicy | Enforces that specific paths require a valid token | Requests without a token pass through freely, even to protected paths |
The ASM console wizard configures both resources. Step 5 (JWT Config) defines the RequestAuthentication parameters. Step 6 (Matching Rules) defines the AuthorizationPolicy parameters.
A RequestAuthentication resource alone does not block requests without a token. You must also configure matching rules (step 6) to generate the AuthorizationPolicy that denies unauthenticated access to the specified paths.
For more information about JWT, see JWT.
Prerequisites
Before you begin, make sure that you have:
Configure JWT authentication
Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.
On the Mesh Management page, click the name of the target ASM instance. In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.
On the Ingress Gateway page, click the name of the ingress gateway.
In the gateway navigation pane, choose Gateway Security > JWT certification.
In the JWT Config step of the wizard, turn on Enable gateway JWT authentication, configure the following parameters, and then click Next.
Advanced configuration options Click AdvancedConfig to open the JWT Rules Advanced Options dialog box. The following options are available: Click OK to save the advanced settings.Example JWKS value
Parameter Description Issuer The JWT issuer identifier. This value must match the issclaim in the tokens you want to accept. Example:testing@secure.istio.ioJWKS Source The source of the JWKS used to verify token signatures. Select jwks to provide the key set inline Key The JWKS content. Paste the JSON key set that contains the public keys for signature verification. See the example below AdvancedConfig Opens the JWT Rules Advanced Options dialog box for additional settings (see below) Option Description JWTToken Position Where the gateway extracts the JWT from incoming requests. The default location is the Authorizationheader with aBearerprefix. You can specify a custom header or query parameterJWT Passthrough When enabled, forwards the original token to upstream services. Use this when backend services need to read JWT claims directly Transmit Payload through Header Extracts specific JWT claims and passes them as HTTP headers to backend services. Use this to share user identity or role information with upstream services without requiring them to parse the JWT { "keys": [ { "e": "AQAB", "kid": "DHFbpoIUqrY8t2zpA2qXfCmr5VO5ZEr4RzHU_-envvQ", "kty": "RSA", "n": "xAE7eB6qugXyCAG3yhh7pkDkT65pHymX-P7KfIupjf59vsdo91bSP9C8H07pSAGQO1MV_xFj9VswgsCg4R6otmg5PV2He95lZdHtOcU5DXIg_pbhLdKXbi66GlVeK6ABZOUW3WYtnNHD-91gVuoeJT_DwtGGcp4ignkgXfkiEm4sw-4sfb4qdt5oLbyVpmW6x9cfa7vs2WTfURiCrBoUqgBo_-4WTiULmmHSGZHOjzwa8WtrtOQGsAFjIbno85jp6MnGGGZPYZbDAa_b3y5u-YpW7ypZrvD8BgtKVjgtQgZhLAGezMt0ua3DRrWnKqTZ0BJ_EyxOGuHJrLsn00fnMQ" } ] }In the Matching Rules step, configure the following parameters and click Submit. In this example, Auth If Matched is selected with path
/productpage:Requests to
/productpagemust carry a valid JWT.Requests to other paths do not require a JWT.
NoteFor non-matched paths, requests without a token are allowed, but requests with an invalid token are still rejected. The gateway validates any JWT it encounters, regardless of the path.
Parameter Description Match Mode Determines how matching rules interact with authentication. Auth If Matched -- require JWT authentication for requests that match the rules. Bypass Auth If Matched -- skip JWT authentication for requests that match the rules Matching Rules Specifies which requests the match mode applies to. Select Custom Matching Rules, turn on Path, and enter the path. Example: /productpageA success message confirms that JWT authentication is configured. The console displays the generated Istio security resources. Click YAML to inspect the RequestAuthentication and AuthorizationPolicy configurations.
Verify the configuration
After you configure JWT authentication, run the following tests to confirm it works as expected.
Set a test token as an environment variable:
TOKEN=eyJhbGciOiJSUzI1NiIsImtpZCI6IkRIRmJwb0lVcXJZOHQyenBBMnFYZkNtcjVWTzVaRXI0UnpIVV8tZW52dlEiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjQ2ODU5ODk3MDAsImZvbyI6ImJhciIsImlhdCI6MTUzMjM4OTcwMCwiaXNzIjoidGVzdGluZ0BzZWN1cmUuaXN0aW8uaW8iLCJzdWIiOiJ0ZXN0aW5nQHNlY3VyZS5pc3Rpby5pbyJ9.CfNnxWP2tcnR9q0vxyxweaF3ovQYHYZl82hAUsn21bwQd9zP7c-LS9qd_vpdLG4Tn1A15NxfCjp5f7QNBUo-KC9PJqYpgGbaXhaGx7bEdFWjcwv3nZzvc7M__ZpaCERdwU7igUmJqYGBYQ51vr2njU9ZimyKkfDe3axcyiBZde7G6dabliUosJvvKOPcKIWPccCgefSj_GNfwIip3-SsFdlR7BtbVUcqR-yv-XOxJ3Uc1MI0tz3uMiiZcyPV7sNCU4KRnemRIMHVOfuvHsU60_GhGbiSFzgPTAa9WTltbnarTbxudb_YEOx12JiwYToeX0DCPb43W1tzIBxgm8NxUgReplace <gateway-ip> with the IP address of your ASM ingress gateway in all test commands below.
Test 1: Valid token to a protected path -- expect 200
curl -I http://<gateway-ip>/productpage -H "Authorization: Bearer $TOKEN"Expected response:
HTTP/1.1 200 OK
content-type: text/html; charset=utf-8
content-length: 4294
server: istio-envoyTest 2: No token to a protected path -- expect 403
curl -I http://<gateway-ip>/productpageExpected response:
HTTP/1.1 403 Forbidden
content-length: 19
content-type: text/plain
server: istio-envoyTest 3: Invalid token to a protected path -- expect 401
curl -I http://<gateway-ip>/productpage -H "Authorization: Bearer invalid token"Expected response:
HTTP/1.1 401 Unauthorized
content-type: text/plain
server: istio-envoyTest 4: No token to an unprotected path -- expect 200
curl -I http://<gateway-ip>/api/v1/products/1Expected response:
HTTP/1.1 200 OK
content-type: application/json
content-length: 195
server: istio-envoyExpected results summary
| Test | Scenario | Expected status | Access |
|---|---|---|---|
| 1 | Valid JWT to /productpage | 200 OK | Allowed |
| 2 | No JWT to /productpage | 403 Forbidden | Denied |
| 3 | Invalid JWT to /productpage | 401 Unauthorized | Denied |
| 4 | No JWT to /api/v1/products/1 | 200 OK | Allowed |
If all four tests return the expected status codes, JWT authentication is working correctly.