|
| 1 | +--- |
| 2 | +date: "2019-08-17T10:20:00+01:00" |
| 3 | +title: "GPG Commit Signatures" |
| 4 | +slug: "signing" |
| 5 | +weight: 20 |
| 6 | +toc: false |
| 7 | +draft: false |
| 8 | +menu: |
| 9 | + sidebar: |
| 10 | + parent: "advanced" |
| 11 | + name: "GPG Commit Signatures" |
| 12 | + weight: 20 |
| 13 | + identifier: "signing" |
| 14 | +--- |
| 15 | + |
| 16 | +# GPG Commit Signatures |
| 17 | + |
| 18 | +Gitea will verify GPG commit signatures in the provided tree by |
| 19 | +checking if the commits are signed by a key within the gitea database, |
| 20 | +or if the commit matches the default key for git. |
| 21 | + |
| 22 | +Keys are not checked to determine if they have expired or revoked. |
| 23 | +Keys are also not checked with keyservers. |
| 24 | + |
| 25 | +A commit will be marked with a grey unlocked icon if no key can be |
| 26 | +found to verify it. If a commit is marked with a red unlocked icon, |
| 27 | +it is reported to be signed with a key with an id. |
| 28 | + |
| 29 | +Please note: The signer of a commit does not have to be an author or |
| 30 | +committer of a commit. |
| 31 | + |
| 32 | +This functionality requires git >= 1.7.9 but for full functionality |
| 33 | +this requires git >= 2.0.0. |
| 34 | + |
| 35 | +## Automatic Signing |
| 36 | + |
| 37 | +There are a number of places where Gitea will generate commits itself: |
| 38 | + |
| 39 | +* Repository Initialisation |
| 40 | +* Wiki Changes |
| 41 | +* CRUD actions using the editor or the API |
| 42 | +* Merges from Pull Requests |
| 43 | + |
| 44 | +Depending on configuration and server trust you may want Gitea to |
| 45 | +sign these commits. |
| 46 | + |
| 47 | +## General Configuration |
| 48 | + |
| 49 | +Gitea's configuration for signing can be found with the |
| 50 | +`[repository.signing]` section of `app.ini`: |
| 51 | + |
| 52 | +```ini |
| 53 | +... |
| 54 | +[repository.signing] |
| 55 | +SIGNING_KEY = default |
| 56 | +SIGNING_NAME = |
| 57 | +SIGNING_EMAIL = |
| 58 | +INITIAL_COMMIT = always |
| 59 | +CRUD_ACTIONS = pubkey, twofa, parentsigned |
| 60 | +WIKI = never |
| 61 | +MERGES = pubkey, twofa, basesigned, commitssigned |
| 62 | + |
| 63 | +... |
| 64 | +``` |
| 65 | + |
| 66 | +### `SIGNING_KEY` |
| 67 | + |
| 68 | +The first option to discuss is the `SIGNING_KEY`. There are three main |
| 69 | +options: |
| 70 | + |
| 71 | +* `none` - this prevents Gitea from signing any commits |
| 72 | +* `default` - Gitea will default to the key configured within |
| 73 | +`git config` |
| 74 | +* `KEYID` - Gitea will sign commits with the gpg key with the ID |
| 75 | +`KEYID`. In this case you should provide a `SIGNING_NAME` and |
| 76 | +`SIGNING_EMAIL` to be displayed for this key. |
| 77 | + |
| 78 | +The `default` option will interrogate `git config` for |
| 79 | +`commit.gpgsign` option - if this is set, then it will use the results |
| 80 | +of the `user.signingkey`, `user.name` and `user.email` as appropriate. |
| 81 | + |
| 82 | +Please note: by adjusting git's `config` file within Gitea's |
| 83 | +repositories, `SIGNING_KEY=default` could be used to provide different |
| 84 | +signing keys on a per-repository basis. However, this is cleary not an |
| 85 | +ideal UI and therefore subject to change. |
| 86 | + |
| 87 | +### `INITIAL_COMMIT` |
| 88 | + |
| 89 | +This option determines whether Gitea should sign the initial commit |
| 90 | +when creating a repository. The possible values are: |
| 91 | + |
| 92 | +* `never`: Never sign |
| 93 | +* `pubkey`: Only sign if the user has a public key |
| 94 | +* `twofa`: Only sign if the user logs in with two factor authentication |
| 95 | +* `always`: Always sign |
| 96 | + |
| 97 | +Options other than `never` and `always` can be combined as a comma |
| 98 | +separated list. |
| 99 | + |
| 100 | +### `WIKI` |
| 101 | + |
| 102 | +This options determines if Gitea should sign commits to the Wiki. |
| 103 | +The possible values are: |
| 104 | + |
| 105 | +* `never`: Never sign |
| 106 | +* `pubkey`: Only sign if the user has a public key |
| 107 | +* `twofa`: Only sign if the user logs in with two factor authentication |
| 108 | +* `parentsigned`: Only sign if the parent commit is signed. |
| 109 | +* `always`: Always sign |
| 110 | + |
| 111 | +Options other than `never` and `always` can be combined as a comma |
| 112 | +separated list. |
| 113 | + |
| 114 | +### `CRUD_ACTIONS` |
| 115 | + |
| 116 | +This option determines if Gitea should sign commits from the web |
| 117 | +editor or API CRUD actions. The possible values are: |
| 118 | + |
| 119 | +* `never`: Never sign |
| 120 | +* `pubkey`: Only sign if the user has a public key |
| 121 | +* `twofa`: Only sign if the user logs in with two factor authentication |
| 122 | +* `parentsigned`: Only sign if the parent commit is signed. |
| 123 | +* `always`: Always sign |
| 124 | + |
| 125 | +Options other than `never` and `always` can be combined as a comma |
| 126 | +separated list. |
| 127 | + |
| 128 | +### `MERGES` |
| 129 | + |
| 130 | +This option determines if Gitea should sign merge commits from PRs. |
| 131 | +The possible options are: |
| 132 | + |
| 133 | +* `never`: Never sign |
| 134 | +* `pubkey`: Only sign if the user has a public key |
| 135 | +* `twofa`: Only sign if the user logs in with two factor authentication |
| 136 | +* `basesigned`: Only sign if the parent commit in the base repo is signed. |
| 137 | +* `headsigned`: Only sign if the head commit in the head branch is signed. |
| 138 | +* `commitssigned`: Only sign if all the commits in the head branch to the merge point are signed. |
| 139 | +* `always`: Always sign |
| 140 | + |
| 141 | +Options other than `never` and `always` can be combined as a comma |
| 142 | +separated list. |
| 143 | + |
| 144 | +## Installing and generating a GPG key for Gitea |
| 145 | + |
| 146 | +It is up to a server administrator to determine how best to install |
| 147 | +a signing key. Gitea generates all its commits using the server `git` |
| 148 | +command at present - and therefore the server `gpg` will be used for |
| 149 | +signing (if configured.) Administrators should review best-practices |
| 150 | +for gpg - in particular it is probably advisable to only install a |
| 151 | +signing secret subkey without the master signing and certifying secret |
| 152 | +key. |
| 153 | + |
| 154 | +## Obtaining the Public Key of the Signing Key |
| 155 | + |
| 156 | +The public key used to sign Gitea's commits can be obtained from the API at: |
| 157 | + |
| 158 | +```/api/v1/signing-key.gpg``` |
| 159 | + |
| 160 | +In cases where there is a repository specific key this can be obtained from: |
| 161 | + |
| 162 | +```/api/v1/repos/:username/:reponame/signing-key.gpg``` |
0 commit comments