Skip to content

Commit 653a582

Browse files
author
zjj
committed
* 'main' of https://github.com/go-gitea/gitea: [skip ci] Updated translations via Crowdin Fix partial cloning a repo (go-gitea#18373) Switch to non-deprecation setting (go-gitea#18358) Update the SSH passthrough documentation (go-gitea#18366) Don't underline commit status icon on hover (go-gitea#18372)
2 parents abee597 + 4bfd749 commit 653a582

File tree

21 files changed

+323
-69
lines changed

21 files changed

+323
-69
lines changed

custom/conf/app.example.ini

+3-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ RUN_MODE = ; prod
211211
;; Enables git-lfs support. true or false, default is false.
212212
;LFS_START_SERVER = false
213213
;;
214-
;; Where your lfs files reside, default is data/lfs.
215-
;LFS_CONTENT_PATH = data/lfs
216214
;;
217215
;; LFS authentication secret, change this yourself
218216
LFS_JWT_SECRET =
@@ -2183,6 +2181,9 @@ PATH =
21832181
;;
21842182
;[lfs]
21852183
;STORAGE_TYPE = local
2184+
;;
2185+
;; Where your lfs files reside, default is data/lfs.
2186+
;PATH = data/lfs
21862187

21872188
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21882189
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docker/root/etc/templates/app.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ DISABLE_SSH = $DISABLE_SSH
2020
SSH_PORT = $SSH_PORT
2121
SSH_LISTEN_PORT = $SSH_LISTEN_PORT
2222
LFS_START_SERVER = $LFS_START_SERVER
23-
LFS_CONTENT_PATH = /data/git/lfs
2423

2524
[database]
2625
PATH = /data/gitea/gitea.db
@@ -59,3 +58,6 @@ REVERSE_PROXY_TRUSTED_PROXIES = *
5958
[service]
6059
DISABLE_REGISTRATION = $DISABLE_REGISTRATION
6160
REQUIRE_SIGNIN_VIEW = $REQUIRE_SIGNIN_VIEW
61+
62+
[lfs]
63+
PATH = /data/git/lfs

docker/rootless/etc/templates/app.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ SSH_PORT = $SSH_PORT
2323
SSH_LISTEN_PORT = $SSH_LISTEN_PORT
2424
BUILTIN_SSH_SERVER_USER = $RUN_USER
2525
LFS_START_SERVER = $LFS_START_SERVER
26-
LFS_CONTENT_PATH = $GITEA_WORK_DIR/git/lfs
2726

2827
[database]
2928
PATH = $GITEA_WORK_DIR/data/gitea.db
@@ -55,3 +54,6 @@ REVERSE_PROXY_TRUSTED_PROXIES = *
5554
[service]
5655
DISABLE_REGISTRATION = $DISABLE_REGISTRATION
5756
REQUIRE_SIGNIN_VIEW = $REQUIRE_SIGNIN_VIEW
57+
58+
[lfs]
59+
PATH = $GITEA_WORK_DIR/git/lfs

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

