Skip to content

config: prove the secure profile end to end, fix its operation limits and the dev certificates - #814

Open
bburda wants to merge 9 commits into
feat/tls-floor-mtlsfrom
feat/secure-profile
Open

bburda wants to merge 9 commits into
feat/tls-floor-mtlsfrom
feat/secure-profile

Conversation

@bburda

@bburda bburda commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Pull Request

Summary

  • A new test starts the gateway from the installed gateway_params.secure.yaml, with the secrets only in MEDKIT_JWT_SECRET and MEDKIT_CLIENTS and a generated certificate. It checks each control the profile turns on:

    • TLS 1.3 only;
    • a token on every route except /api/v1/auth/*;
    • roles, refresh and revoke;
    • no secret served as a parameter;
    • no runtime change of auth or TLS keys;
    • rate limits, CORS and no OpenAPI document;
    • mutual TLS when the commented switch is turned on.

    The test also pins the security values of the file, so a weaker file fails it.

  • The image smoke script runs the image with the profile as its params layer.

  • rate_limiting.endpoint_limits: * matches one path segment, so /api/v1/*/operations/* matched no route. The profile now limits the operation routes (start and control) to 30 requests per minute per client. The examples in the docs now match a real route.

  • The profile's comments name MEDKIT_JWT_SECRET and MEDKIT_CLIENTS. The profile lists auth.public_routes (empty), with a health example for a probe.

  • docs/tutorials/docker.rst shows how to run the image with the profile.

  • scripts/generate_dev_certs.sh is now executable. It also writes a client certificate (client.pem, client-key.pem) for mutual TLS. The docs list the files it really writes (ca.pem, cert.pem, key.pem); before, they named files it never wrote.

Breaking changes:

  • With the secure profile, operation calls are limited to 30 per minute per client. Before, the limit in the file matched no route.

Issue


Type

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

Testing

src/ros2_medkit_gateway/scripts/generate_dev_certs.sh ./certs
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 \
  --params-file $(ros2 pkg prefix ros2_medkit_gateway)/share/ros2_medkit_gateway/config/gateway_params.secure.yaml \
  -p server.tls.cert_file:=$PWD/certs/cert.pem -p server.tls.key_file:=$PWD/certs/key.pem

In a second shell:

U=https://localhost:8443/api/v1; C="--cacert certs/ca.pem"
curl -s -o /dev/null -w '%{http_code}\n' $C $U/areas                       # 401
T=$(curl -s $C -u me:change-me-please -d grant_type=client_credentials $U/auth/authorize | jq -r .access_token)
curl -s -o /dev/null -w '%{http_code}\n' $C -H "Authorization: Bearer $T" $U/areas   # 200
ros2 param get /ros2_medkit_gateway auth.jwt_secret                         # <from MEDKIT_JWT_SECRET>

The image: docker build -t medkit-test . && scripts/smoke_image_auth_posture.sh medkit-test.


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 23, 2026 15:29
# (PUT, DELETE .../executions/{id}). "*" is one segment, so an operation
# id containing "/" is held only by the per-client limit.
endpoint_limits: ["/api/v1/*/*/operations/*:30", "/api/v1/*/*/operations/*/executions:30",
"/api/v1/*/*/operations/*/executions/*:30"]

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.

The limiter does not look at the method, so this entry also meters GET .../executions/{id}, the status poll, in the same bucket as PUT and DELETE. A client polling an async execution at 1 Hz empties the 30/min bucket in about a minute, and its cancel can then get 429. Drop this entry until the limiter can match on method, or raise it so polling fits, and add a test that a cancel still passes after polling.

client_requests_per_minute: 120
# Tighten mutating endpoints (operations / data writes).
endpoint_limits: ["/api/v1/*/operations/*:30"]
# Operation calls: start (.../operations/{op}, .../executions) and control

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.

No route starts an operation at .../operations/{op}. The only handler there is GET operation detail, so /api/v1/*/*/operations/*:30 limits a read. Drop that entry, or keep it and say here and in hardening.rst that it limits detail reads.

``locking`` on operations none lock required for component and app operations
================================ ============== ===========================================

``rate_limiting`` is 600 requests per minute for the gateway, 120 per client and 30 per

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.

Each endpoint pattern has its own bucket (client_ip + "|" + matched_pattern), and those calls use it instead of the 120/min client bucket. So a client gets 30/min per pattern, not 30 across operation calls. Please say "30 per client per pattern, outside the 120" here, and fix the "start" label of the first pattern as in the yaml.

# One request per pattern, built from the real route template: method and path.
OPERATION_REQUESTS = {
'/api/v1/*/*/operations/*':
('POST', f'{API_BASE_PATH}/apps/app1/operations/calibrate'),

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.

There is no POST route at .../operations/{op}, so this case passes on 404/405 answers followed by 429. Use GET here, the only method on that path, and assert the expected status before the 429, not only "not 401/403".

AREAS = f'{API_BASE_PATH}/areas'
HEALTH = f'{API_BASE_PATH}/health'
VERSION_INFO = f'{API_BASE_PATH}/version-info'
WRITE_ROUTE = f'{API_BASE_PATH}/components/test/operations/calibrate'

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.

WRITE_ROUTE is a POST to .../operations/calibrate, which has no handler. The viewer gets 403 from deny-by-default on an unknown key and the admin passes on 404 through POST:/api/v1/**. Point it at .../operations/calibrate/executions so the test checks the operator requirement of a real write route.

Comment thread docs/tutorials/docker.rst
docker cp gateway_params.secure.yaml medkit:/etc/ros2_medkit/params.yaml
tar --owner="$(docker run --rm --entrypoint id "$IMAGE" -u)" \
--group="$(docker run --rm --entrypoint id "$IMAGE" -g)" \
-cf - certs | docker cp - medkit:/etc/ros2_medkit

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_key.pem and client-key.pem into the same certs/, and this tar ships all of it into the container, owned by medkit. If mTLS trusts that CA, its key can mint accepted client certificates. Tar only cert.pem and key.pem here and at hardening.rst:51, plus ca.pem when mTLS is on.

cls.gw.__exit__(None, None, None)
raise AssertionError(f'secure gateway did not start: {output}')
cls.port = cls.gw.port
cls.admin = _login(cls.port, ADMIN)

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.

If a login fails here, tearDownClass does not run and the gateway, started in its own session, keeps running. Register cls.addClassCleanup(cls.gw.__exit__, None, None, None) right after the start and drop the manual cleanup and tearDownClass, so __exit__ runs once.

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