Skip to content

Commit 9c486cf

Browse files
Design Document: Mutual TLS (mTLS) Proof-of-Possession (PoP) Tokens Implementation (#5087)
* init * tasks * pr comments * Add DSTS and non-standard clouds endpoints. --------- Co-authored-by: Gladwin Johnson <[email protected]>
1 parent eb39be7 commit 9c486cf

File tree

2 files changed

+222
-0
lines changed

2 files changed

+222
-0
lines changed

docs/sni_mtls_pop_token_design.md

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
# Overview
2+
3+
Bearer tokens are vulnerable to theft. Proof-of-Possession (PoP) tokens mitigate this by binding tokens to a specific client certificate. mTLS PoP tokens enhance this security by using mutual TLS (mTLS) to ensure the token is tied to the certificate used for authentication.
4+
5+
![Diagram outlining the mTLS PoP flow](../media/mtls_pop.png)
6+
7+
## Key Points
8+
9+
- mTLS PoP tokens are compliant with [RFC 8705](https://datatracker.ietf.org/doc/html/rfc8705).
10+
- Tokens are bound to certificates used in mTLS connections with both the ESTS and the resource server.
11+
12+
## SNI Certificate Scenario
13+
14+
[Subject Name Issuer (SNI)](https://review.learn.microsoft.com/en-us/azure-usage-billing/howto/emission-setup/sdk-auth-sni) certificates are issued by MSFT trusted certificate authorities ([OneCert](https://eng.ms/docs/products/onecert-certificates-key-vault-and-dsms/onecert-customer-guide/onecert/docs)) and provide a secure way to bind tokens to certificates. This method requires setting the `sendX5C` property when using MSAL.
15+
16+
## Token Flow
17+
18+
### Certificate Acquisition
19+
20+
1. The client sends an SNI certificate associated with a 1P application in the token request (cert C).
21+
2. The certificate is used to establish mTLS with ESTS.
22+
23+
### Token Binding
24+
25+
1. ESTS uses the mTLS certificate also as the authentication certificate.
26+
2. A token bound to cert C is issued by ESTS.
27+
28+
### API Call with Bound Token
29+
30+
- The client makes a call to the resource server using the token over mTLS with cert C.
31+
32+
## MSAL Design Details for SNI
33+
34+
### New API Additions
35+
36+
#### `WithMtlsProofOfPossession()` at CCA request level
37+
38+
- Adds support for mTLS PoP tokens and uses the certificate from the CCA application level `.WithCertificate(certificate, true)`.
39+
- Token type will be `mtls_pop`.
40+
- Grant Type will be `ClientCredentials`.
41+
- Request **should not** contain `client_assertion_type` or `client_assertion`.
42+
43+
### MTLS Endpoint Usage
44+
45+
The mTLS PoP flow relies on tenanted endpoints with support for regional configurations. The behavior varies based on the cloud environment:
46+
47+
#### Public Cloud
48+
49+
The base endpoint for public clouds is:
50+
51+
`https://{region}.mtlsauth.microsoft.com/{tenant_id}`
52+
53+
Example: Specifying the `westus` region results in:
54+
55+
`https://eastus.mtlsauth.microsoft.com/{tenant_id}`
56+
57+
#### Sovereign Clouds
58+
59+
For sovereign clouds, the base endpoint is adjusted for the cloud-specific environment. For instance:
60+
61+
- Azure Government: `https://{region}.mtlsauth.microsoftonline.us/{tenant_id}`
62+
- Azure China: `https://{region}.mtlsauth.partner.microsoftonline.cn/{tenant_id}`
63+
64+
#### DSTS Cloud
65+
66+
DSTS does not use regions. The standard DSTS endpoint format is:
67+
68+
Azure DSTS: https://dsts.core.azure-test.net/{tenant_id}
69+
70+
#### Non-Standard Clouds
71+
72+
For non-standard clouds, the endpoint is formed by adding `{region}.mtlsauth` to the authority URL
73+
74+
Note: In MSAL .NET, this functionality is implemented in the [RegionAndMtlsDiscoveryProvider class](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/main/src/client/Microsoft.Identity.Client/Instance/Discovery/RegionAndMtlsDiscoveryProvider.cs). Developers can refer to its unit [tests](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/eb39be7b002b38d7c2885078c4e506160014e458/tests/Microsoft.Identity.Test.Unit/PublicApiTests/MtlsPopTests.cs#L556) to gain further clarity on the logic and expected behavior.
75+
76+
Note: App developers create an MSAL Confidential Client Application (CCA) object with a certificate, which is used both to authenticate the app and to initiate the HTTP mTLS connection to the regional ESTS endpoint. ESTS validates the certificate during the mTLS handshake and also uses it as the authentication certificate to issue the token.
77+
78+
#### Sample usage in MSAL .NET
79+
80+
```csharp
81+
string clientId = "163ffef9-a313-45b4-ab2f-c7e2f5e0e23e";
82+
string authority = "https://login.microsoftonline.com/bea21ebe-8b64-4d06-9f6d-6a889b120a7c";
83+
string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
84+
85+
X509Certificate2 certificate = GetCertificateFromStore("Use The Lab Auth Cert");
86+
87+
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(clientId)
88+
.WithAuthority(authority)
89+
.WithAzureRegion("westus")
90+
.WithCertificate(certificate, true)
91+
.WithExperimentalFeatures(true)
92+
.Build();
93+
94+
AuthenticationResult result = await app.AcquireTokenForClient(scopes).WithMtlsProofOfPossession()
95+
.WithExtraQueryParameters("dc=ESTSR-PUB-WUS3-AZ1-TEST1&slice=TestSlice") //Feature in test slice
96+
.WithSendX5C(true)
97+
.ExecuteAsync();
98+
```
99+
100+
## Tests to Validate mTLS PoP Tokens
101+
102+
### Certificate Validation Tests
103+
104+
- Verify that `MsalClientException` is thrown when no certificate is provided.
105+
- Ensure that the correct exception message (`MsalErrorMessage.MtlsCertificateNotProvidedMessage`) is returned.
106+
- Ensure that the certificate has a private key when used in the `WithCertificate()` method.
107+
- Ensure X5C is sent along with the certificate.
108+
109+
### Authority Tests
110+
111+
- Test with a valid tenanted authority URL (e.g., `https://login.microsoftonline.com/tenant_id`).
112+
- Ensure an exception (`MsalError.MissingTenantedAuthority`) is thrown for `/common` or `/organizations` authority usage.
113+
- Flow is applicable only to AAD and DSTS authorities. Verify that unsupported authority types (e.g., B2C) throw `MsalError.InvalidAuthorityType`.
114+
115+
### Region Validation Tests
116+
117+
- Ensure `MsalClientException` is thrown when no region is set and `WithMtlsProofOfPossession()` is called.
118+
- Validate successful token acquisition with a specified region.
119+
- Test auto-detected region functionality and confirm the expected region is used.
120+
- Region is not required if the authority is DSTS.
121+
122+
### Grant Type Validation
123+
124+
- Ensure the grant type is `ClientCredentials`.
125+
- Do not include `client_assertion` or `client_assertion_type` parameters in the request.
126+
127+
### Token Acquisition Tests
128+
129+
- Ensure tokens are bound to the specified certificate and the token type is `mtls_pop`.
130+
- Test caching behavior: validate that a token is retrieved from the cache on subsequent requests.
131+
132+
### Integration Tests
133+
134+
- Get token from ESTS using an mTLS certificate.
135+
- Simulate calls to the resource server using mTLS and verify successful authentication. *(No resource support yet.)*
136+
- Test telemetry data: validate that both client-side and server-side metrics are captured.
137+
138+
**Integration test should include:**
139+
140+
- User sets authority to `login.microsoftonline.com/tid` and `validateAuthority=true`.
141+
- Specifies region `X`.
142+
- Uses mTLS authentication.
143+
144+
Expected behavior:
145+
146+
1. MSAL validates the original authority.
147+
2. MSAL calls the token endpoint on `mtlsauth.X.login.microsoft.com/tid/`.
148+
149+
## Note for Developers
150+
151+
When implementing this feature, ensure both client-side and server-side telemetry are captured for the new token type (`mtls_pop`). Telemetry should include:
152+
153+
- Token acquisition success and failure metrics.
154+
- Certificate usage in the Client Credentials flow.
155+
- Regional endpoint usage.
156+
157+
This telemetry will aid in diagnosing issues and optimizing performance.
158+
159+
## Task List
160+
161+
### [EPIC 3127989](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3127989) - Public Preview - SDK support for MTLS-POP tokens for SN/I certificates
162+
163+
<details>
164+
<summary>Features</summary>
165+
166+
- **[3127991](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3127991)** Public Preview - SDK support for MTLS-POP tokens for SN/I certificates (MSAL .NET)
167+
168+
<details>
169+
<summary>Product Backlog</summary>
170+
171+
- **[3128002](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128002)** Add support for MTLS-POP tokens for SN/I certificates
172+
- **[3128009](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128009)** Add Unit tests for MTLS-POP tokens for SN/I Certificates
173+
- **[3128017](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128017)** Add client-side telemetry for MTLS-POP tokens for SN/I Certificates
174+
- **[3128015](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128015)** Add Integration tests for MTLS-POP tokens for SN/I Certificates
175+
176+
</details>
177+
178+
- **[3127992](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3127992)** Public Preview - SDK support for MTLS-POP tokens for SN/I certificates (MSAL JAVA)
179+
180+
<details>
181+
<summary>Product Backlog</summary>
182+
183+
- **[3128048](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128048)** Add support for MTLS-POP tokens for SN/I certificates
184+
- **[3128052](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128052)** Add Unit tests for MTLS-POP tokens for SN/I Certificates
185+
- **[3128055](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128055)** Add client-side telemetry for MTLS-POP tokens for SN/I Certificates
186+
- **[3128054](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128054)** Add Integration tests for MTLS-POP tokens for SN/I Certificates
187+
188+
</details>
189+
190+
- **[3127993](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3127993)** Public Preview - SDK support for MTLS-POP tokens for SN/I certificates (MSAL NODE)
191+
192+
<details>
193+
<summary>Product Backlog</summary>
194+
195+
- **[3128059](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128059)** Add support for MTLS-POP tokens for SN/I certificates
196+
- **[3128060](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128060)** Add Unit tests for MTLS-POP tokens for SN/I Certificates
197+
- **[3128057](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128057)** Add client-side telemetry for MTLS-POP tokens for SN/I Certificates
198+
- **[3128058](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128058)** Add Integration tests for MTLS-POP tokens for SN/I Certificates
199+
200+
</details>
201+
202+
- **[3127994](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3127994)** Public Preview - SDK support for MTLS-POP tokens for SN/I certificates (MSAL PYTHON)
203+
204+
<details>
205+
<summary>Product Backlog</summary>
206+
207+
- **[3128065](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128065)** Add support for MTLS-POP tokens for SN/I certificates
208+
- **[3128066](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128066)** Add Unit tests for MTLS-POP tokens for SN/I Certificates
209+
- **[3128061](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128061)** Add client-side telemetry for MTLS-POP tokens for SN/I Certificates
210+
- **[3128064](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128064)** Add Integration tests for MTLS-POP tokens for SN/I Certificates
211+
212+
</details>
213+
214+
- **[3128075](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3128075)** Public Preview - SDK support for MTLS-POP tokens for SN/I certificates in DSTS (MSAL .NET)
215+
216+
</details>
217+
218+
## Appendix: References
219+
220+
- **[RFC 8705: Mutual TLS](https://tools.ietf.org/html/rfc8705)**
221+
- **[MTLS API specifications / MISE Doc](https://identitydivision.visualstudio.com/DevEx/_git/MiseDocumentation?path=/articles/using-mise/how-to-use-mtls-pop.md&version=GBmain)**
222+
- **MSAL .NET Integration tests** *(Uses LabAuth Certificate)*

media/mtls_pop.png

64.5 KB
Loading

0 commit comments

Comments
 (0)