Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Application Service Mesh/ User Guide/ Security/ Authenticating JWT Requests on the Ingress Gateway Using ASM

Authenticating JWT Requests on the Ingress Gateway Using ASM

Updated on 2024-10-09 GMT+08:00

This section describes how to authenticate JWT requests on the ingress gateway using ASM to ensure that users access services through the ingress gateway with a reliable access token.

Preparations

  1. A service mesh of version 1.13/1.15 or 1.18 has been created.
  2. The httpbin service that passes the diagnosis exists in the mesh. The image is httpbin, the port protocol is HTTP, and the port number is 80.
  3. An accessible gateway has been created for the httpbin service in the mesh.

Creating JWT Authentication

  1. Create a JWK.

    1. Visit JWT tool website, set Algorithm to RS512, and obtain the public key (PUBLIC KEY).
      Figure 1 Generating a public key
    2. Select PEM-to-JWK (RSA Only) in the JWK to PEM Convertor online tool, enter the public key obtained in the previous step, and click submit to convert the public key into a JWK.
      Figure 2 Converting the public key to a JWK
      {"kty":"RSA","e":"AQAB","kid":"a78641b9-d81e-4241-b35a-71726c3fa053","n":"u1SU1LfVLPHCozMxH2Mo4lgOEePzNm0tRgeLezV6ffAt0gunVTLw7onLRnrq0_IzW7yWR7QkrmBL7jTKEn5u-qKhbwKfBstIs-bMY2Zkp18gnTxKLxoS2tFczGkPLPgizskuemMghRniWaoLcyehkd3qqGElvW_VDL5AaWTg0nLVkjRo9z-40RQzuVaE8AkAFmxZzow3x-VJYKdjykkJ0iT9wCS0DRTXu269V264Vf_3jvredZiKRkgwlL9xNAwxXFg0x_XFw005UWVRIkdgcKWTjpBP2dPwVZ4WWC-9aGVd-Gyn1o0CLelf4rEjGoXbAAEgAqeGUxrcIlbjXfbcmw"}

  2. Create JWT authentication.

    1. Log in to the ASM console and click the name of the target service mesh to go to its details page.
    2. In the navigation pane, choose Service Management. In the upper right corner of the list, select the namespace that your services belong to.
    3. Locate the httpbin service and click Security in the Operation column. In the window that slides out from the right, click JWT Authentication and then Configure now. In the displayed dialog box, set the following parameters:
      • Issuer: issuer of the JWT. Set this parameter to test.
      • Audience: JWT audiences who use the JWT token to access the target service. Set this parameter to ASM.
      • JWKS: JWT information. Set this parameter to {"keys": [JWK created in 1]}. For example, if the JWK created in 1 is {"kty":"RSA","e":"AQAB","kid":"a78641b9-d81e-4241-b35a-71726c3****"}, the value of JWKS is {"keys": [{"kty":"RSA","e":"AQAB","kid":"a78641b9-d81e-4241-b35a-71726c3****"}]}.
      Figure 3 Creating JWT authentication
    4. Click OK.

Checking Whether JWT Authentication Takes Effect

  1. Use JWT tool to encode the JWT request information into a JWT token.

    Enter the following JWT request information in the Decoded area. The automatically converted JWT token is displayed in the Encode area.

    • HEADER: Set alg to RS512, enter kid in the JWK created in 1, and set typ to JWT.
    • PAYLOAD: Set iss to test and aud to ASM. Ensure that the values are the same as the issuer and token audience configured in 2.
    • VERIFY SIGNATURE: The value must be the same as the public key in 1.a.
    Figure 4 Creating a JWT token

  2. Access the httpbin service through the ingress gateway.

    1. Run the following commands to access the service with the JWT token created in 1:

      TOKEN=JWT token created by the 1.

      curl -I -H "Authorization: Bearer $TOKEN" http:// {External access address of the httpbin service}/

      Expected outputs:

      HTTP/1.1 200 OK
      server: istio-envoy
      date: Wed, 21 Sep 2022 03:11:48 GMT
    2. Run the following command to access the service with an invalid JWT token:

      curl -I -H "Authorization: Bearer invalidToken" http:// {External access address of the httpbin service}/

      Expected outputs:

      HTTP/1.1 401 Unauthorized
      www-authenticate: Bearer realm="http://***.***.***.***:***/", error="invalid_token"
      content-length: 145
      content-type: text/plain
      date: Wed, 21 Sep 2022 03:12:54 GMT
      server: istio-envoy
      x-envoy-upstream-service-time: 19
    3. Modify the JWT authentication created in 2, leave the aud empty (indicating that the service can be accessed by any services), and run the following command to access the service with the JWT token created in 1:

      curl -I -H "Authorization: Bearer $TOKEN" http:// {External access address of the httpbin service}/

      Expected outputs:

      HTTP/1.1 200 OK
      server: istio-envoy
      date: Wed, 21 Sep 2022 03:20:07 GMT
    4. Run the following command to access the service without the JWT token:

      curl -I http:// {External access address of the httpbin service}/

      Expected outputs:

      HTTP/1.1 403 Forbidden
      content-length: 85
      content-type: text/plain
      date: Wed, 21 Sep 2022 03:29:31 GMT
      server: istio-envoy
      x-envoy-upstream-service-time: 6

    According to the preceding outputs, the request with the correct JWT token can access the service, and the request with an incorrect JWT token or without a JWT token cannot access the service. This means the request identity authentication takes effect.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback