Summary
A path traversal flaw in Incus's systemd credential handling for containers allows crafted configuration keys to escape the intended credentials directory.
When exploited, an attacker with control over container configuration can cause Incus to write arbitrary files on the host filesystem as root, leading to privilege escalation and denial of service conditions.
Affected context
This vulnerability affects Incus deployments that:
- Use Incus to manage system containers with systemd integration, and
- Allow configuration of
systemd.credential.*keys for instances, and - Rely on a shared directory mechanism to pass credentials into containers.
The issue manifests when the credential key name includes directory traversal sequences (e.g., ../) embedded in the portion after systemd.credential., allowing writes outside the intended credentials directory associated with a container.
Exploit preconditions
- Attack surface: Incus container configuration interface (API, CLI, or any higher-level management system that sets instance config keys).
- Required access: Ability to define or modify instance configuration keys, specifically those beginning with
systemd.credential.for a target container. - Trigger point: Incus processing of systemd credential configuration for containers, where the credential key name is resolved into a path on the shared credentials directory.
- Why exploitation is possible: The component that maps
systemd.credential.XYZkeys to filesystem paths accepts untrustedXYZvalues without strictly normalizing or rejecting path traversal patterns. BecauseXYZcan contain additional periods and path separators, an attacker can inject../sequences to escape the credential directory and cause Incus to create or overwrite files elsewhere as root.
Why this happens
The underlying bug is a path traversal issue in how Incus converts logical credential configuration keys into filesystem paths for the shared systemd credentials directory.
The configuration syntax systemd.credential.XYZ assumes that XYZ is a safe, relative name under a fixed directory. However, input validation and path normalization are insufficient: the implementation does not robustly sanitize or constrain XYZ to stay within the intended credentials directory. As a result, keys like systemd.credential.../../../../../../root/.bashrc can cause relative path segments to escape the directory boundary, mapping directly to sensitive locations on the host filesystem. This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where failure to enforce directory constraints allows unintended file access—in this case, arbitrary file writes as root.
Potential impact
- Overwriting critical system files (e.g., shell initialization files, service configs) as root, which could enable privilege escalation.
- Injecting malicious commands or configuration into files read by privileged processes on the host.
- Causing denial of service by corrupting essential system files or configuration used by Incus or the host OS.
- Interfering with container or systemd behavior by altering files used during startup.
- Potentially establishing persistence by modifying login shells or startup scripts that run with elevated privileges.
General mitigation guidance
Effective mitigation focuses on constraining how configuration-derived paths are interpreted and written:
- Enforce strict path normalization: Normalize all derived paths and verify that the final, canonical path remains within the intended credentials directory before performing any write.
- Reject unsafe characters and segments: Disallow
../, absolute paths, path separators, and other traversal constructs in credential key suffixes. Treat the credential name as a simple identifier rather than a free-form path. - Apply allowlists: Use a restricted, documented set of valid credential key formats, mapping them to filenames via a controlled transformation instead of direct concatenation.
- Use dedicated mapping logic: Map logical keys to filenames using opaque identifiers or hashes, ensuring that user-controlled data cannot directly influence directory structure.
- Harden privilege boundaries: Where possible, limit the scope of root-level writes and isolate components that process guest configuration so that even if a path error occurs, it cannot affect sensitive host areas.
How teams detect issues like this
Detection efforts can focus on both code-level analysis and runtime behavior:
- Static analysis patterns:
- Searches for string concatenation or interpolation that builds filesystem paths from configuration keys, especially under
systemd.credential.*. - Rules highlighting use of relative paths or lack of canonicalization checks before file writes.
- Identification of file operations that do not enforce a fixed base directory or that omit checks against directory traversal patterns.
- Code review signals:
- Logic that transforms instance configuration values into filenames without explicit validation.
- Absence of checks ensuring derived paths remain within a predefined credentials directory.
- Complex parsing of dotted key names where subcomponents can include periods or slashes.
- Runtime and policy enforcement:
- Monitoring for unusual writes from Incus or related processes to sensitive locations (e.g.,
/root,/etc) that should not be touched by credential handling. - Using security policies (e.g., MAC frameworks, container confinement profiles) to restrict directories that Incus credential-handling code can write to.
- Incorporating automated security scans or SAST tools into CI/CD pipelines to flag potential directory traversal patterns before deployment.

