-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathsigning.asc
More file actions
279 lines (230 loc) · 11.8 KB
/
Copy pathsigning.asc
File metadata and controls
279 lines (230 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
[[r_signing]]
//////////////////////////
=== Signing Your Work
//////////////////////////
=== 作業内容への署名
//////////////////////////
Git is cryptographically secure, but it's not foolproof.
If you're taking work from others on the internet and want to verify that commits are actually from a trusted source, Git has a few ways to sign and verify work using GPG.
//////////////////////////
Git の仕組みは暗号学の点から見れば堅牢です。しかし、容易には得られません。インターネットを使って貢献を受け付けているとしましょう。受け付けた内容が信頼できる筋からのものかどうか調べたいときに、署名の付与・検証をGPG を使っておこなう複数の仕組みが Git にはあります。
//////////////////////////
==== GPG Introduction
//////////////////////////
==== GPG とは
//////////////////////////
First of all, if you want to sign anything you need to get GPG configured and your personal key installed.
//////////////////////////
まずはじめに、何かを署名するには、GPG を設定し、個人鍵をインストールしなければなりません。
[source,console]
----
$ gpg --list-keys
/Users/schacon/.gnupg/pubring.gpg
---------------------------------
pub 2048R/0A46826A 2014-06-04
uid Scott Chacon (Git signing key) <schacon@gmail.com>
sub 2048R/874529A9 2014-06-04
----
//////////////////////////
If you don't have a key installed, you can generate one with `gpg --gen-key`.
//////////////////////////
鍵をインストールしていないのなら、`gpg --gen-key` を使って生成できます。
[source,console]
----
gpg --gen-key
----
//////////////////////////
Once you have a private key to sign with, you can configure Git to use it for signing things by setting the `user.signingkey` config setting.
//////////////////////////
署名付与用の秘密鍵ができたら、Git の設定項目 `user.signingkey` に鍵の内容を設定します。
[source,console]
----
git config --global user.signingkey 0A46826A
----
//////////////////////////
Now Git will use your key by default to sign tags and commits if you want.
//////////////////////////
こうしておけば、タグやコミットに署名を付与するとき、Git はデフォルトでこの鍵を使うようになります。
//////////////////////////
==== Signing Tags
//////////////////////////
==== タグへの署名
//////////////////////////
If you have a GPG private key setup, you can now use it to sign new tags.
All you have to do is use `-s` instead of `-a`:
//////////////////////////
GPG 秘密鍵の設定を終えていれば、その鍵を使ってタグの作成時に署名できます。
その場合は `-a` の代わりに `-s` を指定すればいいだけです。
[source,console]
----
$ git tag -s v1.5 -m 'my signed 1.5 tag'
You need a passphrase to unlock the secret key for
user: "Ben Straub <ben@straub.cc>"
2048-bit RSA key, ID 800430EB, created 2014-05-04
----
//////////////////////////
If you run `git show` on that tag, you can see your GPG signature attached to it:
//////////////////////////
このタグに対して `git show` を実行すると、あなたの GPG 署名が表示されます。
[source,console]
--------
$ git show v1.5
tag v1.5
Tagger: Ben Straub <ben@straub.cc>
Date: Sat May 3 20:29:41 2014 -0700
my signed 1.5 tag
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAABAgAGBQJTZbQlAAoJEF0+sviABDDrZbQH/09PfE51KPVPlanr6q1v4/Ut
LQxfojUWiLQdg2ESJItkcuweYg+kc3HCyFejeDIBw9dpXt00rY26p05qrpnG+85b
hM1/PswpPLuBSr+oCIDj5GMC2r2iEKsfv2fJbNW8iWAXVLoWZRF8B0MfqX/YTMbm
ecorc4iXzQu7tupRihslbNkfvfciMnSDeSvzCpWAHl7h8Wj6hhqePmLm9lAYqnKp
8S5B/1SSQuEAjRZgI4IexpZoeKGVDptPHxLLS38fozsyi0QyDyzEgJxcJQVMXxVi
RUysgqjcpT8+iQM1PblGfHR4XAhuOqN5Fx06PSaFZhqvWFezJ28/CLyX5q+oIVk=
=EFTF
-----END PGP SIGNATURE-----
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date: Mon Mar 17 21:52:11 2008 -0700
changed the version number
--------
//////////////////////////
==== Verifying Tags
//////////////////////////
==== タグの検証
//////////////////////////
To verify a signed tag, you use `git tag -v [tag-name]`.
This command uses GPG to verify the signature.
You need the signer’s public key in your keyring for this to work properly:
//////////////////////////
署名付きのタグを検証するには `git tag -v [tag-name]` を使用します。
このコマンドは、GPG を使って署名を検証します。
これを正しく実行するには、署名者の公開鍵があなたの鍵リングに含まれている必要があります。
[source,console]
----
$ git tag -v v1.4.2.1
object 883653babd8ee7ea23e6a5c392bb739348b1eb61
type commit
tag v1.4.2.1
tagger Junio C Hamano <junkio@cox.net> 1158138501 -0700
GIT 1.4.2.1
Minor fixes since 1.4.2, including git-mv and git-http with alternates.
gpg: Signature made Wed Sep 13 02:08:25 2006 PDT using DSA key ID F3119B9A
gpg: Good signature from "Junio C Hamano <junkio@cox.net>"
gpg: aka "[jpeg image of size 1513]"
Primary key fingerprint: 3565 2A26 2040 E066 C9A7 4A7D C0C6 D9A4 F311 9B9A
----
//////////////////////////
If you don’t have the signer’s public key, you get something like this instead:
//////////////////////////
署名者の公開鍵を持っていない場合は、このようなメッセージが表示されます。
[source,console]
----
gpg: Signature made Wed Sep 13 02:08:25 2006 PDT using DSA key ID F3119B9A
gpg: Can't check signature: public key not found
error: could not verify the tag 'v1.4.2.1'
----
[[r_signing_commits]]
//////////////////////////
==== Signing Commits
//////////////////////////
==== コミットへの署名
//////////////////////////
In more recent versions of Git (v1.7.9 and above), you can now also sign individual commits.
If you're interested in signing commits directly instead of just the tags, all you need to do is add a `-S` to your `git commit` command.
//////////////////////////
最近のバージョン(v1.7.9 以上)では、Git を使ってコミットに署名できるようになりました。
タグだけでなく、コミットにも署名したい場合は、`git commit` コマンドの `-S` オプションを使いましょう。
[source,console]
----
$ git commit -a -S -m 'signed commit'
You need a passphrase to unlock the secret key for
user: "Scott Chacon (Git signing key) <schacon@gmail.com>"
2048-bit RSA key, ID 0A46826A, created 2014-06-04
[master 5c3386c] signed commit
4 files changed, 4 insertions(+), 24 deletions(-)
rewrite Rakefile (100%)
create mode 100644 lib/git.rb
----
//////////////////////////
To see and verify these signatures, there is also a `--show-signature` option to `git log`.
//////////////////////////
また、署名の確認・検証を行うための `--show-signature` オプションが `git log` コマンドに用意されています。
[source,console]
----
$ git log --show-signature -1
commit 5c3386cf54bba0a33a32da706aa52bc0155503c2
gpg: Signature made Wed Jun 4 19:49:17 2014 PDT using RSA key ID 0A46826A
gpg: Good signature from "Scott Chacon (Git signing key) <schacon@gmail.com>"
Author: Scott Chacon <schacon@gmail.com>
Date: Wed Jun 4 19:49:17 2014 -0700
signed commit
----
//////////////////////////
Additionally, you can configure `git log` to check any signatures it finds and list them in its output with the `%G?` format.
//////////////////////////
さらに、`git log` コマンドに署名の有無を出力させることもできます。書式設定で `%G?` を使いましょう。
[source,console]
----
$ git log --pretty="format:%h %G? %aN %s"
5c3386c G Scott Chacon signed commit
ca82a6d N Scott Chacon changed the version number
085bb3b N Scott Chacon removed unnecessary test code
a11bef0 N Scott Chacon first commit
----
//////////////////////////
Here we can see that only the latest commit is signed and valid and the previous commits are not.
//////////////////////////
そうすれば、この例であれば最新のコミットのみが署名付き、しかもそれが有効であることがわかります。
//////////////////////////
In Git 1.8.3 and later, "git merge" and "git pull" can be told to inspect and reject when merging a commit that does not carry a trusted GPG signature with the `--verify-signatures` command.
//////////////////////////
バージョン 1.8.3 以降の Git であれば、マージやプルのときにコミットを拒否することもできます。`--verify-signatures` オプションを使うとコミットが検証され、有効な GPG 署名がない場合はマージやプルが拒否されます。
//////////////////////////
If you use this option when merging a branch and it contains commits that are not signed and valid, the merge will not work.
//////////////////////////
このオプションをブランチをマージするときに使うと、署名がない、もしくは有効でないコミットが含まれているブランチのマージは失敗します。
[source,console]
----
$ git merge --verify-signatures non-verify
fatal: Commit ab06180 does not have a GPG signature.
----
//////////////////////////
If the merge contains only valid signed commits, the merge command will show you all the signatures it has checked and then move forward with the merge.
//////////////////////////
逆に、マージ対象のコミットすべてに有効な署名が施されていれば、検証された署名がすべて表示され、マージが実行に移されます。
[source,console]
----
$ git merge --verify-signatures signed-branch
Commit 13ad65e has a good GPG signature by Scott Chacon (Git signing key) <schacon@gmail.com>
Updating 5c3386c..13ad65e
Fast-forward
README | 2 ++
1 file changed, 2 insertions(+)
----
//////////////////////////
You can also use the `-S` option with the `git merge` command itself to sign the resulting merge commit itself.
The following example both verifies that every commit in the branch to be merged is signed and furthermore signs the resulting merge commit.
//////////////////////////
また、`git merge` コマンドの `-S` オプションを使うと、マージコミットにも署名できます。以下のマージの例では、マージ対象コミットの署名を検証し、さらにマージコミットに署名を施しています。
[source,console]
----
$ git merge --verify-signatures -S signed-branch
Commit 13ad65e has a good GPG signature by Scott Chacon (Git signing key) <schacon@gmail.com>
You need a passphrase to unlock the secret key for
user: "Scott Chacon (Git signing key) <schacon@gmail.com>"
2048-bit RSA key, ID 0A46826A, created 2014-06-04
Merge made by the 'recursive' strategy.
README | 2 ++
1 file changed, 2 insertions(+)
----
//////////////////////////
==== Everyone Must Sign
//////////////////////////
==== 署名付与は全員で
//////////////////////////
Signing tags and commits is great, but if you decide to use this in your normal workflow, you'll have to make sure that everyone on your team understands how to do so.
If you don't, you'll end up spending a lot of time helping people figure out how to rewrite their commits with signed versions.
Make sure you understand GPG and the benefits of signing things before adopting this as part of your standard workflow.
//////////////////////////
タグやコミットに署名を付与するのは素晴らしい試みです。ただし、作業手順のひとつとして採用するのであれば、メンバー全員がやり方を知っているかどうか前もって確認しておくべきでしょう。そうしておかないと、作成済みコミットに署名を付与する方法を説明してまわるハメになりかねません。GPG の仕組み、署名を付与することのメリットをよく理解してから、作業手順に組み込むようにしましょう。