Security experts often face the risk of private SSH keys being compromised when accessed by applications within containers. To mitigate this, developers can use a dedicated SSH agent instead of mounting keys directly, ensuring the container never gains access to the raw private key material.
The proposed architecture involves passing a Unix socket for the SSH agent into the container. This setup requires the Docker daemon to run in rootless mode, with the container process operating under a non-root user. This configuration prevents the container from reading sensitive credentials even if the process is compromised.
A significant technical challenge in rootless Docker is the discrepancy between UID/GID inside the container and on the host due to user namespaces. Because the kernel and the SSH agent verify client identity based on the host-side UID, developers must calculate the correct mapping using /etc/subuid and /etc/subgid files.
To implement this, one must determine the container's internal UID/GID and map them to the host's subordinate range. Once the host-side UID is identified, it is used to configure the SSH agent process. This ensures that the Unix socket permissions align correctly, allowing the container to authenticate without exposing the private key.





