Skip to content

[Potential Security Issue] Leaking ssh host keys #14

@AnixPasBesoin

Description

@AnixPasBesoin

Issue

By default, ssh host keys provided by the user will be mounted on /tmp/host-keys, as shown in the provided docker-compose template:

...
environment:
# Path where the SSH host keys will be mounted in the container
# in order to replace the default keys
# SSH_HOST_KEYS_PATH: /tmp/host-keys
...

And latter on, these files are copied to /etc/ssh/ using:

...
if [ -n "${SSH_HOST_KEYS_PATH-}" ]; then
    if [ -d "${SSH_HOST_KEYS_PATH}" ]; then
        cd /etc/ssh
        rm -rf ssh_host_*
        cp "${SSH_HOST_KEYS_PATH}"/ssh_host_* .
        chmod 600 ssh_host_*
        chmod 644 ssh_host_*.pub
    else
        warn "Directory '${SSH_HOST_KEYS_PATH}' not found."
        warn "Default SSH host keys will be used instead."
    fi
fi
...

The issue with the above is that /tmp can be read by any user, which means that the private host key can be read by non-priveleged users...

Fix

  • Use a different default destination, and/or
  • Delete files once copied to /etc/ssh

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions