Skip to content

Commit 27d00a0

Browse files
mroestclaude
andauthored
Document the secured environment the agent needs (#4)
* Document the secured environment the agent needs Prior to this change, the agent's deliberate security trade-offs (plain HTTP, static bearer tokens that never expire, no rate limiting) were scattered across the docs. A deployer could miss that the agent is not safe to expose on its own, and that a leaked token is as good as the private key it unlocks. This change collects those decisions in SECURITY.md, together with the environment a deployment must provide to compensate, and points the docs and the shipped configuration at it. The agent stays as lean as intended; the responsibility moves from implied to explicit. The vulnerability-reporting section is a placeholder until the maintainers define that process. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Remove section about reporting sec vulns since that does not exists --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent af4acb8 commit 27d00a0

8 files changed

Lines changed: 191 additions & 13 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ Ensure Docker Compose is running (`docker compose up -d`) before running the scr
4040
## Conventions
4141

4242
- **Security First**: The service design aims to protect private keys; keep the REST API surface small and exchange only necessary cryptographic data (no full documents or certificates).
43+
- **Security trade-offs**: Plain HTTP, static non-expiring tokens, no rate limiting, unauthenticated health endpoints and descriptive validation errors are deliberate and documented in `SECURITY.md`. Update `SECURITY.md` whenever a change affects transport, authentication, error responses or supported algorithms.
4344
- **Error Handling**: Use the errors defined in RFC 6750 for client authentication and invalid requests.

‎README.md‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ A REST API service that performs RSA signing and decryption operations using pro
77

88
> **Design specifications:** See [DESIGN-SPECIFICATION.md](docs/DESIGN-SPECIFICATION.md) for the full architecture, API contract, configuration reference, and implementation details.
99
10+
> **Security:** by design the agent serves plain HTTP and uses static bearer tokens that never expire. It must run in an environment that provides TLS, network isolation and token rotation. Read [SECURITY.md](SECURITY.md) before deploying it anywhere other than your own machine.
11+
1012
---
1113

1214
## Overview
@@ -52,9 +54,9 @@ Services like SimpleSAMLphp need to sign SAML assertions and decrypt RSA-encrypt
5254
- **Fail-fast configuration:** invalid or missing config prevents the application container from starting.
5355
- **Health endpoints:** `/v1/health` and `/v1/health/key/{key_name}` for liveness probes and monitoring.
5456

55-
> **Rate limiting** is deliberately out of scope for this application. Protection against bearer-token
56-
> brute-force attacks is an infrastructure responsibility (WAF, reverse proxy, Kubernetes Ingress).
57-
> See the [Design Specification](docs/DESIGN-SPECIFICATION.md) for the rationale.
57+
> **TLS, rate limiting and token rotation** are deliberately out of scope for this application. They
58+
> are infrastructure responsibilities (reverse proxy, WAF, Kubernetes Ingress, secrets manager).
59+
> See [SECURITY.md](SECURITY.md) for the required deployment environment and the rationale.
5860
5961
### Technology stack
6062

@@ -167,7 +169,7 @@ The private key files are **unencrypted and ephemeral** — suitable only for lo
167169

168170
`setup-dev.sh` generates a random 256-bit hex token per run and writes it into `config/private-key-agent.yaml`. It is printed to the terminal on completion.
169171

170-
> **Production equivalent:** generate a cryptographically random token of at least 256 bits and inject it into the config file via your secrets management solution (Docker secrets, Kubernetes secret, Vault, etc.). Each client should have its own token. **Never reuse the development token in production.**
172+
> **Production equivalent:** generate a cryptographically random token of at least 256 bits and inject it into the config file via your secrets management solution (Docker secrets, Kubernetes secret, Vault, etc.). Each client should have its own token. **Never reuse the development token in production.** Tokens never expire, so plan rotation up front: see [SECURITY.md — Rotating a token](SECURITY.md#rotating-a-token).
171173
172174
#### Summary: dev → production mapping
173175

@@ -176,6 +178,9 @@ The private key files are **unencrypted and ephemeral** — suitable only for lo
176178
| Unencrypted PEM key in `config/keys/` | PEM key with restricted filesystem permissions, or secrets-manager-mounted key |
177179
| Hardcoded token in `config/private-key-agent.yaml` | Randomly generated token injected at deploy time via secrets management |
178180
| Single `dev-client` with access to all keys | One client entry per consuming service, with `allowed_keys` scoped to only the keys that service needs |
181+
| Plain HTTP on port 80, published on all host interfaces | Agent port reachable only by its consumers, with TLS terminated in front of it whenever traffic leaves the host |
182+
183+
The full list of production requirements is in [SECURITY.md](SECURITY.md#required-deployment-environment).
179184

180185
---
181186

@@ -290,8 +295,8 @@ End-to-end HTTP tests against the running stack (run from the host, not inside t
290295
# Verbose + single group
291296
./tools/test-endpoints.sh -v sign
292297

293-
# Target a different host
294-
BASE_URL=http://agent.example.com ./tools/test-endpoints.sh
298+
# Target a different host (use HTTPS for anything other than localhost — see SECURITY.md)
299+
BASE_URL=https://agent.example.com ./tools/test-endpoints.sh
295300
```
296301

297302
The script reads the bearer token from `config/private-key-agent.yaml` automatically. Docker Compose must be running.
@@ -317,8 +322,8 @@ brew install hey
317322
# Combined options
318323
./tools/perf-test.sh -c 10 -d 15s sign
319324

320-
# Target a different host
321-
BASE_URL=http://agent.example.com ./tools/perf-test.sh
325+
# Target a different host (use HTTPS for anything other than localhost — see SECURITY.md)
326+
BASE_URL=https://agent.example.com ./tools/perf-test.sh
322327
```
323328

324329
The script runs a sanity check (HTTP 200) before each benchmark and skips the endpoint if the check fails.
@@ -353,9 +358,12 @@ Reports known vulnerabilities in installed packages via the Packagist Security A
353358

354359
The agent is configured from a single YAML file. The path is set via the `PRIVATE_KEY_AGENT_CONFIG` environment variable (default in Docker Compose: `/etc/private-key-agent/config.yaml`).
355360

361+
The file holds client tokens in plaintext. Make it readable only by the agent's service user and deliver it through a secrets manager; see [SECURITY.md](SECURITY.md) for this and the other deployment requirements.
362+
356363
### Minimal example
357364

358365
```yaml
366+
# Holds plaintext tokens that never expire. Read SECURITY.md before deploying.
359367
agent_name: my-private-key-agent
360368

361369
keys:

‎SECURITY.md‎

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Security Policy
2+
3+
The Private Key Agent keeps private keys out of the applications that use them. To stay small, it
4+
deliberately leaves transport encryption, secret lifecycle and abuse protection to the environment it
5+
runs in. On its own, the agent is not safe to expose to an untrusted network. This document lists
6+
what your environment must provide, the design decisions behind that, and how to report a
7+
vulnerability.
8+
9+
A bearer token is as powerful as the private keys it unlocks: whoever holds a client's token can sign
10+
and decrypt with every key that client may use, for as long as the token is configured. Most of the
11+
requirements below exist to keep tokens from leaking.
12+
13+
## Required deployment environment
14+
15+
Do not run the agent outside local development until your environment provides all of the following.
16+
17+
1. **A private network path.** Only the services that consume the agent can reach its port: the same
18+
host (loopback), a private network, or a network policy that allows nothing else.
19+
2. **TLS whenever traffic leaves the host.** Terminate TLS in a reverse proxy, ingress or service-mesh
20+
sidecar in front of the agent, and keep the hop from proxy to agent on the same host or a private
21+
network. Mutual TLS between consumer and proxy adds a second factor on top of the bearer token.
22+
3. **Strong, separate tokens.** At least 256 bits of randomness (for example `openssl rand -hex 32`),
23+
one token per consuming service, never reused across environments.
24+
4. **Protected configuration and key files.** The configuration file holds tokens in plaintext and the
25+
key files hold unencrypted private keys. Make both readable only by the agent's service user, and
26+
deliver them through a secrets manager (Docker or Kubernetes secrets, Vault) rather than baking them
27+
into images or committing them.
28+
5. **A token rotation procedure.** Rotate on a fixed schedule, and immediately when a token may have
29+
leaked or a consuming service is retired. See [Rotating a token](#rotating-a-token).
30+
6. **Rate limiting and request size limits** in the proxy, WAF or ingress in front of the agent.
31+
7. **Restricted health endpoints.** Expose `/v1/health` and `/v1/health/key/{key_name}` only to your
32+
monitoring and orchestration.
33+
8. **Up-to-date dependencies.** Rebuild the image regularly so Symfony and base-image security fixes
34+
are picked up. `composer audit` lists known advisories.
35+
9. **Log monitoring.** Alert on repeated invalid-token and access-denied warnings; they point to token
36+
guessing or a misconfigured consumer.
37+
38+
## Design decisions and known limitations
39+
40+
These are deliberate choices to keep the agent small. Each one moves a responsibility to the
41+
environment described above.
42+
43+
### Plain HTTP, no TLS
44+
45+
The Docker image serves the API over plain HTTP on port 80, and `compose.yaml` publishes that port on
46+
all host interfaces for local development. Bearer tokens travel in the `Authorization` header and
47+
decrypted session keys travel in the response body. Anyone who can observe this traffic can steal a
48+
token, and can read the session keys that protect encrypted SAML assertions.
49+
50+
TLS is left out of the agent because the proxy, ingress or mesh in front of a service already manages
51+
certificates, renewal and cipher policy, and does it better than a per-application setup would.
52+
53+
The Private Key Agent backends for `simplesamlphp/xml-security` require `https://` and allow plain
54+
HTTP only to a loopback address, and only when explicitly enabled. Other clients, including `curl`,
55+
the scripts in `tools/` and custom integrations, have no such guard.
56+
57+
Covered by requirements 1 and 2.
58+
59+
### Static bearer tokens
60+
61+
Clients authenticate with a pre-shared token from the configuration file. Tokens:
62+
63+
- never expire and are not rotated automatically;
64+
- stay valid until they are removed from the configuration and the agent is restarted;
65+
- are stored in plaintext in the configuration file;
66+
- are checked for a minimum length of 32 characters, not for randomness.
67+
68+
A leaked token therefore lets an attacker sign and decrypt with that client's keys until an operator
69+
replaces it. The agent has no token endpoint, expiry or revocation list, because each would add state,
70+
dependencies and attack surface to a service whose only job is to guard keys. Tokens are compared in
71+
constant time and are never logged.
72+
73+
Covered by requirements 3, 4, 5 and 9.
74+
75+
#### Rotating a token
76+
77+
Each client entry has exactly one token, so rotate by running the old and new token side by side:
78+
79+
1. Add a second client entry with a new `name`, a new `token` and the same `allowed_keys`.
80+
2. Restart the agent so it loads the new configuration.
81+
3. Switch the consuming service to the new token.
82+
4. Remove the old client entry and restart the agent again.
83+
84+
To revoke a token immediately, remove its client entry and restart the agent.
85+
86+
### No rate limiting or request size limits in the application
87+
88+
The agent answers every request: an invalid token always gets `401`, never `429`. With 256-bit tokens,
89+
brute force is infeasible at any request rate, and throttling belongs in the layer that already sees
90+
all traffic. The bundled Apache configuration limits request bodies to 64 KB.
91+
92+
Covered by requirement 6.
93+
94+
### Unauthenticated health endpoints
95+
96+
`/v1/health` and `/v1/health/key/{key_name}` need no token, so orchestrators and load balancers can
97+
probe them. They reveal which key names exist and whether each key is healthy.
98+
99+
Covered by requirement 7.
100+
101+
### Descriptive validation errors
102+
103+
When an authenticated request is malformed, the `400` response says what is wrong, for example that
104+
the hash length does not match the algorithm or that the ciphertext length does not match the key
105+
size. This helps integrators, and none of it is secret: expected hash lengths are public, and the key
106+
size follows from the public key. Only callers with a valid token see these messages.
107+
108+
Decryption failures are the exception: every failure of the RSA operation returns the same generic
109+
`400`, so error messages cannot be used as a padding oracle. Backend and internal errors return a
110+
generic `500`; the details go to the log only.
111+
112+
### Legacy algorithms for SAML interoperability
113+
114+
The agent accepts `rsa-pkcs1-v1_5` decryption and `rsa-pkcs1-v1_5-sha1` signing because existing SAML
115+
partners still use them. PKCS#1 v1.5 encryption is inherently exposed to Bleichenbacher-style
116+
padding-oracle attacks. Configure consumers to use OAEP (`rsa-pkcs1-oaep-mgf1-sha256` or stronger) and
117+
SHA-256 or stronger signatures wherever partners allow it.
118+
119+
### Unencrypted key files
120+
121+
The agent loads private keys from PEM files without a passphrase. Their protection comes from file
122+
permissions and from the secrets manager that delivers them.
123+
124+
Covered by requirement 4.
125+
126+
## What the agent protects
127+
128+
In an environment that meets the requirements above, the agent guarantees that:
129+
130+
- private keys never leave the agent process: only hashes and ciphertext go in, only signatures and
131+
decrypted session keys come out;
132+
- a client can use only the keys in its `allowed_keys`, and a key only for the operations in its
133+
`operations`;
134+
- tokens are compared in constant time;
135+
- tokens, key material, hashes and decrypted values are never logged;
136+
- an invalid or incomplete configuration stops the agent from starting.
137+
138+
## Related documents
139+
140+
- [README](README.md): setup and the development-to-production mapping
141+
- [Design specification](docs/DESIGN-SPECIFICATION.md): architecture and configuration reference
142+
- [API reference](docs/api.md): endpoints and error responses
143+
- [OWASP ASVS Level 1 audit (2026-05-15)](docs/openconext-private-key-agent-ASVS-L1-audit-2026-05-15.md)

‎compose.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ services:
99
- .:/var/www/html
1010
- ./config/private-key-agent.yaml:/etc/private-key-agent/config.yaml:ro
1111
- ./docker/app.dev.ini:/usr/local/etc/php/conf.d/zz-app-local.ini:ro
12+
# Local development only: publishes plain HTTP on all host interfaces.
13+
# See SECURITY.md for production requirements.
1214
ports:
1315
- "80:80"
1416
restart: unless-stopped

‎docker/apache-app.conf‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Plain HTTP by design: terminate TLS in front of the agent and keep this port
2+
# on a private network. See SECURITY.md.
13
<VirtualHost *:80>
24
DocumentRoot /var/www/html/public
35

0 commit comments

Comments
 (0)