mirror of
https://github.com/apple/container.git
synced 2026-10-13 09:39:18 +00:00
Fixes #518. ## What vminitd logs the full OCI spec and exec process at debug level in `ManagedContainer` ("created bundle with spec …", "creating exec process with …"), which puts every `NAME=value` environment entry into the boot log. Environment variables routinely carry secrets, so `container logs --boot web | grep PASSWORD` reproduces the leak exactly as described in #518. Rather than redacting at the call sites, this makes the redacted form the *default* rendering of the types that own an environment: `Process` and `Hook` conform to `CustomStringConvertible` with values masked and names kept. `Spec` and `Hooks` inherit it, because Swift's reflection-based description renders a nested value through that value's own `description`. The effect is that any `\(spec)` or `\(process)` is safe without the author knowing this file exists, which is what stops a log line added later from reintroducing the leak. The two existing log sites are unchanged, so this no longer touches vminitd at all. Two details worth calling out: - **`Codable` is untouched.** `description` governs text rendering only, so an encoded spec still carries the real values and nothing changes about what is written to disk or sent to the guest. The unredacted environment also remains available to callers through `process.env`. - **`description` renders through a mirror** rather than a hand-written field list. `Process` has 13 fields; listing them by hand would drop the rest from the log line and would rot as fields are added. ## Verification - New `SpecRedactionTests` (9 tests) cover: a whole `Spec` interpolated into a log line never renders the values; `String(describing:)` and `String(reflecting:)` are redacted too; variable names survive; `NAME`-only inherit entries pass through; `NAME=` and values containing further `=` are masked whole; encoding round-trips with the real values; rendering does not mutate; and the other fields are still rendered. - Negative control: with the redaction disabled the suite fails with 13 issues, and the output shows the secret in the clear, reproducing #518. - Full `ContainerizationOCITests` passes, 58 tests in 9 suites. - `swift format lint --strict --configuration .swift-format-nolint` is clean, and `swift format` leaves both files unchanged. Every line here is one I can explain and justify; the reasoning above is the complete rationale for each change.