Authentication methods
You can enable either or both authentication methods:JWT
Clients include a bearer token in the
authorization header. MockServer validates the token against a JWKS source.mTLS
Clients present an X.509 certificate. MockServer validates it against a trusted CA chain.
JWT authentication
When JWT authentication is enabled, all control plane requests must include anAuthorization: Bearer <token> header. MockServer validates the JWT signature using keys from the configured JWKS source.
Enable JWT authentication
Configure the JWKS source
Provide a URL, file system path, or classpath location for the JSON Web Key Set used to verify token signatures:
JWT property reference
| Property | Environment variable | Default | Description |
|---|---|---|---|
mockserver.controlPlaneJWTAuthenticationRequired | MOCKSERVER_CONTROL_PLANE_JWT_AUTHENTICATION_REQUIRED | false | Enable JWT authentication |
mockserver.controlPlaneJWTAuthenticationJWKSource | MOCKSERVER_CONTROL_PLANE_JWT_AUTHENTICATION_JWK_SOURCE | null | URL or path to JWKS |
mockserver.controlPlaneJWTAuthenticationExpectedAudience | MOCKSERVER_CONTROL_PLANE_JWT_AUTHENTICATION_EXPECTED_AUDIENCE | null | Required aud claim value |
mockserver.controlPlaneJWTAuthenticationMatchingClaims | MOCKSERVER_CONTROL_PLANE_JWT_AUTHENTICATION_MATCHING_CLAIMS | null | Required claims as key=value pairs |
mockserver.controlPlaneJWTAuthenticationRequiredClaims | MOCKSERVER_CONTROL_PLANE_JWT_AUTHENTICATION_REQUIRED_CLAIMS | null | Claims that must be present (any value) |
mTLS authentication
When mTLS authentication is enabled, all control plane requests must arrive over a mutual TLS connection. MockServer validates the client’s X.509 certificate against the configured CA chain.Enable mTLS authentication
Configure the trusted CA chain
Provide the CA certificate (or chain) that signed the client certificates you want to allow:
Configure client credentials for MockServerClient
If you use The private key and certificate must be a valid pair, and the certificate must be signed by one of the CAs in
MockServerClient to manage expectations programmatically, provide the client private key and certificate it should present:controlPlaneTLSMutualAuthenticationCAChain.mTLS property reference
| Property | Environment variable | Default | Description |
|---|---|---|---|
mockserver.controlPlaneTLSMutualAuthenticationRequired | MOCKSERVER_CONTROL_PLANE_TLS_MUTUAL_AUTHENTICATION_REQUIRED | false | Enable mTLS for control plane |
mockserver.controlPlaneTLSMutualAuthenticationCAChain | MOCKSERVER_CONTROL_PLANE_TLS_MUTUAL_AUTHENTICATION_CERTIFICATE_CHAIN | null | CA chain to validate client certificates |
mockserver.controlPlanePrivateKeyPath | MOCKSERVER_CONTROL_PLANE_TLS_PRIVATE_KEY_PATH | null | Client private key for MockServerClient |
mockserver.controlPlaneX509CertificatePath | MOCKSERVER_CONTROL_PLANE_TLS_X509_CERTIFICATE_PATH | null | Client certificate for MockServerClient |
Other security options
In addition to control plane authentication, consider these measures for production environments:- Restrict network access — run MockServer on
localhostor a private network so it is not reachable from outside your test infrastructure. - Short-lived instances — start MockServer just before your tests and stop it immediately after to minimize the window of exposure.
- Restrict CORS — keep
enableCORSForAPIandenableCORSForAllResponsesdisabled unless your use case requires cross-origin requests. - Restrict templates — limit what JavaScript, Velocity, or Mustache templates can do using the template restriction configuration properties.
- All-connections mTLS — use
tlsMutualAuthenticationRequiredto require client certificates on all TLS connections, not just control plane requests. See TLS / HTTPS for details.