Skip to content

Improve instance wide ssh commit signing #34341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ChristopherHX
Copy link
Contributor

@ChristopherHX ChristopherHX commented May 2, 2025

  • Signed SSH commits can look in the UI like on GitHub, just like gpg keys today in Gitea
  • No user account of the SIGNING_EMAIL required anymore to get the verified badge
  • SSH format can be added in gitea config
  • No gitconfig changes needed
  • Set gpg.format git key for signing command
  • Previously only the default gpg key had global trust in Gitea
    • SSH Signing worked before with DEFAULT_TRUST_MODEL=committer, but not with model default and manually changing the .gitconfig

e.g. the following is all needed after ssh-keygen, no trouble with installing and setting up gpg or hacking around a hidden .gitconfig for ssh key usage

[repository.signing]
SIGNING_KEY = /data/id_ed25519.pub
SIGNING_NAME = Gitea
SIGNING_EMAIL = [email protected]
SIGNING_FORMAT = ssh
INITIAL_COMMIT = always
CRUD_ACTIONS = always
WIKI = always
MERGES = always

Where /data/id_ed25519 is the private key.

TRUSTED_SSH_KEYS can be a list of additional ssh public key contents to trust for every user of this instance

Closes #34329
Related #31392

* Signed SSH commits can look like on GitHub
* No user account of the committer needed
* SSH format can be added in gitea config
* No gitconfig changes needed
* Set gpg.format git key for signing command
* Previously only the default gpg key had global trust in Gitea
  * SSH Signing worked before with DEFAULT_TRUST_MODEL=committer, but not with model default and manually changing the .gitconfig

e.g. the following is all needed
```
[repository.signing]
SIGNING_KEY = /data/id_ed25519.pub
SIGNING_NAME = Gitea
SIGNING_EMAIL = [email protected]
SIGNING_FORMAT = ssh
INITIAL_COMMIT = always
CRUD_ACTIONS = always
WIKI = always
MERGES = always
```

`TRUSTED_SSH_KEYS` can be a list of additional ssh public keys to trust for every user of this instance
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 2, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels May 2, 2025
@ChristopherHX
Copy link
Contributor Author

ChristopherHX commented May 2, 2025

What do you think @brtwrst about this?

Except of an absent automatic setup this should now be even easier, by just editing a single file.

I found out that gpg supported global key verification for all users, but ssh not, this PR aims to change that.

No I have no idea how to write tests for this

@brtwrst
Copy link

brtwrst commented May 2, 2025

That looks awesome. Makes it super simple to set up and the TRUSTED_SSH_KEYS allows for "key rotation" without losing the green checkmark on older commits. How should TRUSTED_SSH_KEYS look in the app.ini?
Like this?
TRUSTED_SSH_KEYS="ssh-ed25519 AAAA... user1@hostname", "ssh-ed25519 AAAA... user2@hostname"
Or should it be a path to a file that includes the trusted public keys?

@ChristopherHX
Copy link
Contributor Author

I tested this like this TRUSTED_SSH_KEYS = ssh-ed25519 AAAA... and should support comma like other array like ini options.

Since the ssh keys are so simple idk if a double quote are even needed / supported.

File paths are not supported in this PR for this list.

@brtwrst
Copy link

brtwrst commented May 2, 2025

Ok, can't wait for this to make it in :)

Thank you for your work.

@lunny lunny added this to the 1.25.0 milestone May 3, 2025
@lunny lunny added the type/enhancement An improvement of existing functionality label May 3, 2025
@lunny
Copy link
Member

lunny commented May 11, 2025

app.example.ini needs to be updated.

@github-actions github-actions bot added the docs-update-needed The document needs to be updated synchronously label May 11, 2025
@wxiaoguang wxiaoguang self-assigned this Jun 7, 2025
@wxiaoguang wxiaoguang marked this pull request as draft June 10, 2025 17:43
@wxiaoguang
Copy link
Contributor

Made some changes in c771cd6 and reverted unnecessary test changes.

I have some new questions and left some FIXMEs in code.

@wxiaoguang wxiaoguang removed their assignment Jun 10, 2025
@wxiaoguang
Copy link
Contributor

I made some new changes and added some comments, does it look good to you? If it looks good, let's merge ~

@wxiaoguang wxiaoguang marked this pull request as ready for review June 11, 2025 09:56
@ChristopherHX
Copy link
Contributor Author

Looks good for me now, updated the default openpgp value reference with your rename and removed the lint error

@wxiaoguang wxiaoguang enabled auto-merge (squash) June 11, 2025 10:07
@wxiaoguang wxiaoguang added type/feature Completely new functionality. Can only be merged if feature freeze is not active. and removed type/enhancement An improvement of existing functionality labels Jun 11, 2025
@wxiaoguang wxiaoguang merged commit c9505a2 into go-gitea:main Jun 11, 2025
26 checks passed
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jun 13, 2025
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  Improve the performance when detecting the file editable (go-gitea#34653)
  Fix various problems (go-gitea#34708)
  Refactor embedded assets and drop unnecessary dependencies (go-gitea#34692)
  Bump minimum go version to 1.24.4 (go-gitea#34699)
  Update JS deps (go-gitea#34701)
  Fix markdown wrap (go-gitea#34697)
  [skip ci] Updated translations via Crowdin
  frontport changelog (go-gitea#34689)
  Improve instance wide ssh commit signing (go-gitea#34341)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-update-needed The document needs to be updated synchronously lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow SSH key to be used for commit signatures
8 participants