-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Description
Feature Description
I found a simple and effective way to set up an SSH passthrough that works with the rootless docker image. It leverages the AuthorizedKeysCommand configuration in sshd, and doesn't require mounting the ~/.ssh
directory or synchronizing the authorized_keys
file between host and container. It also works fine with the internal gitea ssh server.
I've tested it under podman, but it should work with docker as well. I can write and submit a PR for the rootless documentation.
I suspect it would also work for the rootfull docker image, but haven't tested. It's a lot simpler to setup than the current method, so if valid it could also replace it.
The details are as follows for podman, but will likely work for docker by just changing the binary name:
In the host, create an executable containing the following, replacing with the actual name of the container:
# cat /usr/bin/gitea-shell
#!/bin/bash
/usr/bin/podman exec -i --env SSH_ORIGINAL_COMMAND="$SSH_ORIGINAL_COMMAND" <container-name> bash "$@"
Then set it as the shell for the gitea user (git
in this case) on the host:
# usermod -s /usr/bin/gitea-shell git
Finally add the following to /etc/ssh/sshd_config
, also replacing with the actual container name:
Match User git
AuthorizedKeysCommandUser git
AuthorizedKeysCommand /usr/bin/podman exec -i <container-name> /usr/local/bin/gitea keys -c /etc/gitea/app.ini -u %u -t %t -k %k
Don't forget to restart sshd for these settings to take effect:
# systemctl restart sshd
And that's it.
EDIT: forgot to remove the -t
options from podman exec
. These can modify the output and break the git protocol.
Screenshots
No response