Skip to content

Commit e2995ef

Browse files
authored
docs: add SSH passthrough instructions to with-docker-rootless (#17505) (#17508)
The passthrough is based upon AuthorizedKeysCommand and a custom shell wrapper that forwards commands to the container over the docker pipe.
1 parent 599ff1c commit e2995ef

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

docs/content/doc/installation/with-docker-rootless.en-us.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,43 @@ services:
285285

286286
To set required TOKEN and SECRET values, consider using gitea's built-in [generate utility functions](https://docs.gitea.io/en-us/command-line/#generate).
287287

288-
# SSH Container Passthrough (not tested)
288+
# SSH Container Passthrough
289289

290-
This should be possible by forcing `authorized_keys` generation via `gitea admin regenerate keys`.
290+
Since SSH is running inside the container, SSH needs to be passed through from the host to the container if SSH support is desired. One option would be to run the container SSH on a non-standard port (or moving the host port to a non-standard port). Another option which might be more straightforward is to forward SSH commands from the host to the container. This setup is explained in the following.
291291

292-
We should use directly [SSH AuthorizedKeysCommand](https://docs.gitea.io/en-us/command-line/#keys) when it will be based on internal api.
292+
This guide assumes that you have created a user on the host called `git` with permission to run `docker exec`, and that the gitea container is called `gitea`. You will need to modify that user's shell to forward the commands to the `sh` executable inside the container, using `docker exec`.
293+
294+
First, create the file `/usr/local/bin/gitea-shell` on the host, with the following contents:
295+
296+
```bash
297+
#!/bin/sh
298+
/usr/bin/docker exec -i --env SSH_ORIGINAL_COMMAND="$SSH_ORIGINAL_COMMAND" gitea sh "$@"
299+
```
300+
301+
Note that `gitea` in the docker command above is the name of the container. If you named yours differently, don't forget to change that.
302+
303+
You should also make sure that you’ve set the permissions of the shell wrapper correctly:
304+
305+
```bash
306+
sudo chmod +x /usr/local/bin/gitea-shell
307+
```
308+
309+
Once the wrapper is in place, you can make it the shell for the `git` user:
310+
311+
```bash
312+
sudo usermod -s /usr/local/bin/gitea-shell git
313+
```
314+
315+
Now that all the SSH commands are forwarded to the container, you need to set up the SSH authentication on the host. This is done by leveraging the [SSH AuthorizedKeysCommand](https://docs.gitea.io/en-us/command-line/#keys) to match the keys against those accepted by gitea. Add the following block to `/etc/ssh/sshd_config`, on the host:
316+
317+
```bash
318+
Match User git
319+
AuthorizedKeysCommandUser git
320+
AuthorizedKeysCommand /usr/bin/docker exec -i gitea /usr/local/bin/gitea keys -c /etc/gitea/app.ini -e git -u %u -t %t -k %k
321+
```
322+
323+
All that is left to do is restart the SSH server:
324+
325+
```bash
326+
sudo systemctl restart sshd
327+
```

0 commit comments

Comments
 (0)