+7
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,15 @@ Match User git
322322
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
323323
```
324324

325+
(From 1.16.0 you will not need to set the `-c /etc/gitea/app.ini` option.)
326+
325327
All that is left to do is restart the SSH server:
326328

327329
```bash
328330
sudo systemctl restart sshd
329331
```
332+
333+
**Notes**
334+
335+
This isn't actually using the docker SSH - it is simply using the commands around it.
336+
You could theoretically not run the internal SSH server.

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

+199-43
Original file line numberDiff line numberDiff line change
@@ -307,77 +307,233 @@ To set required TOKEN and SECRET values, consider using Gitea's built-in [genera
307307

308308
## SSH Container Passthrough
309309

310-
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 connections from the host to the container. This setup is explained in the following.
310+
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 connections from the host to the container.
311311

312-
This guide assumes that you have created a user on the host called `git` which shares the same `UID`/ `GID` as the container values `USER_UID`/ `USER_GID`. These values can be set as environment variables in the `docker-compose.yml`:
312+
There are multiple ways of doing this - however, all of these require some information about the docker being passed to the host.
313313

314-
```bash
315-
environment:
316-
- USER_UID=1000
317-
- USER_GID=1000
318-
```
314+
### SSHing Shim (with authorized_keys)
319315

320-
Next mount `/home/git/.ssh` of the host into the container. Otherwise the SSH authentication cannot work inside the container.
316+
The idea of this option is to use (essentially unchanged) the authorized_keys that gitea creates on the docker and simply shim the gitea binary the docker would use on the host to instead ssh into the docker ssh.
321317

322-
```bash
323-
volumes:
324-
- /home/git/.ssh/:/data/git/.ssh
325-
```
318+
- To make the forwarding work, the SSH port of the container (22) needs to be mapped to the host port 2222 in `docker-compose.yml` . Since this port does not need to be exposed to the outside world, it can be mapped to the `localhost` of the host machine:
326319

327-
Now a SSH key pair needs to be created on the host. This key pair will be used to authenticate the `git` user on the host to the container.
320+
```yaml
321+
ports:
322+
# [...]
323+
- "127.0.0.1:2222:22"
324+
```
328325
329-
```bash
330-
sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key"
331-
```
326+
- Next on the host create the `git` user which shares the same `UID`/ `GID` as the container values `USER_UID`/ `USER_GID`. These values can be set as environment variables in the `docker-compose.yml`:
327+
328+
```yaml
329+
environment:
330+
- USER_UID=1000
331+
- USER_GID=1000
332+
```
333+
334+
- Mount `/home/git/.ssh` of the host into the container. Otherwise the SSH authentication cannot work inside the container.
335+
336+
```yaml
337+
volumes:
338+
- /home/git/.ssh/:/data/git/.ssh
339+
```
340+
341+
- Now a SSH key pair needs to be created on the host. This key pair will be used to authenticate the `git` user on the host to the container.
342+
343+
```bash
344+
sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key"
345+
```
346+
347+
- Please note depending on the local version of ssh you may want to consider using `-t ecdsa` here.
348+
349+
- `/home/git/.ssh/authorized_keys` on the host now needs to be modified. It needs to act in the same way as `authorized_keys` within the Gitea container. Therefore add the public key of the key you created above ("Gitea Host Key") to `~/git/.ssh/authorized_keys`.
350+
351+
```bash
352+
echo "$(cat /home/git/.ssh/id_rsa.pub)" >> /home/git/.ssh/authorized_keys
353+
```
354+
355+
Important: The pubkey from the `git` user needs to be added "as is" while all other pubkeys added via the Gitea web interface will be prefixed with `command="/usr [...]`.
356+
357+
`/home/git/.ssh/authorized_keys` should then look somewhat like
358+
359+
```bash
360+
# SSH pubkey from git user
361+
ssh-rsa <Gitea Host Key>
362+
363+
# other keys from users
364+
command="/usr/local/bin/gitea --config=/data/gitea/conf/app.ini serv key-1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty <user pubkey>
365+
```
366+
367+
- The next step is to create the file that will issue the SSH forwarding from the host to the container. The name of this file depends on your version of Gitea:
368+
369+
- For Gitea v1.16.0+:
370+
371+
```bash
372+
cat <<"EOF" | sudo tee /usr/local/bin/gitea
373+
#!/bin/sh
374+
ssh -p 2222 -o StrictHostKeyChecking=no git@127.0.0.1 "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@"
375+
EOF
376+
chmod +x /usr/local/bin/gitea
377+
```
378+
379+
- For Gitea v1.15.x and earlier
380+
381+
```bash
382+
cat <<"EOF" | sudo tee /app/gitea/gitea
383+
#!/bin/sh
384+
ssh -p 2222 -o StrictHostKeyChecking=no git@127.0.0.1 "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@"
385+
EOF
386+
sudo chmod +x /app/gitea/gitea
387+
```
388+
389+
Here is a detailed explanation what is happening when a SSH request is made:
390+
391+
1. A SSH request is made against the host (usually port 22) using the `git` user, e.g. `git clone git@domain:user/repo.git`.
392+
2. In `/home/git/.ssh/authorized_keys` , the command executes the `/usr/local/bin/gitea` script.
393+
3. `/usr/local/bin/gitea` forwards the SSH request to port 2222 which is mapped to the SSH port (ssh 22) of the container.
394+
4. Due to the existence of the public key of the `git` user in `/home/git/.ssh/authorized_keys` the authentication host → container succeeds and the SSH request get forwarded to Gitea running in the docker container.
395+
396+
If a new SSH key is added in the Gitea web interface, it will be appended to `.ssh/authorized_keys` in the same way as the already existing key.
397+
398+
**Notes**
399+
400+
SSH container passthrough using `authorized_keys` will work only if
401+
402+
- `opensshd` is used in the container
403+
- if `AuthorizedKeysCommand` is _not used_ in combination with `SSH_CREATE_AUTHORIZED_KEYS_FILE=false` to disable authorized files key generation
404+
- `LOCAL_ROOT_URL` is not changed (depending on the changes)
405+
406+
### SSHing Shell (with authorized_keys)
407+
408+
The idea of this option is to use (essentially unchanged) the authorized_keys that gitea creates on the docker and use a special shell for git user that uses ssh to shell to the docker git user.
409+
410+
- In this case we setup as above except instead of creating `/usr/local/bin/gitea` or `/app/gitea/gitea`
411+
we create a new shell for the git user:
412+
413+
```bash
414+
cat <<"EOF" | sudo tee /home/git/ssh-shell
415+
#!/bin/sh
416+
shift
417+
ssh -p 2222 -o StrictHostKeyChecking=no git@127.0.0.1 "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $@"
418+
EOF
419+
sudo chmod +x /home/git/ssh-shell
420+
sudo usermod -s /home/git/ssh-shell git
421+
```
422+
423+
Be careful here - if you try to login as the git user in future you will ssh directly to the docker.
424+
425+
Here is a detailed explanation what is happening when a SSH request is made:
332426

