Tested end-to-end on Azure

True mTLS validation at APIM, behind an App Gateway in passthrough

A caller presents a client certificate → Azure Application Gateway (WAF_v2, passthrough) forwards it → API Management performs the real certificate validation. The gateway never validates the cert — APIM does. Here is each link, proven with real command output.

Region eastus2 App Gateway WAF_v2 passthrough APIM v1, internal VNet Generated 2026-07-08 03:40 UTC
16/16
scenarios passed

● The core question — true mTLS validation at APIM

Does App Gateway forward the client certificate to APIM, and does APIM validate it against Key Vault?

Yes. APIM reconstructs the forwarded certificate and validates it under the selected model before authorizing per client - a pinned-thumbprint allow list, or a real cryptographic chain-of-trust signature check. A certificate from an untrusted issuer is rejected even though the gateway forwarded it unvalidated: APIM is the trust anchor, and Key Vault holds the trust material.

Two validation models · both fully supported

There are two legitimate ways to decide whether a forwarded certificate is trustworthy, and this scenario ships both. Choose one with the certValidationMode parameter (pinned or chain). Neither is universally “correct” — they trade explicit control against operational overhead. Both were run live; see the evidence below.

🔑 Model A · Pinned thumbprint

Accept only certificates on a Key Vault allow list.

Trust test
SHA-1 thumbprint is on the allow list (and issuer matches the Root CA).
New client
Add its thumbprint to Key Vault first.
Strength
Most restrictive; an over-permissive CA can’t widen access.
Cost
Per-certificate maintenance.
Best for
A small, known set of clients.
client3 (CA-signed, not listed) → rejected · spoofed → rejected (not on list)

🔗 Model B · Chain of trust

Accept anything the Root CA cryptographically signed.

Trust test
Root CA public key verifies the certificate’s RSA signature (real VerifyData).
New client
Works automatically once your CA issues it.
Strength
No allow list to maintain; trust the CA, not each cert.
Cost
You must fully trust (and protect) the CA.
Best for
A private CA issuing many / rotating client certs.
client3 (CA-signed, not listed) → accepted · spoofed → rejected (NOT_CA_SIGNED)

“Isn’t this just a thumbprint or name compare?” — No.

Chain mode performs a genuine RSA signature verification with the Key Vault Root CA’s public key. The spoofed certificate proves it: its issuer Distinguished Name is byte-for-byte identical to the real Root CA (CN=mTLS POC Root CA), yet it is rejected with NOT_CA_SIGNED and chainOk=false — because the Root CA’s key never signed it. A string comparison would have been fooled; RSA.VerifyData is not.

Sandbox note: the APIM policy validator blocks both X509Chain and System.Func (both confirmed at deploy time), so chain mode parses the leaf DER inline to recover the TBSCertificate bytes and signature, then verifies with GetRSAPublicKey().VerifyData(...).

How it works

Architecture — who does what

The gateway forwards the certificate; APIM is the trust anchor and validates it against Key Vault material.

