Reviewer · Security
Fail-closed security validation
When a code path depends on an externally-controlled value, an advertised capability, or an isolation boundary for its security guarantee, verify it explicitly and reject the request if verification is not possible — never silently fall back to a less-restrictive behavior. Silent fallbacks turn an opt-in security control into something that looks enforced...
When a code path depends on an externally-controlled value, an advertised capability, or an isolation boundary for its security guarantee, verify it explicitly and reject the request if verification is not possible — never silently fall back to a less-restrictive behavior. Silent fallbacks turn an opt-in security control into something that looks enforced but isn’t.
Apply this in at least these situations:
- Untrusted identifiers that are later used to build filesystem paths (e.g. a checkpoint-id) must be validated against a strict allow-list pattern before use, to prevent path traversal.
- Numeric ranges used for OS/runtime-level security semantics (e.g. ID-mapping source/target/size) must be validated for both the start and the computed end of the range, not just the individual fields, to prevent overflow/out-of-range values from reaching the OCI runtime.
- Operations that depend on a remote feature or capability (e.g. an OCI runtime supporting idmap/rro mounts) must check that the capability is actually advertised before relying on it, and reject the operation otherwise.
- Config isolation/protocol restrictions enforced on a primary operation (e.g. git clone’s disallowed-protocol and isolated-config settings) must be propagated to all secondary operations it triggers (e.g. submodule fetches), so the restriction can’t be bypassed through a side channel.
- Features that exist specifically to enforce isolation (e.g. deriving a container’s cgroup parent from the calling client) must fail the request with a clear error when the enforcement data can’t be obtained or resolves to an unsafe value (missing peer credentials, empty/root cgroup), rather than falling back to a default that defeats the purpose of the feature.
- Mount/bind targets that could undermine container configuration (e.g. id-mapped binds over
/etc/hosts,/etc/hostname,/etc/resolv.conf) must be explicitly rejected rather than having the security-relevant option silently dropped.
Example of the fail-closed pattern:
cgroupPath, err := cgrouputil.GetClientCgroup(cred.PID)
if err != nil || cgroupPath == "" || cgroupPath == "/" {
// Reject instead of silently using the daemon's default cgroup parent,
// which would defeat the isolation this flag is meant to enforce.
return errdefs.InvalidParameter(errors.New("cannot determine client cgroup for enforced cgroup-parent-from-client"))
}
Treat any place where a security option can be ignored, a capability assumed, or a restriction not propagated to downstream operations as a bug: the correct behavior is always to reject the operation with a clear error, not to proceed with reduced security.