333-
In the next step a file named `/app/gitea/gitea` (with executable permissions) needs to be created on the host. This file will issue the SSH forwarding from the host to the container. Add the following contents to `/app/gitea/gitea`:
427+
1. A SSH request is made against the host (usually port 22) using the `git` user, e.g. `git clone git@domain:user/repo.git`.
428+
2. In `/home/git/.ssh/authorized_keys` , the command in the command portion is passed to the `ssh-shell` script
429+
3. `ssh-shell` forwards the SSH request to port 2222 overriding whi is mapped to the SSH port (ssh 22) of the container.
430+
4. Due to the existence of the public key of the `git` user in `/home/git/.ssh/authorized_keys` the authentication host → container succeeds and the SSH request get forwarded to Gitea running in the docker container.
431+
432+
If a new SSH key is added in the Gitea web interface, it will be appended to `.ssh/authorized_keys` in the same way as the already existing key.
433+
434+
**Notes**
435+
436+
SSH container passthrough using `authorized_keys` will work only if
437+
438+
- `opensshd` is used in the container
439+
- if `AuthorizedKeysCommand` is _not used_ in combination with `SSH_CREATE_AUTHORIZED_KEYS_FILE=false` to disable authorized files key generation
440+
- `LOCAL_ROOT_URL` is not changed (depending on the changes)
441+
442+
### Docker Shell (with authorized_keys)
443+
444+
Similar to the above ssh shell technique we can use a shell which simply uses `docker exec`:
334445

335446
```bash
447+
cat <<"EOF" | sudo tee /home/git/docker-shell
336448
#!/bin/sh
337-
ssh -p 2222 -o StrictHostKeyChecking=no git@127.0.0.1 "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@"
449+
/usr/bin/docker exec -i --env SSH_ORIGINAL_COMMAND="$SSH_ORIGINAL_COMMAND" gitea sh "$@"
450+
EOF
451+
sudo chmod +x /home/git/docker-shell
452+
sudo usermod -s /home/git/docker-shell git
338453
```
339454

