Skip to content

gateway: enforce the TLS floor, mutual TLS by a switch, warn about secrets over plain HTTP - #813

Open
bburda wants to merge 11 commits into
feat/public-routesfrom
feat/tls-floor-mtls
Open

bburda wants to merge 11 commits into
feat/public-routesfrom
feat/tls-floor-mtls

Conversation

@bburda

@bburda bburda commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Pull Request

Summary

  • server.tls.min_version is now the real protocol floor of the HTTPS server. Before, a value other than 1.2 only logged a warning. The start log states the floor.
  • New server.tls.require_client_cert (default false) turns on mutual TLS. The server then requires a client certificate signed by a CA in server.tls.ca_file. The gateway does not start when the switch is on and ca_file holds no CA certificate, or when TLS is off. With the switch off, ca_file changes nothing for clients, as before. A client certificate does not replace a token.
  • server.tls.* keys are read at start. A runtime ros2 param set on them is refused, as for auth.*.
  • gateway_https.launch.py require_client_cert:=true makes a client certificate signed by its CA and prints a curl command that uses it.
  • When auth.require_auth_for is write or all, server.host is not loopback and TLS is off, the gateway logs a warning at start: client secrets and tokens travel in clear text.

Breaking changes:

  • With min_version: "1.3", a client limited to TLS 1.2 is refused.
  • A runtime set of a server.tls.* parameter is refused. Before, it was accepted and had no effect.

Issue


Type

  • Bug fix
  • New feature or tests
  • Breaking change
  • Documentation only

Testing

ros2 launch ros2_medkit_gateway gateway_https.launch.py \
  require_client_cert:=true min_tls_version:=1.3 cert_dir:=/tmp/medkit-certs

The launch prints the curl command. In a second shell:

D=/tmp/medkit-certs; U=https://127.0.0.1:8443/api/v1/health
C="--cacert $D/ca.pem --cert $D/client.pem --key $D/client-key.pem"
curl -s -o /dev/null -w '%{http_code}\n' $C $U                      # 200
curl -s -o /dev/null -w '%{http_code}\n' --cacert $D/ca.pem $U      # 000, no client certificate
curl -s -o /dev/null -w '%{http_code}\n' $C --tls-max 1.2 $U        # 000, below the floor

The plain-HTTP warning:

export MEDKIT_JWT_SECRET=$(head -c 32 /dev/urandom | base64)
export MEDKIT_CLIENTS="me:change-me-please:admin"
ros2 run ros2_medkit_gateway gateway_node --ros-args -p server.host:=0.0.0.0
# [WARN] ... Authentication is on and the REST API binds 0.0.0.0 without TLS: ...

Checklist

  • Breaking changes are clearly described (and announced in docs / changelog if needed)
  • Tests were added or updated if needed
  • Docs were updated if behavior or public API changed

@bburda
bburda added this pull request to stack #802 November 22, 2026 21:28
"Failed to create SSL server. Check certificate and key files: " + tls_config_.cert_file +
" (key configured: " + (tls_config_.key_file.empty() ? "no" : "yes") + ")");
}
if (tls_config_.require_client_cert) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a client CA, httplib turns on SSL_VERIFY_PEER but nothing sets a session id context, so OpenSSL aborts any resumed handshake with an internal_error alert. curl --cert ... with two URLs gets 200 and then error 35. Call SSL_CTX_set_session_id_context(ctx, ...) with a fixed non-empty id here, check its return, and add TLS 1.2 and 1.3 resume cases to test_tls_floor_mtls.

# ./certs/server.crt - Server certificate
# ./certs/server.key - Server private key (chmod 600)
# ./certs/client.crt - Client certificate (for future mutual TLS)
# ./certs/client.crt - Client certificate (for mutual TLS)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generate_dev_certs.sh writes ca.pem, ca_key.pem, cert.pem and key.pem, so this file list is wrong and client.crt/client.key do not exist. Point the mTLS examples here and in docs/tutorials/https.rst at gateway_https.launch.py cert_dir:=./certs require_client_cert:=true and its ca.pem, client.pem and client-key.pem, or add a clientAuth leaf to the script.

'server.tls.enabled': True,
'server.tls.cert_file': cert_paths['cert_file'],
'server.tls.key_file': cert_paths['key_file'],
'server.tls.ca_file': cert_paths['ca_file'],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mTLS is detected only from the launch arg, but a config_file with require_client_cert: true turns it on too. Then no client cert is made, this line swaps the config's ca_file for the dev CA, and the printed curl -k fails the handshake. Read the flag from config_file as well, like cors_override does, and set ca_file only when mTLS is on.

"""Create client.pem and client-key.pem signed by the CA in cert_dir, unless they exist."""
client_cert = os.path.join(cert_dir, 'client.pem')
client_key = os.path.join(cert_dir, 'client-key.pem')
if os.path.exists(client_cert) and os.path.exists(client_key):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An existing client.pem is reused even when generate_certificates just made a new CA, so the printed curl gets unknown ca. Regenerate the client pair when the CA was recreated, or when openssl verify -CAfile ca.pem client.pem fails.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants