1.. SPDX-License-Identifier: GPL-2.0 2 3.. _pgpguide: 4 5=========================== 6Kernel Maintainer PGP guide 7=========================== 8 9:Author: Konstantin Ryabitsev <konstantin@linuxfoundation.org> 10 11This document is aimed at Linux kernel developers, and especially at 12subsystem maintainers. It contains a subset of information discussed in 13the more general "`Protecting Code Integrity`_" guide published by the 14Linux Foundation. Please read that document for more in-depth discussion 15on some of the topics mentioned in this guide. 16 17.. _`Protecting Code Integrity`: https://github.com/lfit/itpol/blob/master/protecting-code-integrity.md 18 19The role of PGP in Linux Kernel development 20=========================================== 21 22PGP helps ensure the integrity of the code that is produced by the Linux 23kernel development community and, to a lesser degree, establish trusted 24communication channels between developers via PGP-signed email exchange. 25 26The Linux kernel source code is available in two main formats: 27 28- Distributed source repositories (git) 29- Periodic release snapshots (tarballs) 30 31Both git repositories and tarballs carry PGP signatures of the kernel 32developers who create official kernel releases. These signatures offer a 33cryptographic guarantee that downloadable versions made available via 34kernel.org or any other mirrors are identical to what these developers 35have on their workstations. To this end: 36 37- git repositories provide PGP signatures on all tags 38- tarballs provide detached PGP signatures with all downloads 39 40.. _devs_not_infra: 41 42Trusting the developers, not infrastructure 43------------------------------------------- 44 45Ever since the 2011 compromise of core kernel.org systems, the main 46operating principle of the Kernel Archives project has been to assume 47that any part of the infrastructure can be compromised at any time. For 48this reason, the administrators have taken deliberate steps to emphasize 49that trust must always be placed with developers and never with the code 50hosting infrastructure, regardless of how good the security practices 51for the latter may be. 52 53The above guiding principle is the reason why this guide is needed. We 54want to make sure that by placing trust into developers we do not merely 55shift the blame for potential future security incidents to someone else. 56The goal is to provide a set of guidelines developers can use to create 57a secure working environment and safeguard the PGP keys used to 58establish the integrity of the Linux kernel itself. 59 60.. _pgp_tools: 61 62PGP tools 63========= 64 65Use GnuPG 2.4 or later 66---------------------- 67 68Your distro should already have GnuPG installed by default, you just 69need to verify that you are using a reasonably recent version of it. 70To check, run:: 71 72 $ gpg --version | head -n1 73 74If you have version 2.4 or above, then you are good to go. If you have 75an earlier version, then you are using a release of GnuPG that is no 76longer maintained and some commands from this guide may not work. 77 78Configure gpg-agent options 79~~~~~~~~~~~~~~~~~~~~~~~~~~~ 80 81The GnuPG agent is a helper tool that will start automatically whenever 82you use the ``gpg`` command and run in the background with the purpose 83of caching the private key passphrase. There are two options you should 84know in order to tweak when the passphrase should be expired from cache: 85 86- ``default-cache-ttl`` (seconds): If you use the same key again before 87 the time-to-live expires, the countdown will reset for another period. 88 The default is 600 (10 minutes). 89- ``max-cache-ttl`` (seconds): Regardless of how recently you've used 90 the key since initial passphrase entry, if the maximum time-to-live 91 countdown expires, you'll have to enter the passphrase again. The 92 default is 30 minutes. 93 94If you find either of these defaults too short (or too long), you can 95edit your ``~/.gnupg/gpg-agent.conf`` file to set your own values:: 96 97 # set to 30 minutes for regular ttl, and 2 hours for max ttl 98 default-cache-ttl 1800 99 max-cache-ttl 7200 100 101.. note:: 102 103 It is no longer necessary to start gpg-agent manually at the 104 beginning of your shell session. You may want to check your rc files 105 to remove anything you had in place for older versions of GnuPG, as 106 it may not be doing the right thing any more. 107 108.. _protect_your_key: 109 110Protect your PGP key 111==================== 112 113This guide assumes that you already have a PGP key that you use for Linux 114kernel development purposes. If you do not yet have one, please see the 115"`Protecting Code Integrity`_" document mentioned earlier for guidance 116on how to create a new one. 117 118You should also make a new key if your current one is weaker than 2048 119bits (RSA). 120 121Understanding PGP Subkeys 122------------------------- 123 124A PGP key rarely consists of a single keypair -- usually it is a 125collection of independent subkeys that can be used for different 126purposes based on their capabilities, assigned at their creation time. 127PGP defines four capabilities that a key can have: 128 129- **[S]** keys can be used for signing 130- **[E]** keys can be used for encryption 131- **[A]** keys can be used for authentication 132- **[C]** keys can be used for certifying other keys 133 134The key with the **[C]** capability is often called the "master" key, 135but this terminology is misleading because it implies that the Certify 136key can be used in place of any of other subkey on the same chain (like 137a physical "master key" can be used to open locks made for other keys). 138Since this is not the case, this guide will refer to it as "the Certify 139key" to avoid any ambiguity. 140 141It is critical to fully understand the following: 142 1431. All subkeys are fully independent from each other. If you lose a 144 private subkey, it cannot be restored or recreated from any other 145 private key on your chain. 1462. With the exception of the Certify key, there can be multiple subkeys 147 with identical capabilities (e.g. you can have 2 valid encryption 148 subkeys, 3 valid signing subkeys, but only one valid certification 149 subkey). All subkeys are fully independent -- a message encrypted to 150 one **[E]** subkey cannot be decrypted with any other **[E]** subkey 151 you may also have. 1523. A single subkey may have multiple capabilities (e.g. your **[C]** key 153 can also be your **[S]** key). 154 155The key carrying the **[C]** (certify) capability is the only key that 156can be used to indicate relationship with other keys. Only the **[C]** 157key can be used to: 158 159- add or revoke other keys (subkeys) with S/E/A capabilities 160- add, change or revoke identities (uids) associated with the key 161- add or change the expiration date on itself or any subkey 162- sign other people's keys for web of trust purposes 163 164By default, GnuPG creates the following when generating new keys: 165 166- One subkey carrying both Certify and Sign capabilities (**[SC]**) 167- A separate subkey with the Encryption capability (**[E]**) 168 169If you used the default parameters when generating your key, then that 170is what you will have. You can verify by running ``gpg --list-secret-keys``, 171for example:: 172 173 sec ed25519 2022-12-20 [SC] [expires: 2024-12-19] 174 000000000000000000000000AAAABBBBCCCCDDDD 175 uid [ultimate] Alice Dev <adev@kernel.org> 176 ssb cv25519 2022-12-20 [E] [expires: 2024-12-19] 177 178The long line under the ``sec`` entry is your key fingerprint -- 179whenever you see ``[fpr]`` in the examples below, that 40-character 180string is what it refers to. 181 182Ensure your passphrase is strong 183-------------------------------- 184 185GnuPG uses passphrases to encrypt your private keys before storing them on 186disk. This way, even if your ``.gnupg`` directory is leaked or stolen in 187its entirety, the attackers cannot use your private keys without first 188obtaining the passphrase to decrypt them. 189 190It is absolutely essential that your private keys are protected by a 191strong passphrase. To set it or change it, use:: 192 193 $ gpg --change-passphrase [fpr] 194 195Create a separate Signing subkey 196-------------------------------- 197 198Our goal is to protect your Certify key by moving it to offline media, 199so if you only have a combined **[SC]** key, then you should create a 200separate signing subkey:: 201 202 $ gpg --quick-addkey [fpr] ed25519 sign 203 204Back up your Certify key for disaster recovery 205---------------------------------------------- 206 207The more signatures you have on your PGP key from other developers, the 208more reasons you have to create a backup version that lives on something 209other than digital media, for disaster recovery reasons. 210 211A good way to create a printable hardcopy of your private key is by 212using the ``paperkey`` software written for this very purpose. See ``man 213paperkey`` for more details on the output format and its benefits over 214other solutions. Paperkey should already be packaged for most 215distributions. 216 217Run the following command to create a hardcopy backup of your private 218key:: 219 220 $ gpg --export-secret-key [fpr] | paperkey -o /tmp/key-backup.txt 221 222Print out that file, then take a pen and write your passphrase on the 223margin of the paper. **This is strongly recommended** because the key 224printout is still encrypted with that passphrase, and if you ever change 225it you will not remember what it used to be when you had created the 226backup -- *guaranteed*. 227 228Put the resulting printout and the hand-written passphrase into an envelope 229and store in a secure and well-protected place, preferably away from your 230home, such as your bank vault. 231 232.. note:: 233 234 The key is still encrypted with your passphrase, so printing out 235 even to "cloud-integrated" modern printers should remain a 236 relatively safe operation. 237 238Back up your whole GnuPG directory 239---------------------------------- 240 241.. warning:: 242 243 **!!!Do not skip this step!!!** 244 245It is important to have a readily available backup of your PGP keys 246should you need to recover them. This is different from the 247disaster-level preparedness we did with ``paperkey``. You will also rely 248on these external copies whenever you need to use your Certify key -- 249such as when making changes to your own key or signing other people's 250keys after conferences and summits. 251 252Start by getting an external media card (preferably two!) that you will 253use for backup purposes. You will need to create an encrypted partition 254on this device using LUKS -- refer to your distro's documentation on how 255to accomplish this. 256 257For the encryption passphrase, you can use the same one as on your 258PGP key. 259 260Once the encryption process is over, re-insert your device and make sure 261it gets properly mounted. Copy your entire ``.gnupg`` directory over to 262the encrypted storage:: 263 264 $ cp -a ~/.gnupg /media/disk/foo/gnupg-backup 265 266You should now test to make sure everything still works:: 267 268 $ gpg --homedir=/media/disk/foo/gnupg-backup --list-key [fpr] 269 270If you don't get any errors, then you should be good to go. Unmount the 271device, distinctly label it so you don't overwrite it by accident, and 272put in a safe place -- but not too far away, because you'll need to use 273it every now and again for things like editing identities, adding or 274revoking subkeys, or signing other people's keys. 275 276Remove the Certify key from your homedir 277---------------------------------------- 278 279The files in our home directory are not as well protected as we like to 280think. They can be leaked or stolen via many different means: 281 282- by accident when making quick homedir copies to set up a new workstation 283- by systems administrator negligence or malice 284- via poorly secured backups 285- via malware in desktop apps (browsers, pdf viewers, etc) 286- via coercion when crossing international borders 287 288Protecting your key with a good passphrase greatly helps reduce the risk 289of any of the above, but passphrases can be discovered via keyloggers, 290shoulder-surfing, or any number of other means. For this reason, the 291recommended setup is to remove your Certify key from your home directory 292and store it on offline storage. 293 294.. warning:: 295 296 Please see the previous section and make sure you have backed up 297 your GnuPG directory in its entirety. What we are about to do will 298 render your key useless if you do not have a usable backup! 299 300First, identify the "keygrip" of your Certify key:: 301 302 $ gpg --with-keygrip --list-key [fpr] 303 304The output will be something like this:: 305 306 pub ed25519 2022-12-20 [SC] [expires: 2022-12-19] 307 000000000000000000000000AAAABBBBCCCCDDDD 308 Keygrip = 1111000000000000000000000000000000000000 309 uid [ultimate] Alice Dev <adev@kernel.org> 310 sub cv25519 2022-12-20 [E] [expires: 2022-12-19] 311 Keygrip = 2222000000000000000000000000000000000000 312 sub ed25519 2022-12-20 [S] 313 Keygrip = 3333000000000000000000000000000000000000 314 315Find the keygrip entry that is beneath the ``pub`` line (right under the 316Certify key fingerprint). This will correspond directly to a file in your 317``~/.gnupg`` directory:: 318 319 $ cd ~/.gnupg/private-keys-v1.d 320 $ ls 321 1111000000000000000000000000000000000000.key 322 2222000000000000000000000000000000000000.key 323 3333000000000000000000000000000000000000.key 324 325It is sufficient to remove the .key file that corresponds to the Certify 326key keygrip:: 327 328 $ cd ~/.gnupg/private-keys-v1.d 329 $ rm 1111000000000000000000000000000000000000.key 330 331Now, if you issue the ``--list-secret-keys`` command, it will show that 332the Certify key is missing (the ``#`` indicates it is not available):: 333 334 $ gpg --list-secret-keys 335 sec# ed25519 2022-12-20 [SC] [expires: 2024-12-19] 336 000000000000000000000000AAAABBBBCCCCDDDD 337 uid [ultimate] Alice Dev <adev@kernel.org> 338 ssb cv25519 2022-12-20 [E] [expires: 2024-12-19] 339 ssb ed25519 2022-12-20 [S] 340 341You should also remove any ``secring.gpg`` files in the ``~/.gnupg`` 342directory, which may be left over from previous versions of GnuPG. 343 344If you don't have the "private-keys-v1.d" directory 345~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 346 347If you do not have a ``~/.gnupg/private-keys-v1.d`` directory, then your 348secret keys are still stored in the legacy ``secring.gpg`` file used by 349GnuPG v1. Making any changes to your key, such as changing the 350passphrase or adding a subkey, should automatically convert the old 351``secring.gpg`` format to use ``private-keys-v1.d`` instead. 352 353Once you get that done, make sure to delete the obsolete ``secring.gpg`` 354file, which still contains your private keys. 355 356.. _smartcards: 357 358Move the subkeys to a dedicated crypto device 359============================================= 360 361Even though the Certify key is now safe from being leaked or stolen, the 362subkeys are still in your home directory. Anyone who manages to get 363their hands on those will be able to decrypt your communication or fake 364your signatures (if they know the passphrase). Furthermore, each time a 365GnuPG operation is performed, the keys are loaded into system memory and 366can be stolen from there by sufficiently advanced malware (think 367Meltdown and Spectre). 368 369A good way to completely protect your keys is to move them to a 370specialized hardware device that is capable of smartcard operations. 371 372The benefits of smartcards 373-------------------------- 374 375A smartcard contains a cryptographic chip that is capable of storing 376private keys and performing crypto operations directly on the card 377itself. Because the key contents never leave the smartcard, the 378operating system of the computer into which you plug in the hardware 379device is not able to retrieve the private keys themselves. This is very 380different from the encrypted media storage device we used earlier for 381backup purposes -- while that device is plugged in and mounted, the 382operating system is able to access the private key contents. 383 384Using external encrypted media is not a substitute to having a 385smartcard-capable device. 386 387Available smartcard devices 388--------------------------- 389 390Unless all your laptops and workstations have smartcard readers, the 391easiest is to get a specialized USB device that implements smartcard 392functionality. There are several options available: 393 394- `Nitrokey Start`_: Open hardware and Free Software, based on FSI 395 Japan's `Gnuk`_. One of the cheapest options, but offers fewest 396 security features (such as resistance to tampering or some 397 side-channel attacks). 398- `Nitrokey 3`_: Similar to the Nitrokey Start, but more 399 tamper-resistant and offers more security features and USB 400 form-factors. Supports ECC cryptography (ED25519 and NISTP). 401- `Yubikey 5`_: proprietary hardware and software, but cheaper than 402 Nitrokey with a similar set of features. Supports ECC cryptography 403 (ED25519 and NISTP). 404 405Your choice will depend on cost, shipping availability in your 406geographical region, and open/proprietary hardware considerations. 407 408.. note:: 409 410 If you are listed in an `M:` entry in MAINTAINERS or have an account at 411 kernel.org, you `qualify for a free Nitrokey Start`_ courtesy of The Linux 412 Foundation. 413 414.. _`Nitrokey Start`: https://www.nitrokey.com/products/nitrokeys 415.. _`Nitrokey 3`: https://www.nitrokey.com/products/nitrokeys 416.. _`Yubikey 5`: https://www.yubico.com/products/yubikey-5-overview/ 417.. _Gnuk: https://www.fsij.org/doc-gnuk/ 418.. _`qualify for a free Nitrokey Start`: https://www.kernel.org/nitrokey-digital-tokens-for-kernel-developers.html 419 420Configure your smartcard device 421------------------------------- 422 423Your smartcard device should Just Work (TM) the moment you plug it into 424any modern Linux workstation. You can verify it by running:: 425 426 $ gpg --card-status 427 428If you see full smartcard details, then you are good to go. 429Unfortunately, troubleshooting all possible reasons why things may not 430be working for you is way beyond the scope of this guide. If you are 431having trouble getting the card to work with GnuPG, please seek help via 432usual support channels. 433 434To configure your smartcard, you will need to use the GnuPG menu system, as 435there are no convenient command-line switches:: 436 437 $ gpg --card-edit 438 [...omitted...] 439 gpg/card> admin 440 Admin commands are allowed 441 gpg/card> passwd 442 443You should set the user PIN (1), Admin PIN (3), and the Reset Code (4). 444Please make sure to record and store these in a safe place -- especially 445the Admin PIN and the Reset Code (which allows you to completely wipe 446the smartcard). You so rarely need to use the Admin PIN, that you will 447inevitably forget what it is if you do not record it. 448 449Getting back to the main card menu, you can also set other values (such 450as name, gender, login data, etc), but it's not necessary and will 451additionally leak information about your smartcard should you lose it. 452 453.. note:: 454 455 Despite having the name "PIN", neither the user PIN nor the admin 456 PIN on the card need to be numbers. 457 458.. warning:: 459 460 Some devices may require that you move the subkeys onto the device 461 before you can change the passphrase. Please check the documentation 462 provided by the device manufacturer. 463 464Move the subkeys to your smartcard 465---------------------------------- 466 467Exit the card menu (using "q") and save all changes. Next, let's move 468your subkeys onto the smartcard. You will need both your PGP key 469passphrase and the admin PIN of the card for most operations:: 470 471 $ gpg --edit-key [fpr] 472 473 Secret subkeys are available. 474 475 pub ed25519/AAAABBBBCCCCDDDD 476 created: 2022-12-20 expires: 2024-12-19 usage: SC 477 trust: ultimate validity: ultimate 478 ssb cv25519/1111222233334444 479 created: 2022-12-20 expires: never usage: E 480 ssb ed25519/5555666677778888 481 created: 2017-12-07 expires: never usage: S 482 [ultimate] (1). Alice Dev <adev@kernel.org> 483 484 gpg> 485 486Using ``--edit-key`` puts us into the menu mode again, and you will 487notice that the key listing is a little different. From here on, all 488commands are done from inside this menu mode, as indicated by ``gpg>``. 489 490First, let's select the key we'll be putting onto the card -- you do 491this by typing ``key 1`` (it's the first one in the listing, the **[E]** 492subkey):: 493 494 gpg> key 1 495 496In the output, you should now see ``ssb*`` on the **[E]** key. The ``*`` 497indicates which key is currently "selected." It works as a *toggle*, 498meaning that if you type ``key 1`` again, the ``*`` will disappear and 499the key will not be selected any more. 500 501Now, let's move that key onto the smartcard:: 502 503 gpg> keytocard 504 Please select where to store the key: 505 (2) Encryption key 506 Your selection? 2 507 508Since it's our **[E]** key, it makes sense to put it into the Encryption 509slot. When you submit your selection, you will be prompted first for 510your PGP key passphrase, and then for the admin PIN. If the command 511returns without an error, your key has been moved. 512 513**Important**: Now type ``key 1`` again to unselect the first key, and 514``key 2`` to select the **[S]** key:: 515 516 gpg> key 1 517 gpg> key 2 518 gpg> keytocard 519 Please select where to store the key: 520 (1) Signature key 521 (3) Authentication key 522 Your selection? 1 523 524You can use the **[S]** key both for Signature and Authentication, but 525we want to make sure it's in the Signature slot, so choose (1). Once 526again, if your command returns without an error, then the operation was 527successful:: 528 529 gpg> q 530 Save changes? (y/N) y 531 532Saving the changes will delete the keys you moved to the card from your 533home directory (but it's okay, because we have them in our backups 534should we need to do this again for a replacement smartcard). 535 536Verifying that the keys were moved 537~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 538 539If you perform ``--list-secret-keys`` now, you will see a subtle 540difference in the output:: 541 542 $ gpg --list-secret-keys 543 sec# ed25519 2022-12-20 [SC] [expires: 2024-12-19] 544 000000000000000000000000AAAABBBBCCCCDDDD 545 uid [ultimate] Alice Dev <adev@kernel.org> 546 ssb> cv25519 2022-12-20 [E] [expires: 2024-12-19] 547 ssb> ed25519 2022-12-20 [S] 548 549The ``>`` in the ``ssb>`` output indicates that the subkey is only 550available on the smartcard. If you go back into your secret keys 551directory and look at the contents there, you will notice that the 552``.key`` files there have been replaced with stubs:: 553 554 $ cd ~/.gnupg/private-keys-v1.d 555 $ strings *.key | grep 'private-key' 556 557The output should contain ``shadowed-private-key`` to indicate that 558these files are only stubs and the actual content is on the smartcard. 559 560Verifying that the smartcard is functioning 561~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 562 563To verify that the smartcard is working as intended, you can create a 564signature:: 565 566 $ echo "Hello world" | gpg --clearsign > /tmp/test.asc 567 $ gpg --verify /tmp/test.asc 568 569This should ask for your smartcard PIN on your first command, and then 570show "Good signature" after you run ``gpg --verify``. 571 572Congratulations, you have successfully made it extremely difficult to 573steal your digital developer identity! 574 575Other common GnuPG operations 576----------------------------- 577 578Here is a quick reference for some common operations you'll need to do 579with your PGP key. 580 581Mounting your safe offline storage 582~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 583 584You will need your Certify key for any of the operations below, so you 585will first need to mount your backup offline storage and tell GnuPG to 586use it:: 587 588 $ export GNUPGHOME=/media/disk/foo/gnupg-backup 589 $ gpg --list-secret-keys 590 591You want to make sure that you see ``sec`` and not ``sec#`` in the 592output (the ``#`` means the key is not available and you're still using 593your regular home directory location). 594 595Extending key expiration date 596~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 597 598The Certify key has the default expiration date of 2 years from the date 599of creation. This is done both for security reasons and to make obsolete 600keys eventually disappear from keyservers. 601 602To extend the expiration on your key by a year from current date, just 603run:: 604 605 $ gpg --quick-set-expire [fpr] 1y 606 607You can also use a specific date if that is easier to remember (e.g. 608your birthday, January 1st, or Canada Day):: 609 610 $ gpg --quick-set-expire [fpr] 2038-07-01 611 612Remember to send the updated key back to keyservers:: 613 614 $ gpg --send-key [fpr] 615 616Updating your work directory after any changes 617~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 618 619After you make any changes to your key using the offline storage, you will 620want to import these changes back into your regular working directory:: 621 622 $ gpg --export | gpg --homedir ~/.gnupg --import 623 $ unset GNUPGHOME 624 625Using gpg-agent over ssh 626~~~~~~~~~~~~~~~~~~~~~~~~ 627 628You can forward your gpg-agent over ssh if you need to sign tags or 629commits on a remote system. Please refer to the instructions provided 630on the GnuPG wiki: 631 632- `Agent Forwarding over SSH`_ 633 634It works more smoothly if you can modify the sshd server settings on the 635remote end. 636 637.. _`Agent Forwarding over SSH`: https://wiki.gnupg.org/AgentForwarding 638 639.. _pgp_with_git: 640 641Using PGP with Git 642================== 643 644One of the core features of Git is its decentralized nature -- once a 645repository is cloned to your system, you have full history of the 646project, including all of its tags, commits and branches. However, with 647hundreds of cloned repositories floating around, how does anyone verify 648that their copy of linux.git has not been tampered with by a malicious 649third party? 650 651Or what happens if malicious code is discovered in the kernel and the 652"Author" line in the commit says it was done by you, while you're pretty 653sure you had `nothing to do with it`_? 654 655To address both of these issues, Git introduced PGP integration. Signed 656tags prove the repository integrity by assuring that its contents are 657exactly the same as on the workstation of the developer who created the 658tag, while signed commits make it nearly impossible for someone to 659impersonate you without having access to your PGP keys. 660 661.. _`nothing to do with it`: https://github.com/jayphelps/git-blame-someone-else 662 663Configure git to use your PGP key 664--------------------------------- 665 666If you only have one secret key in your keyring, then you don't really 667need to do anything extra, as it becomes your default key. However, if 668you happen to have multiple secret keys, you can tell git which key 669should be used (``[fpr]`` is the fingerprint of your key):: 670 671 $ git config --global user.signingKey [fpr] 672 673How to work with signed tags 674---------------------------- 675 676To create a signed tag, pass the ``-s`` switch to the tag command:: 677 678 $ git tag -s [tagname] 679 680Our recommendation is to always sign git tags, as this allows other 681developers to ensure that the git repository they are pulling from has 682not been maliciously altered. 683 684How to verify signed tags 685~~~~~~~~~~~~~~~~~~~~~~~~~ 686 687To verify a signed tag, use the ``verify-tag`` command:: 688 689 $ git verify-tag [tagname] 690 691If you are pulling a tag from another fork of the project repository, 692git should automatically verify the signature at the tip you're pulling 693and show you the results during the merge operation:: 694 695 $ git pull [url] tags/sometag 696 697The merge message will contain something like this:: 698 699 Merge tag 'sometag' of [url] 700 701 [Tag message] 702 703 # gpg: Signature made [...] 704 # gpg: Good signature from [...] 705 706If you are verifying someone else's git tag, you will first need to 707import their PGP key. Please refer to the ":ref:`verify_identities`" 708section below. 709 710Configure git to always sign annotated tags 711~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 712 713Chances are, if you're creating an annotated tag, you'll want to sign 714it. To force git to always sign annotated tags, you can set a global 715configuration option:: 716 717 $ git config --global tag.forceSignAnnotated true 718 719How to work with signed commits 720------------------------------- 721 722It is also possible to create signed commits, but they have limited 723usefulness in Linux kernel development. The kernel contribution workflow 724relies on sending in patches, and converting commits to patches does not 725preserve git commit signatures. Furthermore, when rebasing your own 726repository on a newer upstream, PGP commit signatures will end up 727discarded. For this reason, most kernel developers don't bother signing 728their commits and will ignore signed commits in any external 729repositories that they rely upon in their work. 730 731That said, if you have your working git tree publicly available at some 732git hosting service (kernel.org, infradead.org, ozlabs.org, or others), 733then the recommendation is that you sign all your git commits even if 734upstream developers do not directly benefit from this practice. 735 736We recommend this for the following reasons: 737 7381. Should there ever be a need to perform code forensics or track code 739 provenance, even externally maintained trees carrying PGP commit 740 signatures will be valuable for such purposes. 7412. If you ever need to re-clone your local repository (for example, 742 after reinstalling your system), this lets you verify the repository 743 integrity before resuming your work. 7443. If someone needs to cherry-pick your commits, this allows them to 745 quickly verify their integrity before applying them. 746 747Creating signed commits 748~~~~~~~~~~~~~~~~~~~~~~~ 749 750To create a signed commit, pass the ``-S`` flag to the ``git commit`` 751command (it's capital ``-S`` due to collision with another flag):: 752 753 $ git commit -S 754 755Configure git to always sign commits 756~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 757 758You can tell git to always sign commits:: 759 760 git config --global commit.gpgSign true 761 762.. note:: 763 764 Make sure you configure ``gpg-agent`` before you turn this on. 765 766.. _verify_identities: 767 768How to work with signed patches 769------------------------------- 770 771It is possible to use your PGP key to sign patches sent to kernel 772developer mailing lists. Since existing email signature mechanisms 773(PGP-Mime or PGP-inline) tend to cause problems with regular code 774review tasks, you should use the tool kernel.org created for this 775purpose that puts cryptographic attestation signatures into message 776headers (a-la DKIM): 777 778- `Patatt Patch Attestation`_ 779 780.. _`Patatt Patch Attestation`: https://pypi.org/project/patatt/ 781 782Installing and configuring patatt 783~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 784 785.. note:: 786 787 If you use B4 to send in your patches, patatt is already installed 788 and integrated into your workflow. 789 790Patatt is packaged for many distributions already, so please check there 791first. You can also install it from pypi using "``pip install patatt``". 792 793If you already have your PGP key configured with git (via the 794``user.signingKey`` configuration parameter), then patatt requires no 795further configuration. You can start signing your patches by installing 796the git-send-email hook in the repository you want:: 797 798 patatt install-hook 799 800Now any patches you send with ``git send-email`` will be automatically 801signed with your cryptographic signature. 802 803Checking patatt signatures 804~~~~~~~~~~~~~~~~~~~~~~~~~~ 805 806If you are using ``b4`` to retrieve and apply patches, then it will 807automatically attempt to verify all DKIM and patatt signatures it 808encounters, for example:: 809 810 $ b4 am 20220720205013.890942-1-broonie@kernel.org 811 [...] 812 Checking attestation on all messages, may take a moment... 813 --- 814 ✓ [PATCH v1 1/3] kselftest/arm64: Correct buffer allocation for SVE Z registers 815 ✓ [PATCH v1 2/3] arm64/sve: Document our actual ABI for clearing registers on syscall 816 ✓ [PATCH v1 3/3] kselftest/arm64: Enforce actual ABI for SVE syscalls 817 --- 818 ✓ Signed: openpgp/broonie@kernel.org 819 ✓ Signed: DKIM/kernel.org 820 821.. note:: 822 823 Patatt and b4 are still in active development and you should check 824 the latest documentation for these projects for any new or updated 825 features. 826 827.. _kernel_identities: 828 829How to verify kernel developer identities 830========================================= 831 832Signing tags and commits is straightforward, but how does one go about 833verifying that the key used to sign something belongs to the actual 834kernel developer and not to a malicious imposter? 835 836Configure auto-key-retrieval using WKD and DANE 837----------------------------------------------- 838 839If you are not already someone with an extensive collection of other 840developers' public keys, then you can jumpstart your keyring by relying 841on key auto-discovery and auto-retrieval. GnuPG can piggyback on other 842delegated trust technologies, namely DNSSEC and TLS, to get you going if 843the prospect of starting your own Web of Trust from scratch is too 844daunting. 845 846Add the following to your ``~/.gnupg/gpg.conf``:: 847 848 auto-key-locate wkd,dane,local 849 auto-key-retrieve 850 851DNS-Based Authentication of Named Entities ("DANE") is a method for 852publishing public keys in DNS and securing them using DNSSEC signed 853zones. Web Key Directory ("WKD") is the alternative method that uses 854https lookups for the same purpose. When using either DANE or WKD for 855looking up public keys, GnuPG will validate DNSSEC or TLS certificates, 856respectively, before adding auto-retrieved public keys to your local 857keyring. 858 859Kernel.org publishes the WKD for all developers who have kernel.org 860accounts. Once you have the above changes in your ``gpg.conf``, you can 861auto-retrieve the keys for Linus Torvalds and Greg Kroah-Hartman (if you 862don't already have them):: 863 864 $ gpg --locate-keys torvalds@kernel.org gregkh@kernel.org 865 866If you have a kernel.org account, then you should `add the kernel.org 867UID to your key`_ to make WKD more useful to other kernel developers. 868 869.. _`add the kernel.org UID to your key`: https://korg.docs.kernel.org/mail.html#adding-a-kernel-org-uid-to-your-pgp-key 870 871Web of Trust (WOT) vs. Trust on First Use (TOFU) 872------------------------------------------------ 873 874PGP incorporates a trust delegation mechanism known as the "Web of 875Trust." At its core, this is an attempt to replace the need for 876centralized Certification Authorities of the HTTPS/TLS world. Instead of 877various software makers dictating who should be your trusted certifying 878entity, PGP leaves this responsibility to each user. 879 880Unfortunately, very few people understand how the Web of Trust works. 881While it is still an important part of the OpenPGP specification, 882recent versions of GnuPG (2.2 and above) have implemented an alternative 883mechanism called "Trust on First Use" (TOFU). You can think of TOFU as 884"the SSH-like approach to trust." With SSH, the first time you connect 885to a remote system, its key fingerprint is recorded and remembered. If 886the key changes in the future, the SSH client will alert you and refuse 887to connect, forcing you to make a decision on whether you choose to 888trust the changed key or not. Similarly, the first time you import 889someone's PGP key, it is assumed to be valid. If at any point in the 890future GnuPG comes across another key with the same identity, both the 891previously imported key and the new key will be marked for verification 892and you will need to manually figure out which one to keep. 893 894We recommend that you use the combined TOFU+PGP trust model (which is 895the new default in GnuPG v2). To set it, add (or modify) the 896``trust-model`` setting in ``~/.gnupg/gpg.conf``:: 897 898 trust-model tofu+pgp 899 900Using the kernel.org web of trust repository 901-------------------------------------------- 902 903Kernel.org maintains a git repository with developers' public keys as a 904replacement for replicating keyserver networks that have gone mostly 905dark in the past few years. The full documentation for how to set up 906that repository as your source of public keys can be found here: 907 908- `Kernel developer PGP Keyring`_ 909 910If you are a kernel developer, please consider submitting your key for 911inclusion into that keyring. 912 913.. _`Kernel developer PGP Keyring`: https://korg.docs.kernel.org/pgpkeys.html 914