340-
Here you should also make sure that you've set the permission of `/app/gitea/gitea` correctly:
455+
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. The `git` user also have to have
456+
permission to run `docker exec`.
457+
458+
**Notes**
459+
460+
Docker shell passthrough using `authorized_keys` will work only if
461+
462+
- `opensshd` is used in the container
463+
- if `AuthorizedKeysCommand` is _not used_ in combination with `SSH_CREATE_AUTHORIZED_KEYS_FILE=false` to disable authorized files key generation
464+
- `LOCAL_ROOT_URL` is not changed (depending on the changes)
465+
466+
A Docker execing shim could be created similarly to above.
467+
468+
### Docker Shell with AuthorizedKeysCommand
469+
470+
The AuthorizedKeysCommand route provides another option that does not require many changes to the compose file or the `authorized_keys` - but does require changes to the host `/etc/sshd_config`.
471+
472+
- On the host create called `git` with permission to run `docker exec`.
473+
- We will again assume that the Gitea container is called `gitea`.
474+
- Modify the `git` user's shell to forward commands to the `sh` executable inside the container using `docker exec` as previously described:
475+
476+
```bash
477+
cat <<"EOF" | sudo tee /home/git/docker-shell
478+
#!/bin/sh
479+
/usr/bin/docker exec -i --env SSH_ORIGINAL_COMMAND="$SSH_ORIGINAL_COMMAND" gitea sh "$@"
480+
EOF
481+
sudo chmod +x /home/git/docker-shell
482+
sudo usermod -s /home/git/docker-shell git
483+
```
484+
485+
Now all attempts to login as the `git` user will be forwarded to the docker - including the `SSH_ORIGINAL_COMMAND`. We now need to set-up SSH authenitication on the host.
486+
487+
We will do this by leveraging the [SSH AuthorizedKeysCommand](https://docs.gitea.io/en-us/command-line/#keys) to match the keys against those accepted by Gitea.
488+
489+
Add the following block to `/etc/ssh/sshd_config`, on the host:
341490

342491
```bash
343-
sudo chmod +x /app/gitea/gitea
492+
Match User git
493+
AuthorizedKeysCommandUser git
494+
AuthorizedKeysCommand /usr/bin/docker exec -i gitea /usr/local/bin/gitea keys -c /data/gitea/conf/app.ini -e git -u %u -t %t -k %k
344495
```
345496

346-
To make the forwarding work, the SSH port of the container (22) needs to be mapped to the host port 2222 in `docker-compose.yml` . Since this port does not need to be exposed to the outside world, it can be mapped to the `localhost` of the host machine:
497+
(From 1.16.0 you will not need to set the `-c /data/gitea/conf/app.ini` option.)
498+
499+
Finally restart the SSH server:
347500

348501
```bash
349-
ports:
350-
# [...]
351-
- "127.0.0.1:2222:22"
502+
sudo systemctl restart sshd
352503
```
353504

354-
In addition, `/home/git/.ssh/authorized_keys` on the host needs to be modified. It needs to act in the same way as `authorized_keys` within the Gitea container. Therefore add the public key of the key you created above ("Gitea Host Key") to `~/git/.ssh/authorized_keys`.
355-
This can be done via `echo "$(cat /home/git/.ssh/id_rsa.pub)" >> /home/git/.ssh/authorized_keys`.
356-
Important: The pubkey from the `git` user needs to be added "as is" while all other pubkeys added via the Gitea web interface will be prefixed with `command="/app [...]`.
505+
**Notes**
357506

358-
The file should then look somewhat like
507+
Docker shell passthrough using `AuthorizedKeysCommand` will work only if
359508

360-
```bash
361-
# SSH pubkey from git user
362-
ssh-rsa <Gitea Host Key>
509+
- The host `git` user is allowed to run the `docker exec` command.
510+
511+
A Docker execing shim could be created similarly to above.
512+
513+
### SSH Shell with AuthorizedKeysCommand
514+
515+
Create a key for the host `git` user as above, add it to the docker `/data/git/.ssh/authorized_keys` then finally create and set the `ssh-shell` as above.
516+
517+
Add the following block to `/etc/ssh/sshd_config`, on the host:
363518

364-
# other keys from users
365-
command="/app/gitea/gitea --config=/data/gitea/conf/app.ini serv key-1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty <user pubkey>
519+
```bash
520+
Match User git
521+
AuthorizedKeysCommandUser git
522+
AuthorizedKeysCommand ssh -p 2222 -o StrictHostKeyChecking=no git@127.0.0.1 /usr/local/bin/gitea keys -c /data/gitea/conf/app.ini -e git -u %u -t %t -k %k
366523
```
367524

368-
Here is a detailed explanation what is happening when a SSH request is made:
525+
(From 1.16.0 you will not need to set the `-c /data/gitea/conf/app.ini` option.)
369526

370-
1. A SSH request is made against the host (usually port 22) using the `git` user, e.g. `git clone git@domain:user/repo.git`.
371-
2. In `/home/git/.ssh/authorized_keys` , the command executes the `/app/gitea/gitea` script.
372-
3. `/app/gitea/gitea` forwards the SSH request to port 2222 which is mapped to the SSH port (22) of the container.
373-
4. Due to the existence of the public key of the `git` user in `/home/git/.ssh/authorized_keys` the authentication host → container succeeds and the SSH request get forwarded to Gitea running in the docker container.
527+
Finally restart the SSH server:
374528

375-
If a new SSH key is added in the Gitea web interface, it will be appended to `.ssh/authorized_keys` in the same way as the already existing key.
529+
```bash
530+
sudo systemctl restart sshd
531+
```
376532

377533
**Notes**
378534

379-
SSH container passthrough will work only if
535+
SSH container passthrough using `AuthorizedKeysCommand` will work only if
380536

381-
- `opensshd` is used in the container
382-
- if `AuthorizedKeysCommand` is _not used_ in combination with `SSH_CREATE_AUTHORIZED_KEYS_FILE=false` to disable authorized files key generation
383-
- `LOCAL_ROOT_URL` is not changed
537+
- `opensshd` is running on the container
538+
539+
SSHing shims could be created similarly to above.

docs/content/doc/usage/git-lfs-support.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ To use Gitea's built-in LFS support, you must update the `app.ini` file:
2121
[server]
2222
; Enables git-lfs support. true or false, default is false.
2323
LFS_START_SERVER = true
24+
25+
[lfs]
2426
; Where your lfs files reside, default is data/lfs.
25-
LFS_CONTENT_PATH = /home/gitea/data/lfs
27+
PATH = /home/gitea/data/lfs
2628
```
2729

2830
**Note**: LFS server support needs at least Git v2.1.2 installed on the server

integrations/git_helper_for_declarative_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
122122
}
123123
}
124124

