You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit was created on GitHub.com and signed with GitHub’s verified signature.
Added
KMS wrapping of secret.key (#61; the Vault Transit part of #62). With MONGORESCUE_KEY_WRAP=<provider>:<key URI> (or -key-wrap) the data directory holds only secret.key.wrapped, which every start unwraps with the instance's own identity. See docs/security.md.
Providers.aws-kms (AWS SDK, default credential chain, encryption context), gcp-kms (Cloud KMS REST API with Application Default Credentials and CRC32C checks), azure-keyvault (wrapKey/unwrapKey with RSA-OAEP-256 and DefaultAzureCredential) and vault-transit (a minimal HTTP client with token, AppRole or Kubernetes authentication). Key URIs are validated and never hold credentials; http:// (Vault only) needs MONGORESCUE_KEY_WRAP_ALLOW_INSECURE=true (development only, logged as a warning), and no KMS client follows redirects.
Migration. The first start with wrapping on wraps secret.key (and the .next and .previous files of a key rotation), writes the wrapped files atomically, checks that they unwrap to the same keys and only then removes the plaintext files (renamed aside first, then overwritten, synced and deleted); an interrupted migration finishes at the next start, and leftovers of a crash during the removal are cleaned up with a warning instead of failing the start.
Startup. The unwrap is retried while the KMS is unreachable and fails with an actionable error (provider, key URI, permissions to check) when it stays so or refuses; there is never a fallback to a plaintext key. A data directory with secret.key.wrapped refuses to start without MONGORESCUE_KEY_WRAP, and MONGORESCUE_SECRET_KEY cannot be combined with it.
Key rotation and other KMS keys. A secret.key rotation wraps the new key before it is written. mongorescue key rewrap --to <provider>:<key URI> moves the wrapped keys to another KMS key, mongorescue key unwrap --confirm-plaintext leaves the KMS, and mongorescue key status shows the stored key's provider and fingerprint; all run offline on the data directory and take the KMS key from MONGORESCUE_KEY_WRAP (or a confirmed --from), never from the data directory.
Recovery kit. With wrapping on, the kit carries secret.key.wrapped and the KMS key URI, and its README explains that recovery needs the KMS key; the plaintext key only with "plaintext_secret_key": true (audited, and approved by a second administrator under the two-person rule: approval kind plaintext_recovery_kit, usable once by the requester within an hour). GET /api/v1/recovery-kit reports key_wrapped.
HA. Instances share the wrapped key (or wrap copies of the same key); the lease's shared-key check still applies, and an instance unwraps once per process, so a takeover does not need the KMS.
Observability. The event security.key_wrapping_changed (wrapped, rewrapped, unwrapped_to_file) with audit entries keywrap.*, the series mongorescue_key_wrapping_active, mongorescue_key_wrap_duration_seconds and mongorescue_key_wrap_errors_total, and key_wrapping in GET /api/v1/readiness.
The Helm chart has a keyWrap value, and docs/kubernetes.md covers IRSA, GKE and Azure Workload Identity and Vault's Kubernetes auth. The integration suite tests AWS KMS on LocalStack and Vault Transit on a Vault dev server; Google Cloud KMS and Azure Key Vault are covered by contract tests against httptest fakes.
API key expiry (#190). A key may get an expiry when it is created (expires_at or expires_in_days in POST /api/v1/api-keys; 30, 90, 180 or 365 days or a date in the dashboard), and security.api_key_max_lifetime_days (default 0, unlimited) caps every key. See docs/security.md.
Refusal. From its expiry a key is refused with 401 and the code api_key_expired (a new code field of the error envelope) on every route, /mcp and /metrics included, and each refusal is audited with the key. apiclient reports ErrAPIKeyExpired (also ErrUnauthorized), and the CLI exits 3 with a hint to create a new key.
Maximum lifetime. While it is set, new keys need an expiry within it (400 otherwise), and every key except the imported one that has no expiry or a later one gets the deadline now + the lifetime once per maximum (a clock stepping back does not cap again), announced by the api_key.deadline_set event, an audit entry and a log line. Existing keys keep no expiry until then; only the key imported from MONGORESCUE_API_KEY (now flagged imported) keeps none and raises the api_key_never_expires warning; keys it creates record it in created_by_key and are capped like any other.
Warnings.security.api_key_expiry_warning_days (default 14): a key within it is announced once by api_key.expiring, listed in the api_keys_expiring settings warning and counted by mongorescue_api_keys_expiring (mongorescue_api_keys_expired counts expired keys not yet revoked). The keys list and GET /api/v1/auth/me (key_expires_at) show the expiry; the dashboard strings come in all eight languages.
Store migration 0030_api_key_expiry adds expires_at, expiry_max_days, expiry_warned_for, imported (backfilled for the imported key) and created_by_key to api_keys; releases before this one refuse a database at this version.
REST API rate limits (#191). Every API key and every session has a token bucket: security.api_rate_limit_per_minute (default 1200) and security.api_rate_limit_burst (default 300), 0 turns the limit off. Routes that start work spend a tighter budget too: security.api_work_rate_limit_per_minute (default 60) and _burst (20). Unauthenticated requests get 300 a minute (bursts of 100) per client address, with IPv6 counted by /64. The sign-in routes have a bucket of their own, so failed credentials elsewhere cannot lock out signing in. Behind a reverse proxy this needs security.trust_proxy_headers, and a one-time warning is logged when forwarding headers arrive while it is off. See docs/security.md.
Refusal. A request over a budget answers 429 before it runs, with Retry-After and the new envelope field code: "rate_limited". GET /api/v1/health and /metrics with a valid key are never limited (a wrong key counts against the address), and /mcp keeps its own limit.
Observability.mongorescue_api_rate_limited_total{caller, budget}, a log line at most once a minute per caller, and audit entries (refused changes as before with outcome rate_limited, coalesced, plus a caller's first refusal per minute even for a read).
Clients.
The dashboard waits for Retry-After and sends the refused request again once; its polling pauses meanwhile.
apiclient (and so the CLI) sends a refused request again after Retry-After, twice, for waits of up to 30 seconds.
The routes that start work are listed in a table that a test keeps in step with the routes.
The buckets are shared with the MCP limiter (new package internal/ratelimit). Memory is bounded at 100,000 buckets: refilled buckets are dropped first, then the least recently used, so a flood of new keys cannot reset a throttled one. The dashboard settings come in all eight languages.
Signed releases (#144). The release archives, their SBOMs, checksums.txt, the desktop assets and the desktop checksums are signed with Sigstore cosign keyless signing (GitHub Actions OIDC, no keys or secrets): each asset gets a <asset>.sigstore.json bundle. The archives and checksums.txt also get SLSA Build Level 3 provenance (mongorescue_<version>.intoto.jsonl, from slsa-github-generator), next to the existing GitHub artifact attestations and SBOMs, and container images are signed with cosign by digest. The release jobs build without a cache. Verification with cosign verify-blob, cosign verify, slsa-verifier and gh attestation verify in docs/security.md.
Continuous fuzzing with ClusterFuzzLite (#144): .clusterfuzzlite/ builds every native Go fuzz target as a libFuzzer binary, and .github/workflows/cflite.yml fuzzes the targets a pull request affects for 5 minutes, runs an hour of batch fuzzing daily and prunes the corpus weekly. New fuzz targets for PEM and PKCS#8 TLS keys and certificates (FuzzDecryptKey, FuzzCheckKDF, FuzzConfig in internal/mongotls), the HA storage location (FuzzParseHATarget, FuzzHATargetLabel, FuzzFileTargetPath in internal/config) and the synthetic oplog archive (FuzzArchiveWriter); FuzzParseProgress now runs with the others (make fuzz, make fuzz-list).
A threat model (#144): docs/threat-model.md covers every component with STRIDE (assets, trust boundaries, threats, the mitigations and their code, residual risk, open items).
Changed
An HA instance keeps its HTTP listener open across role changes (#192). A takeover or a step-down closed the App of the old role and opened the next, so the port was closed for about a second and clients and load balancers saw connection refused. The HA supervisor now owns the listener and hands it from one App to the next: requests in progress on the old App drain as before (2 seconds on a takeover, none when the lease is lost) and are then aborted, the old App closes only once none of its requests runs, and the new App receives requests only once it has started. In between (and at startup, before the first App serves), every request but the health check and /metrics answers 503 with Retry-After: 1 and a JSON error, and GET /api/v1/health reports "role": "switching". Load balancers should treat 503 as not ready and route on "role": "active". The standby gate is unchanged, and so is a single instance. See docs/design/ha.md and docs/production.md.
HTTP requests of an HA active instance are fenced like its runs (#192). A request that may change something checks the HA fence when it arrives, and the synchronous changes of the API and MCP (backup deletion and undeletion, job edits, pauses and deletions, storage target and connection edits, dropping kept clones) check it again right before they commit; without the lease they answer 503 with Retry-After (operations.ErrNotActive) and change nothing. When the lease is lost, the runs (and the Database Tools' processes) are stopped at once, before the wait for the aborted requests, and a request whose handler had already finished gets its response instead of a cut connection.
Fixed
An s3:// HA storage location whose host has a colon (such as s3://key:123/secret@bucket, a credential with a / after a numeric first part) was accepted with the bucket key:123 and the rest of the credential as the prefix, and its log label showed it; it is now refused. Found by FuzzHATargetLabel.
A mongodump or mongorestore progress line with an empty quoted namespace was parsed as progress of a namespace without a name. Found by FuzzParseProgress.
Security
golang.org/x/net v0.58.0 → v0.60.0. The Azure SDK used for key wrapping links golang.org/x/net/http2 into the binary, which made five HTTP/2 advisories reachable (govulncheck): GO-2026-6617 (HPACK encoder race), GO-2026-6612 (double flow control refund), GO-2026-6611 (excessive CPU from repeated initial window changes), GO-2026-6610 (malformed framing headers accepted) and GO-2026-6603 (memory exhaustion through trailers); the image scan reported it as CVE-2026-78669.
API keys no longer have to live forever (#190): an expiry per key and a maximum lifetime limit how long a leaked or forgotten key stays usable, and keys that expire are announced in advance.
A leaked or runaway API key or session can no longer hammer the REST API (#191): requests are rate limited per key, per session and per client address, with a tighter budget for routes that start backups, restores, scans and other work.
HA metadata snapshots authenticate their cluster and epoch (#189). A snapshot's epoch and cluster were read from its object key only, so someone with write access to the HA target but without secret.key could copy an old snapshot (from before an API key was revoked or a user removed) under a higher epoch, or bring in a snapshot of another cluster sharing the key, and the next takeover restored it: the metadata rolled back silently, and the new lease's epoch followed the forged one. Snapshots now start with an encrypted header (format, cluster, epoch, instance_id, created_at) that age authenticates with the database. The takeover, the epoch floor of a new lease, retention and the startup key check verify it against the object key and refuse a mismatch or a snapshot that does not decrypt: it is never restored, never deleted, never raises the epoch, and the next verified snapshot is used. Refusals are logged and counted in the new mongorescue_ha_snapshots_rejected_total, with the alert rule MongoRescueHASnapshotRejected. Retention decides on verified snapshots only, so planted names never displace genuine ones. Snapshots written by earlier versions (no header) are restored only while the cluster has no snapshot with one, with a warning, and are deleted after the first new snapshot; an earlier version cannot restore the new format, so upgrade the standbys before the active instance. See docs/design/ha.md.
A new HA lease is no longer acquired while a metadata snapshot that sorts above the newest verified one cannot be checked (a storage error): it may carry the highest epoch, so the acquisition waits, as after a listing error, instead of taking its epoch from an older snapshot (#189).
HA snapshot retention stays bounded however many objects are planted on the HA target (#189). Every decision reads the whole listing instead of stopping after 64 headers, and each instance remembers every check per stored object version, so a snapshot is downloaded and reported once. Refused snapshots never count toward the kept ones and are never deleted: the new gauge mongorescue_ha_refused_snapshots keeps MongoRescueHASnapshotRejected firing until someone deletes them (docs/design/ha.md says how). A snapshot that cannot be checked (a storage error, a newer format) only protects the snapshots that sort before it; the older ones are pruned as usual.
HA takeovers refuse to roll the metadata back (#189). Whoever can write to the HA target could still delete the newest snapshots (or the lease) so that an older genuine snapshot was restored. The lease now carries last_snapshot_epoch and last_snapshot_at, which the active instance updates after every snapshot it writes, and a mac (HMAC-SHA256 with an HKDF subkey of secret.key, domain ha-lease) over the cluster, epoch, holder and last snapshot. A takeover is refused, counted in mongorescue_ha_rollback_suspected_total{reason} and alerted (MongoRescueHARollbackSuspected) when the lease it replaced is unreadable or has no valid MAC, when no lease exists although snapshots do, when the newest verified snapshot is older than the one the lease names or than this instance's high-water mark (the newest snapshot it wrote or restored, now kept per cluster in ha.json), or when only header-less snapshots are left after the cluster wrote ones with a header. It never restores an older snapshot while a newer one cannot be read: it tries four times and gives up. A takeover is also refused when a verified snapshot was written under a higher epoch than the lease's (an older lease put back) or when the lease lags the verified snapshots by more than one write. Taking over without a lease and without any snapshot is allowed only on a genuine first activation: no HA history for the cluster in ha.json (a new cluster, or HA enabled on an existing instance, whose database is kept); it is never silent: mongorescue_ha_empty_starts_total, the critical alert MongoRescueHAStartedFromEmptyState and the event ha.empty_start (to every channel) name the cluster and the instance, and after an unexpected one the operator checks the HA target and runs a storage scan to re-import the archives. The new command mongorescue ha force-takeover --from-snapshot <key> (or --keep-local-database) lets an operator force one takeover past these checks after checking the HA target; it works on the instance's data directory, and the forced takeover is logged, recorded in the audit log and sent as security.destructive_action. Upgrading: leases of earlier versions have no MAC; such a lease (like a header-less snapshot) is trusted on first use, only while the HA target holds no snapshot of the cluster with an authenticated header and the instance has never seen an authenticated lease (seen_authenticated_lease in ha.json), so a rolling upgrade (standbys first, active last) needs no operator; an old instance that becomes active again after the upgraded ones wrote snapshots needs the command (docs/production.md). Deleting the lease by hand, and the secret key rotation procedure, need the command. See docs/design/ha.md.