[FEAT] Allow pushmirror to use publickey authentication

- Continuation of https://github.com/go-gitea/gitea/pull/18835 (by
@Gusted, so it's fine to change copyright holder to Forgejo).
- Add the option to use SSH for push mirrors, this would allow for the
deploy keys feature to be used and not require tokens to be used which
cannot be limited to a specific repository. The private key is stored
encrypted (via the `keying` module) on the database and NEVER given to
the user, to avoid accidental exposure and misuse.
- CAVEAT: This does require the `ssh` binary to be present, which may
not be available in containerized environments, this could be solved by
adding a SSH client into forgejo itself and use the forgejo binary as
SSH command, but should be done in another PR.
- CAVEAT: Mirroring of LFS content is not supported, this would require
the previous stated problem to be solved due to LFS authentication (an
attempt was made at forgejo/forgejo#2544).
- Integration test added.
- Resolves #4416
This commit is contained in:
Philip Peterson 2024-08-04 14:46:05 -04:00 committed by Gusted
parent 61e018f8b4
commit 03508b33a8
No known key found for this signature in database
GPG key ID: FD821B732837125F
24 changed files with 648 additions and 66 deletions

View file

@ -136,6 +136,7 @@
<th class="tw-w-2/5">{{ctx.Locale.Tr "repo.settings.mirror_settings.mirrored_repository"}}</th>
<th>{{ctx.Locale.Tr "repo.settings.mirror_settings.direction"}}</th>
<th>{{ctx.Locale.Tr "repo.settings.mirror_settings.last_update"}}</th>
<th>{{ctx.Locale.Tr "repo.mirror_public_key"}}</th>
<th></th>
</tr>
</thead>
@ -233,6 +234,7 @@
<th class="tw-w-2/5">{{ctx.Locale.Tr "repo.settings.mirror_settings.pushed_repository"}}</th>
<th>{{ctx.Locale.Tr "repo.settings.mirror_settings.direction"}}</th>
<th>{{ctx.Locale.Tr "repo.settings.mirror_settings.last_update"}}</th>
<th>{{ctx.Locale.Tr "repo.mirror_public_key"}}</th>
<th></th>
</tr>
</thead>
@ -242,7 +244,8 @@
<td class="tw-break-anywhere">{{.RemoteAddress}}</td>
<td>{{ctx.Locale.Tr "repo.settings.mirror_settings.direction.push"}}</td>
<td>{{if .LastUpdateUnix}}{{DateTime "full" .LastUpdateUnix}}{{else}}{{ctx.Locale.Tr "never"}}{{end}} {{if .LastError}}<div class="ui red label" data-tooltip-content="{{.LastError}}">{{ctx.Locale.Tr "error"}}</div>{{end}}</td>
<td class="right aligned">
<td>{{if not (eq (len .GetPublicKey) 0)}}<a data-clipboard-text="{{.GetPublicKey}}">{{ctx.Locale.Tr "repo.settings.mirror_settings.push_mirror.copy_public_key"}}</a>{{else}}{{ctx.Locale.Tr "repo.settings.mirror_settings.push_mirror.none"}}{{end}}</td>
<td class="right aligned df">
<button
class="ui tiny button show-modal"
data-modal="#push-mirror-edit-modal"
@ -274,7 +277,7 @@
{{end}}
{{if (not .DisableNewPushMirrors)}}
<tr>
<td colspan="4">
<td colspan="5">
<form class="ui form" method="post">
{{template "base/disable_form_autofill"}}
{{.CsrfTokenHtml}}
@ -297,6 +300,13 @@
<label for="push_mirror_password">{{ctx.Locale.Tr "password"}}</label>
<input id="push_mirror_password" name="push_mirror_password" type="password" value="{{.push_mirror_password}}" autocomplete="off">
</div>
<div class="inline field {{if .Err_PushMirrorUseSSH}}error{{end}}">
<div class="ui checkbox df ac">
<input id="push_mirror_use_ssh" name="push_mirror_use_ssh" type="checkbox" {{if .push_mirror_use_ssh}}checked{{end}}>
<label for="push_mirror_use_ssh" class="inline">{{ctx.Locale.Tr "repo.mirror_use_ssh.text"}}</label>
<span class="help tw-block">{{ctx.Locale.Tr "repo.mirror_use_ssh.helper"}}
</div>
</div>
</div>
</details>
<div class="field">

View file

@ -21529,6 +21529,10 @@
"sync_on_commit": {
"type": "boolean",
"x-go-name": "SyncOnCommit"
},
"use_ssh": {
"type": "boolean",
"x-go-name": "UseSSH"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
@ -25325,6 +25329,10 @@
"format": "date-time",
"x-go-name": "LastUpdateUnix"
},
"public_key": {
"type": "string",
"x-go-name": "PublicKey"
},
"remote_address": {
"type": "string",
"x-go-name": "RemoteAddress"