125+
func doPartialGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
126+
return func(t *testing.T) {
127+
assert.NoError(t, git.CloneWithArgs(context.Background(), u.String(), dstLocalPath, allowLFSFilters(), git.CloneRepoOptions{
128+
Filter: "blob:none",
129+
}))
130+
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
131+
assert.NoError(t, err)
132+
assert.True(t, exist)
133+
}
134+
}
135+
125136
func doGitCloneFail(u *url.URL) func(*testing.T) {
126137
return func(t *testing.T) {
127138
tmpDir, err := os.MkdirTemp("", "doGitCloneFail")

integrations/git_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ func testGit(t *testing.T, u *url.URL) {
6969

7070
t.Run("Clone", doGitClone(dstPath, u))
7171

72+
dstPath2, err := os.MkdirTemp("", httpContext.Reponame)
73+
assert.NoError(t, err)
74+
defer util.RemoveAll(dstPath2)
75+
76+
t.Run("Partial Clone", doPartialGitClone(dstPath2, u))
77+
7278
little, big := standardCommitAndPushTest(t, dstPath)
7379
littleLFS, bigLFS := lfsCommitAndPushTest(t, dstPath)
7480
rawTest(t, &httpContext, little, big, littleLFS, bigLFS)

integrations/mssql.ini.tmpl

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ SSH_LISTEN_HOST = localhost
4545
SSH_PORT = 2201
4646
START_SSH_SERVER = true
4747
LFS_START_SERVER = true
48-
LFS_CONTENT_PATH = integrations/gitea-integration-mssql/data/lfs
4948
OFFLINE_MODE = false
5049
LFS_JWT_SECRET = Tv_MjmZuHqpIY6GFl12ebgkRAMt4RlWt0v4EHKSXO0w
5150
APP_DATA_PATH = integrations/gitea-integration-mssql/data
@@ -100,3 +99,6 @@ DISABLE_GIT_HOOKS = false
10099
INSTALL_LOCK = true
101100
SECRET_KEY = 9pCviYTWSb
102101
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ
102+
103+
[lfs]
104+
PATH = integrations/gitea-integration-mssql/data/lfs

0 commit comments

Comments
 (0)