136_auth_deployment_azure - amresh087/Question GitHub Wiki
This document explains how to implement authentication and authorization for microservices using Azure native services, replacing a custom auth-service.
- user-service
- cloud-gateway-service
- auth-service (custom JWT)
- Azure-managed authentication
- No custom auth-service
- JWT validation at gateway
- Zero Trust security
Client | v Azure Active Directory | v Cloud Gateway (JWT Validation) | v User Service / Other Microservices
Key Principle: :contentReference[oaicite:0]{index=0} acts as the central authentication provider and replaces auth-service.
| Component | Description |
|---|---|
| Azure Active Directory | User authentication, OAuth2, OpenID Connect, JWT issuance |
| Azure API Management | Optional API gateway, JWT validation, throttling |
| Azure Kubernetes Service | Runs microservices |
| Azure Managed Identity | Service-to-service authentication |
| Azure Key Vault | Secrets and certificates |
- User login
- Password and MFA
- JWT token issuance
- Token signing and key rotation
- JWT validation
- Authorization using scopes
- Business logic
Azure authentication is based on App Registrations. Two app registrations are required.
Expose API and create scope:
api://user-service/read
Meaning: Any client with this scope can call user-service.
Represents frontend, mobile app, or Postman.
user-service/read
Client → Azure AD Login Page → User authenticates → Azure AD issues JWT access token
{
"iss": "https://login.microsoftonline.com/<tenant-id>/v2.0",
"aud": "api://user-service",
"scp": "read",
"sub": "user-id",
"exp": 1710000000
}
Tokens are signed by Microsoft. Services never generate tokens.
- Validate JWT signature
- Verify issuer and expiry
- Enforce authorization rules
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: https://login.microsoftonline.com/<tenant-id>/v2.0
scp: read → SCOPE_read
- Security duplicated in every service
- Harder to manage
- Single enforcement point
- Consistent security
Even after gateway validation, user-service validates JWT again.
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: https://login.microsoftonline.com/<tenant-id>/v2.0
user-service → order-service
- Do not forward user JWT
- Do not use shared secrets
Each service has its own Azure identity.
DefaultAzureCredential credential =
new DefaultAzureCredentialBuilder().build();
| Secret | Storage |
|---|---|
| Database password | Azure Key Vault |
| API keys | Azure Key Vault |
Secrets must never be stored in Git, YAML files, or Docker images.
- Central Authentication – Azure AD
- Zero Trust – JWT validation everywhere
- Least Privilege – OAuth scopes
- No Secrets – Managed Identity
- Defense in Depth – Gateway + service validation
We replaced a custom auth-service with Azure AD. Authentication is centralized, JWTs are issued by Azure, validated at the gateway, and microservices act as OAuth2 resource servers. Service-to-service communication uses Managed Identity.