Restoring an Archive Can Restore Linux File Capabilities Too
An archive restore is commonly treated as a copy operation. On Linux it can also be a privilege operation. File modes, access control lists, extended attributes, and file capabilities can all travel with the archive. A service account that can write an extracted file is dangerous enough. A file that regains security.capability during extraction may be able to execute with privileges that ordinary permission checks do not reveal.
GNU tar documents that extraction normally applies the user's umask to archived permissions. The --same-permissions or --preserve-permissions option restores modes from the archive. Extended attributes need the --xattrs family, and the manual states that extraction with --xattrs defaults to the user namespace unless a wider pattern is requested.
That default is an important distinction. An archive can contain the file and mode that an operator expects while the capability attribute is dropped or restored depending on flags, privileges, filesystem support, and namespace handling. A successful restore is not proof that the security metadata reached the intended state.
Where the extra authority comes from
The Linux credentials model treats file capabilities as exec-time privilege escalation bits. They are part of the file's security context rather than a process setting that disappears when the parent shell exits. A binary with the right effective capability can perform an operation that its numeric UID would otherwise be denied, subject to the kernel's capability checks and the active Linux Security Module policy.
This is why an extraction directory can become a privilege boundary. If an application, CI worker, or unprivileged user can replace a capability-bearing binary or cause it to execute, the archive pipeline may have converted file-write access into a more useful capability.
Make restoration explicit
Define whether each archive is a data restore, a package deployment, or a full filesystem recovery. Those operations should not share one extraction command and one destination.
For a data restore, use a destination owned by the application and do not grant extraction rights over system paths. If the archive is not trusted to carry security metadata, exclude it deliberately and verify the result. If a system restore must preserve capabilities, run it with a reviewed privilege boundary and a narrow destination:
tar --xattrs --xattrs-include='security.capability' \
--same-permissions --file backup.tar --extract --directory /reviewed/root
The exact options must be tested on the target tar, filesystem, and kernel. --same-permissions restores archived modes, which can also restore setuid or setgid bits. A restore process that runs as root should use a dedicated working directory, avoid untrusted path names, and preserve owner and permission decisions as separate controls.
Verify the security metadata
After extraction, compare more than file hashes. Check the resulting modes, ownership, ACLs, and capabilities. Commands such as getcap -r can identify files carrying capabilities, while the distribution's archive and filesystem tools can report whether security attributes were accepted. A pipeline that silently skips unsupported attributes should fail closed when those attributes are part of the intended state.
Keep these checks in the restore job rather than relying on a one-time operator review. A later archive can carry a new capability or a different owner mapping even when the application files look unchanged.
Operational limits
Capabilities do not make an application trusted. They can add authority to a compromised process, and a file with no capability can still be dangerous if the service runs as root or has access to credentials. Conversely, a filesystem or container runtime may prevent the attribute from being restored. The correct conclusion is not that every archive is malicious. It is that restore tooling must state which security metadata it preserves and prove that the production path matches that statement.
Top comments (0)