flowchart LR
    Caller(["Caller
presents client cert"]) subgraph AGW["Application Gateway • WAF_v2 • PASSTHROUGH"] direction TB L["HTTPS listener :443
requests client cert,
does NOT validate"] RW["Header rewrite (overwrite)
X-Client-Cert = {var_client_certificate}"] L --> RW end subgraph VNET["Internal virtual network (locked down)"] APIM["API Management
validates cert in policy"] end KV["Key Vault
Root CA + pinned allow-list"] Caller -- "mTLS (client cert)" --> AGW AGW -- "HTTPS + forwarded cert header" --> APIM KV -. "named values (managed identity)" .-> APIM APIM -- "200 ALLOW / 403 DENY" --> Caller

Request sequence — end to end

Trust is decided in APIM against Key Vault, not at the gateway.

sequenceDiagram
    autonumber
    participant C as Caller
    participant AG as App Gateway
    participant A as APIM
    participant KV as Key Vault
    C->>AG: TLS handshake plus client certificate
    Note over AG: Passthrough - requests the cert but does not validate it
    AG->>AG: Rewrite - overwrite X-Client-Cert with the TLS cert
    AG->>A: HTTPS plus X-Client-Cert header, forwarded PEM
    A->>KV: Resolve Root CA and allow-list via named values
    KV-->>A: trusted-root-ca-der-b64 and client-cert-allowlist
    A->>A: Parse cert, check validity, issuer vs Root CA, thumbprint vs allow-list
    alt Trusted, allow-listed and authorized
        A-->>C: 200 ALLOW
    else Untrusted or not allow-listed or wrong path
        A-->>C: 403 DENY
    end

Every scenario · expected vs. actual

BOTH
Configuration proofs
These hold regardless of the chosen model.
1
App Gateway forwards the client certificate to APIM
PASS
Expected
Rewrite rule SETS X-Client-Cert = {var_client_certificate}
Observed
X-Client-Cert={var_client_certificate}; X-Client-Cert-Verify={var_client_certificate_verification} (8 headers overwritten)
APIM decision
CONFIG
gateway-forwards-cert
az network application-gateway rewrite-rule list --rule-set-name forward-client-cert
Proves: Application Gateway in passthrough mode forwards the TLS client certificate to APIM as an overwrite-only header.
</> Backed by bicep/modules/app-gateway.bicep
// App Gateway forwards the TLS client cert to APIM. Every header is SET
// (overwrite) from a mutual-auth server variable, so a client can never
// inject its own X-Client-Cert value.
rewriteRuleSets: [
  {
    name: 'forward-client-cert'
    properties: {
      rewriteRules: [
        {
          name: 'set-client-cert-headers'
          actionSet: {
            requestHeaderConfigurations: [
              { headerName: 'X-Client-Cert'        headerValue: '{var_client_certificate}' }
              { headerName: 'X-Client-Cert-Issuer' headerValue: '{var_client_certificate_issuer}' }
              { headerName: 'X-Client-Cert-Verify' headerValue: '{var_client_certificate_verification}' }
              // + subject / fingerprint / serial / start / end
            ]
          }
        }
      ]
    }
  }
]
2
Key Vault holds the trust material; APIM references it
PASS
Expected
KV secrets trusted-root-ca-der-b64 + client-cert-allowlist, referenced by APIM named values
Observed
Both secrets present; APIM named values bound to the vault secret identifiers; cert-validation-mode selects the model
APIM decision
CONFIG
kv-holds-trust-material
az keyvault secret list + APIM namedValues keyVault.secretIdentifier
Proves: The Root CA and per-client allow list live in Key Vault and are surfaced to the APIM policy via named values (managed identity).
</> Backed by bicep/modules/apim-config.bicep
// The Root CA and the pinned allow-list live in Key Vault and are surfaced
// to the APIM policy as named values via the service's managed identity.
resource nvRoot 'Microsoft.ApiManagement/service/namedValues@2023-05-01-preview' = {
  parent: apim
  name: 'trusted-root-ca-der-b64'
  properties: {
    secret: true
    keyVault: { secretIdentifier: rootSecretIdentifier }   // -> KV secret
  }
}
resource nvAllow 'Microsoft.ApiManagement/service/namedValues@2023-05-01-preview' = {
  parent: apim
  name: 'client-cert-allowlist'
  properties: {
    secret: true
    keyVault: { secretIdentifier: allowlistSecretIdentifier }
  }
}
PINNED
Model A · Pinned thumbprint allow list
Trust = the certificate’s thumbprint is on the Key Vault allow list.
3
Allow-listed client1 -> 200
PASS
Expected
200 ALLOW
Observed
HTTP 200 decision=ALLOW chainOk=True pinnedMatch=True
HTTP status
200
APIM decision
ALLOW
chainOk (RSA signature verified)
True
pinnedMatch (on allow list)
True
Authenticated client
client1
pinned-client1
[PINNED] GET /poc/whoami with X-Client-Cert = <client1 PEM>
Proves: PINNED accepts client1: its thumbprint is on the Key Vault allow list and its issuer matches the Key Vault Root CA.
</> Backed by apim/api-policy.xml
// Rebuild the forwarded cert, then decide trust under the active model.
string pem  = System.Uri.UnescapeDataString(fwdCertHeader);   // X-Client-Cert
var cert    = new X509Certificate2(Convert.FromBase64String(pemBody));
var root    = new X509Certificate2(Convert.FromBase64String("{{trusted-root-ca-der-b64}}"));

// MODEL A (pinned): thumbprint must be on the KV allow-list AND issuer match.
bool issuerDnMatch = string.Equals(cert.Issuer, root.Subject,
                                   StringComparison.OrdinalIgnoreCase);
bool pinnedMatch = false;
foreach (var e in "{{client-cert-allowlist}}".Split('|')) {
    var kv = e.Split(':');                       // "client1:THUMBPRINT"
    if (kv.Length == 2 &&
        string.Equals(kv[1].Trim(), cert.Thumbprint, StringComparison.OrdinalIgnoreCase))
        pinnedMatch = true;
}
bool pinnedOk = timeOk && issuerDnMatch && pinnedMatch;   // -> 200 when true
4
Allow-listed client2 -> 200
PASS
Expected
200 ALLOW
Observed
HTTP 200 decision=ALLOW chainOk=True pinnedMatch=True
HTTP status
200
APIM decision
ALLOW
chainOk (RSA signature verified)
True
pinnedMatch (on allow list)
True
Authenticated client
client2
pinned-client2
[PINNED] GET /poc/whoami with X-Client-Cert = <client2 PEM>
Proves: PINNED accepts client2 for the same reason: a second allow-listed thumbprint.
</> Backed by apim/api-policy.xml
// Rebuild the forwarded cert, then decide trust under the active model.
string pem  = System.Uri.UnescapeDataString(fwdCertHeader);   // X-Client-Cert
var cert    = new X509Certificate2(Convert.FromBase64String(pemBody));
var root    = new X509Certificate2(Convert.FromBase64String("{{trusted-root-ca-der-b64}}"));

// MODEL A (pinned): thumbprint must be on the KV allow-list AND issuer match.
bool issuerDnMatch = string.Equals(cert.Issuer, root.Subject,
                                   StringComparison.OrdinalIgnoreCase);
bool pinnedMatch = false;
foreach (var e in "{{client-cert-allowlist}}".Split('|')) {
    var kv = e.Split(':');                       // "client1:THUMBPRINT"
    if (kv.Length == 2 &&
        string.Equals(kv[1].Trim(), cert.Thumbprint, StringComparison.OrdinalIgnoreCase))
        pinnedMatch = true;
}
bool pinnedOk = timeOk && issuerDnMatch && pinnedMatch;   // -> 200 when true
5
CA-signed but NOT allow-listed client3 -> 403
PASS
Expected
403 DENY NOT_IN_ALLOWLIST
Observed
HTTP 403 decision=DENY reason=NOT_IN_ALLOWLIST chainOk=True pinnedMatch=False
HTTP status
403
APIM decision
DENY
Reason
NOT_IN_ALLOWLIST
chainOk (RSA signature verified)
True
pinnedMatch (on allow list)
False
pinned-client3
[PINNED] GET /poc/whoami with X-Client-Cert = <client3 PEM>
Proves: PINNED rejects client3 even though it is validly signed by the Root CA (chainOk=true): it is not on the allow list. This is the restrictive edge of the pinned model.
</> Backed by apim/api-policy.xml
// Rebuild the forwarded cert, then decide trust under the active model.
string pem  = System.Uri.UnescapeDataString(fwdCertHeader);   // X-Client-Cert
var cert    = new X509Certificate2(Convert.FromBase64String(pemBody));
var root    = new X509Certificate2(Convert.FromBase64String("{{trusted-root-ca-der-b64}}"));

// MODEL A (pinned): thumbprint must be on the KV allow-list AND issuer match.
bool issuerDnMatch = string.Equals(cert.Issuer, root.Subject,
                                   StringComparison.OrdinalIgnoreCase);
bool pinnedMatch = false;
foreach (var e in "{{client-cert-allowlist}}".Split('|')) {
    var kv = e.Split(':');                       // "client1:THUMBPRINT"
    if (kv.Length == 2 &&
        string.Equals(kv[1].Trim(), cert.Thumbprint, StringComparison.OrdinalIgnoreCase))
        pinnedMatch = true;
}
bool pinnedOk = timeOk && issuerDnMatch && pinnedMatch;   // -> 200 when true
6
Forged-signature cert (same issuer DN) -> 403
PASS
Expected
403 DENY NOT_IN_ALLOWLIST
Observed
HTTP 403 decision=DENY reason=NOT_IN_ALLOWLIST chainOk=False pinnedMatch=False
HTTP status
403
APIM decision
DENY
Reason
NOT_IN_ALLOWLIST
chainOk (RSA signature verified)
False
pinnedMatch (on allow list)
False
pinned-spoofed
[PINNED] GET /poc/whoami with X-Client-Cert = <spoofed PEM>
Proves: PINNED rejects the spoofed cert: its thumbprint is not on the allow list (a thumbprint is a hash of the whole certificate and cannot be forged).
</> Backed by apim/api-policy.xml
// Rebuild the forwarded cert, then decide trust under the active model.
string pem  = System.Uri.UnescapeDataString(fwdCertHeader);   // X-Client-Cert
var cert    = new X509Certificate2(Convert.FromBase64String(pemBody));
var root    = new X509Certificate2(Convert.FromBase64String("{{trusted-root-ca-der-b64}}"));

// MODEL A (pinned): thumbprint must be on the KV allow-list AND issuer match.
bool issuerDnMatch = string.Equals(cert.Issuer, root.Subject,
                                   StringComparison.OrdinalIgnoreCase);
bool pinnedMatch = false;
foreach (var e in "{{client-cert-allowlist}}".Split('|')) {
    var kv = e.Split(':');                       // "client1:THUMBPRINT"
    if (kv.Length == 2 &&
        string.Equals(kv[1].Trim(), cert.Thumbprint, StringComparison.OrdinalIgnoreCase))
        pinnedMatch = true;
}
bool pinnedOk = timeOk && issuerDnMatch && pinnedMatch;   // -> 200 when true
7
Untrusted issuer -> 403
PASS
Expected
403 DENY UNTRUSTED_ISSUER
Observed
HTTP 403 decision=DENY reason=UNTRUSTED_ISSUER chainOk=False pinnedMatch=False
HTTP status
403
APIM decision
DENY
Reason
UNTRUSTED_ISSUER
chainOk (RSA signature verified)
False
pinnedMatch (on allow list)
False
pinned-rogue
[PINNED] GET /poc/whoami with X-Client-Cert = <rogue PEM>
Proves: PINNED rejects the rogue cert: its issuer does not match the Key Vault Root CA.
</> Backed by apim/api-policy.xml
// Untrusted issuer -> rejected. The gateway forwarded the cert unvalidated;
// APIM is the trust anchor. In pinned mode the issuer DN must match the KV
// Root CA; in chain mode the Root CA key must have signed the cert.
r["reason"] = ok ? (mode == "chain" ? "CHAIN_OK" : "PINNED_OK")
                 : (mode == "chain"
                     ? "NOT_CA_SIGNED"                 // signature check failed
                     : (!issuerDnMatch ? "UNTRUSTED_ISSUER"
                                       : "NOT_IN_ALLOWLIST"));   // -> 403
8
No certificate -> 403
PASS
Expected
403 DENY NO_CERT_FORWARDED
Observed
HTTP 403 decision=DENY reason=NO_CERT_FORWARDED chainOk=False pinnedMatch=False
HTTP status
403
APIM decision
DENY
Reason
NO_CERT_FORWARDED
chainOk (RSA signature verified)
False
pinnedMatch (on allow list)
False
pinned-nocert
[PINNED] GET /poc/whoami with X-Client-Cert = (none)
Proves: PINNED rejects a request with no forwarded certificate.
</> Backed by apim/api-policy.xml
// No certificate forwarded -> rejected before any trust check.
if (cert == null) {
    r["ok"] = false;
    r["reason"] = "NO_CERT_FORWARDED";
    return r.ToString();   // -> 403 DENY
}
9
client1 -> its own path A -> 200
PASS
Expected
200 ALLOW
Observed
HTTP 200 decision=ALLOW chainOk=True
HTTP status
200
APIM decision
ALLOW
chainOk (RSA signature verified)
True
Authenticated client
client1
pinned-authz-own
[PINNED] GET /poc/client1 with X-Client-Cert = <client1 PEM>
Proves: Per-client authorization: client1 is authorised for path A.
</> Backed by apim/operation-client1-policy.xml
// Per-client authorization: only the client that owns cert1 may use path A.
// (client2 has the mirror policy for path B.)
<choose>
  <when condition='@((string)((JObject)context.Variables["auth"])["client"] != "client1")'>
    <return-response>
      <set-status code="403" reason="Not authorised for this resource" />
    </return-response>
  </when>
</choose>
10
client1 -> client2 path B -> 403
PASS
Expected
403 DENY_AUTHZ
Observed
HTTP 403 decision=DENY_AUTHZ reason=Authenticated client is not authorised for path B (client2)
HTTP status
403
APIM decision
DENY_AUTHZ
Reason
Authenticated client is not authorised for path B (client2)
pinned-authz-cross
[PINNED] GET /poc/client2 with X-Client-Cert = <client1 PEM>
Proves: Per-client authorization: an authenticated client is still confined to its own path; identity from the certificate drives authorization.
</> Backed by apim/operation-client1-policy.xml
// Per-client authorization: only the client that owns cert1 may use path A.
// (client2 has the mirror policy for path B.)
<choose>
  <when condition='@((string)((JObject)context.Variables["auth"])["client"] != "client1")'>
    <return-response>
      <set-status code="403" reason="Not authorised for this resource" />
    </return-response>
  </when>
</choose>
CHAIN
Model B · Chain of trust (Root CA signature)
Trust = the Key Vault Root CA cryptographically signed the certificate.
11
CA-signed client1 -> 200
PASS
Expected
200 ALLOW
Observed
HTTP 200 decision=ALLOW chainOk=True pinnedMatch=True
HTTP status
200
APIM decision
ALLOW
chainOk (RSA signature verified)
True
pinnedMatch (on allow list)
True
Authenticated client
client1
chain-client1
[CHAIN] GET /poc/whoami with X-Client-Cert = <client1 PEM>
Proves: CHAIN accepts client1: the Key Vault Root CA public key verifies the RSA signature over its TBSCertificate.
</> Backed by apim/api-policy.xml
// MODEL B (chain): a REAL RSA signature check - not a name compare.
// The sandbox blocks X509Chain and System.Func, so the leaf DER is parsed
// inline to pull out the TBSCertificate bytes and the signature, then the
// Key-Vault Root CA public key must verify that signature.
byte[] der = cert.RawData;
byte[] tbs = /* inline DER walk: SEQUENCE -> tbsCertificate bytes */;
byte[] sig = /* inline DER walk: signatureValue BIT STRING          */;

var rsa = root.GetRSAPublicKey();
bool chainOk = rsa.VerifyData(tbs, sig,
                 HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);

bool chainModeOk = timeOk && chainOk;   // accepts ANY cert the Root CA signed
// A cert that merely copies the Root CA's issuer NAME but is signed by another
// key fails here (chainOk=false) -> 403 NOT_CA_SIGNED. Cryptography, not string.
12
CA-signed client2 -> 200
PASS
Expected
200 ALLOW
Observed
HTTP 200 decision=ALLOW chainOk=True pinnedMatch=True
HTTP status
200
APIM decision
ALLOW
chainOk (RSA signature verified)
True
pinnedMatch (on allow list)
True
Authenticated client
client2
chain-client2
[CHAIN] GET /poc/whoami with X-Client-Cert = <client2 PEM>
Proves: CHAIN accepts client2: also validly signed by the Root CA.
</> Backed by apim/api-policy.xml
// MODEL B (chain): a REAL RSA signature check - not a name compare.
// The sandbox blocks X509Chain and System.Func, so the leaf DER is parsed
// inline to pull out the TBSCertificate bytes and the signature, then the
// Key-Vault Root CA public key must verify that signature.
byte[] der = cert.RawData;
byte[] tbs = /* inline DER walk: SEQUENCE -> tbsCertificate bytes */;
byte[] sig = /* inline DER walk: signatureValue BIT STRING          */;

var rsa = root.GetRSAPublicKey();
bool chainOk = rsa.VerifyData(tbs, sig,
                 HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);

bool chainModeOk = timeOk && chainOk;   // accepts ANY cert the Root CA signed
// A cert that merely copies the Root CA's issuer NAME but is signed by another
// key fails here (chainOk=false) -> 403 NOT_CA_SIGNED. Cryptography, not string.
13
CA-signed client3 (no allow list needed) -> 200
PASS
Expected
200 ALLOW
Observed
HTTP 200 decision=ALLOW chainOk=True pinnedMatch=False
HTTP status
200
APIM decision
ALLOW
chainOk (RSA signature verified)
True
pinnedMatch (on allow list)
False
Authenticated client
client3
chain-client3
[CHAIN] GET /poc/whoami with X-Client-Cert = <client3 PEM>
Proves: CHAIN accepts client3 with NO allow-list entry -- the exact certificate PINNED rejected. This is the money shot: the two models genuinely differ.
</> Backed by apim/api-policy.xml
// MODEL B (chain): a REAL RSA signature check - not a name compare.
// The sandbox blocks X509Chain and System.Func, so the leaf DER is parsed
// inline to pull out the TBSCertificate bytes and the signature, then the
// Key-Vault Root CA public key must verify that signature.
byte[] der = cert.RawData;
byte[] tbs = /* inline DER walk: SEQUENCE -> tbsCertificate bytes */;
byte[] sig = /* inline DER walk: signatureValue BIT STRING          */;

var rsa = root.GetRSAPublicKey();
bool chainOk = rsa.VerifyData(tbs, sig,
                 HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);

bool chainModeOk = timeOk && chainOk;   // accepts ANY cert the Root CA signed
// A cert that merely copies the Root CA's issuer NAME but is signed by another
// key fails here (chainOk=false) -> 403 NOT_CA_SIGNED. Cryptography, not string.
14
Forged signature, identical issuer DN -> 403
PASS
Expected
403 DENY NOT_CA_SIGNED
Observed
HTTP 403 decision=DENY reason=NOT_CA_SIGNED chainOk=False pinnedMatch=False
HTTP status
403
APIM decision
DENY
Reason
NOT_CA_SIGNED
chainOk (RSA signature verified)
False
pinnedMatch (on allow list)
False
chain-spoofed
[CHAIN] GET /poc/whoami with X-Client-Cert = <spoofed PEM>
Proves: CHAIN rejects the spoofed cert even though its issuer string is byte-for-byte identical to the real Root CA. The RSA signature check fails (chainOk=false) -- proof this is real cryptography, not a name compare.
</> Backed by apim/api-policy.xml
// MODEL B (chain): a REAL RSA signature check - not a name compare.
// The sandbox blocks X509Chain and System.Func, so the leaf DER is parsed
// inline to pull out the TBSCertificate bytes and the signature, then the
// Key-Vault Root CA public key must verify that signature.
byte[] der = cert.RawData;
byte[] tbs = /* inline DER walk: SEQUENCE -> tbsCertificate bytes */;
byte[] sig = /* inline DER walk: signatureValue BIT STRING          */;

var rsa = root.GetRSAPublicKey();
bool chainOk = rsa.VerifyData(tbs, sig,
                 HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);

bool chainModeOk = timeOk && chainOk;   // accepts ANY cert the Root CA signed
// A cert that merely copies the Root CA's issuer NAME but is signed by another
// key fails here (chainOk=false) -> 403 NOT_CA_SIGNED. Cryptography, not string.
15
Untrusted issuer -> 403
PASS
Expected
403 DENY NOT_CA_SIGNED
Observed
HTTP 403 decision=DENY reason=NOT_CA_SIGNED chainOk=False pinnedMatch=False
HTTP status
403
APIM decision
DENY
Reason
NOT_CA_SIGNED
chainOk (RSA signature verified)
False
pinnedMatch (on allow list)
False
chain-rogue
[CHAIN] GET /poc/whoami with X-Client-Cert = <rogue PEM>
Proves: CHAIN rejects the rogue cert: the Root CA did not sign it.
</> Backed by apim/api-policy.xml
// MODEL B (chain): a REAL RSA signature check - not a name compare.
// The sandbox blocks X509Chain and System.Func, so the leaf DER is parsed
// inline to pull out the TBSCertificate bytes and the signature, then the
// Key-Vault Root CA public key must verify that signature.
byte[] der = cert.RawData;
byte[] tbs = /* inline DER walk: SEQUENCE -> tbsCertificate bytes */;
byte[] sig = /* inline DER walk: signatureValue BIT STRING          */;

var rsa = root.GetRSAPublicKey();
bool chainOk = rsa.VerifyData(tbs, sig,
                 HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);

bool chainModeOk = timeOk && chainOk;   // accepts ANY cert the Root CA signed
// A cert that merely copies the Root CA's issuer NAME but is signed by another
// key fails here (chainOk=false) -> 403 NOT_CA_SIGNED. Cryptography, not string.
16
No certificate -> 403
PASS
Expected
403 DENY NO_CERT_FORWARDED
Observed
HTTP 403 decision=DENY reason=NO_CERT_FORWARDED chainOk=False pinnedMatch=False
HTTP status
403
APIM decision
DENY
Reason
NO_CERT_FORWARDED
chainOk (RSA signature verified)
False
pinnedMatch (on allow list)
False
chain-nocert
[CHAIN] GET /poc/whoami with X-Client-Cert = (none)
Proves: CHAIN rejects a request with no forwarded certificate.
</> Backed by apim/api-policy.xml
// No certificate forwarded -> rejected before any trust check.
if (cert == null) {
    r["ok"] = false;
    r["reason"] = "NO_CERT_FORWARDED";
    return r.ToString();   // -> 403 DENY
}

Also verified on API Management v2

● Same policy, same certs, same results — on API Management v2.

The API Management v2 tiers carry a documented limitation: context.Request.Certificate and TLS renegotiation are not supported. That would matter if trust were established at APIM’s own TLS layer — but this scenario never does that. Trust is decided entirely from the forwarded X-Client-Cert header, so the limitation does not apply.

To prove it, the identical dual-model policy, named values, and certificates were deployed to a standalone API Management v2 instance (public gateway) and the same matrix was run directly against its gateway. 11/11 checks passed — behaviour is identical to the v1 deployment, including the real RSA chain-of-trust signature check that rejects the forged-issuer spoofed certificate. The certificate-validation pattern is tier-agnostic: it works the same on API Management v1 and v2.

11/11
v2 checks passed
ModelCheckObserved on API Management v2Result
PINNEDAllow-listed client1 -> 200HTTP 200 decision=ALLOW chainOk=True pinnedMatch=TruePASS
PINNEDCA-signed but NOT allow-listed client3 -> 403HTTP 403 decision=DENY reason=NOT_IN_ALLOWLIST chainOk=True pinnedMatch=FalsePASS
PINNEDForged-signature cert (same issuer DN) -> 403HTTP 403 decision=DENY reason=NOT_IN_ALLOWLIST chainOk=False pinnedMatch=FalsePASS
PINNEDUntrusted issuer -> 403HTTP 403 decision=DENY reason=UNTRUSTED_ISSUER chainOk=False pinnedMatch=FalsePASS
PINNEDNo certificate -> 403HTTP 403 decision=DENY reason=NO_CERT_FORWARDED chainOk=False pinnedMatch=FalsePASS
PINNEDclient1 -> client2 path B -> 403HTTP 403 decision=DENY_AUTHZ reason=Authenticated client is not authorised for path B (client2)PASS
CHAINCA-signed client1 -> 200HTTP 200 decision=ALLOW chainOk=True pinnedMatch=TruePASS
CHAINCA-signed client3 (no allow list needed) -> 200HTTP 200 decision=ALLOW chainOk=True pinnedMatch=FalsePASS
CHAINForged signature, identical issuer DN -> 403HTTP 403 decision=DENY reason=NOT_CA_SIGNED chainOk=False pinnedMatch=FalsePASS
CHAINUntrusted issuer -> 403HTTP 403 decision=DENY reason=NOT_CA_SIGNED chainOk=False pinnedMatch=FalsePASS
CHAINNo certificate -> 403HTTP 403 decision=DENY reason=NO_CERT_FORWARDED chainOk=False pinnedMatch=FalsePASS

API Management v2 run · 2026-07-09 03:01 UTC

How we validated the forwarded certificate in the APIM sandbox

Parse the header, then decide trust in APIM — never at the gateway.

Behind a Layer-7 gateway, APIM's context.Request.Certificate is not the client cert (the gateway opens a separate TLS session to APIM). The client certificate is forwarded as a percent-encoded PEM in X-Client-Cert, set from the gateway's mutual-authentication server variables.

The APIM policy URL-decodes the header, strips the PEM armor, base64-decodes to DER, and builds an X509Certificate2. It then checks the validity window and applies the active model: a Key Vault-sourced thumbprint allow list (pinned) or a real Root CA signature verification (chain).

Sandbox limitations found at deploy time: the APIM policy-expression validator rejects DateTime.ToUniversalTime(), X509Chain, and System.Func. Validity uses DateTime.Now against the certificate’s local NotBefore/NotAfter; chain mode verifies trust by parsing the leaf DER inline (no X509Chain, no lambdas) and calling GetRSAPublicKey().VerifyData(...) with the Key Vault Root CA.

Security verdict

● A strong, defensible pattern

  • Possession — enforced by TLS; a public certificate without its private key is useless.
  • Trust — enforced in APIM under whichever model you pick: a pinned Key Vault allow list, or a real cryptographic chain-of-trust signature check. APIM is the trust anchor either way.
  • Real cryptography, not string matching — chain mode rejects the spoofed certificate (identical issuer name, forged signature) with chainOk=false. Trust is proven by the CA’s key, not by a name.
  • Authorization — per-client path binding in APIM operation policies.
  • Anti-spoofing — the gateway overwrites every X-Client-Cert* header from the real TLS connection, and APIM is reachable only from the gateway (internal VNet), so a forged header can’t be injected or bypass the gateway.

One thing to keep in mind: the gateway itself performs no certificate validation in passthrough, so treat its client_certificate_verification value as informational only — the header overwrite and the internal-VNet lockdown are what make the forwarded certificate trustworthy for APIM to validate.