github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/www/docs/customization/sign.md (about) 1 --- 2 title: Signing 3 --- 4 5 Signing ensures that the artifacts have been generated by yourself and your 6 users can verify that by comparing the generated signature with your public 7 signing key. 8 9 GoReleaser provides means to sign both executables and archives. 10 11 ## Usage 12 13 Signing works in combination with checksum files and it is generally sufficient 14 to sign the checksum files only. 15 16 The default is configured to create a detached signature for the checksum files 17 with [GnuPG](https://www.gnupg.org/) and your default key. To enable signing 18 just add 19 20 ```yaml 21 # .goreleaser.yml 22 signs: 23 - artifacts: checksum 24 ``` 25 26 To customize the signing pipeline you can use the following options: 27 28 ```yaml 29 # .goreleaser.yml 30 signs: 31 - 32 # ID of the sign config, must be unique. 33 # 34 # Defaults to "default". 35 id: foo 36 37 # Name/template of the signature file. 38 # 39 # Available environment variables: 40 # - '${artifact}': the path to the artifact that will be signed 41 # - '${artifactID}': the ID of the artifact that will be signed 42 # 43 # Defaults to `${artifact}.sig`. 44 signature: "${artifact}_sig" 45 46 # Path to the signature command 47 # 48 # Defaults to `gpg` 49 cmd: gpg2 50 51 # Command line templateable arguments for the command 52 # 53 # to sign with a specific key use 54 # args: ["-u", "<key id, fingerprint, email, ...>", "--output", "${signature}", "--detach-sign", "${artifact}"] 55 # 56 # Defaults to `["--output", "${signature}", "--detach-sign", "${artifact}"]` 57 args: ["--output", "${signature}", "${artifact}", "{{ .ProjectName }}"] 58 59 60 # Which artifacts to sign 61 # 62 # all: all artifacts 63 # none: no signing 64 # checksum: only checksum file(s) 65 # source: source archive 66 # package: linux packages (deb, rpm, apk) 67 # archive: archives from archive pipe 68 # binary: binaries if archiving format is set to binary 69 # 70 # Defaults to `none` 71 artifacts: all 72 73 # IDs of the artifacts to sign. 74 # 75 # If `artifacts` is checksum or source, this fields has no effect. 76 # 77 # Defaults to empty (which implies no filtering). 78 ids: 79 - foo 80 - bar 81 82 # Stdin data template to be given to the signature command as stdin. 83 # 84 # Defaults to empty 85 stdin: '{{ .Env.GPG_PASSWORD }}' 86 87 # StdinFile file to be given to the signature command as stdin. 88 # 89 # Defaults to empty 90 stdin_file: ./.password 91 ``` 92 93 ## Signing with cosign 94 95 You can sign you artifacts with [cosign][] as well. 96 97 Assuming you have a `cosign.key` in the repository root and a `COSIGN_PWD` environment variable set, a simple usage example would look like this: 98 99 ```yaml 100 # .goreleaser.yml 101 signs: 102 - cmd: cosign 103 stdin: '{{ .Env.COSIGN_PWD }}' 104 args: ["sign-blob", "-key=cosign.key", "-output=${signature}", "${artifact}"] 105 artifacts: all 106 ``` 107 108 Your users can then verify the signature with: 109 110 ```sh 111 cosign verify-blob -key cosign.pub -signature file.tar.gz.sig file.tar.gz 112 ``` 113 114 115 ## Signing executables 116 117 Executables can be signed after build using post hooks. 118 119 ### With gon 120 121 For example, you can use [gon][] to create notarized MacOS apps: 122 123 ```yaml 124 # .goreleaser.yml 125 builds: 126 - binary: foo 127 id: foo 128 goos: 129 - linux 130 - windows 131 goarch: 132 - amd64 133 134 # notice that we need a separated build for the MacOS binary only: 135 - binary: foo 136 id: foo-macos 137 goos: 138 - darwin 139 goarch: 140 - amd64 141 hooks: 142 post: gon gon.hcl 143 ``` 144 145 and: 146 147 ```terraform 148 # gon.hcl 149 # 150 # The path follows a pattern 151 # ./dist/BUILD-ID_TARGET/BINARY-NAME 152 source = ["./dist/foo-macos_darwin_amd64/foo"] 153 bundle_id = "com.mitchellh.example.terraform" 154 155 apple_id { 156 username = "mitchell@example.com" 157 password = "@env:AC_PASSWORD" 158 } 159 160 sign { 161 application_identity = "Developer ID Application: Mitchell Hashimoto" 162 } 163 ``` 164 165 Note that notarizing may take some time, and will need to be run from a MacOS machine. 166 167 If you generate ZIP or DMG as part of your signing via gon you may need 168 to ensure their file names align with desired pattern of other artifacts 169 as GoReleaser doesn't control how these get generated beyond just executing `gon` 170 with given arguments. Relatedly you may need to list these additional artifacts 171 as `extra_files` in the `release` section to make sure they also get uploaded. 172 173 You can also check [this issue](https://github.com/goreleaser/goreleaser/issues/1227) for more details. 174 175 176 ### With cosign 177 178 You can also use [cosign][] to sign the binaries directly, 179 but you'll need to manually add the `.sig` files to the release and/or archive: 180 181 ```yaml 182 # .goreleaser.yml 183 builds: 184 - hooks: 185 post: 186 - sh -c "echo $COSIGN_PWD | cosign sign-blob -key cosign.key {{ .Path }} > dist/{{ .ProjectName }}_{{ .Version }}_{{ .Target }}.sig" 187 188 # add to the release directly: 189 release: 190 extra_files: 191 - glob: dist/*.sig 192 193 # or just to the archives: 194 archives: 195 - files: 196 - dist/*.sig 197 ``` 198 199 While this works, I would recommend using the signing pipe directly. 200 201 ## Signing Docker images and manifests 202 203 Please refer to [Docker Images Signing](/customization/docker_sign/). 204 205 ## Limitations 206 207 You can sign with any command that either outputs a file or modify the file being signed. 208 209 If you want to sign with something that writes to `STDOUT` instead of a file, 210 you can wrap the command inside a `sh -c` execution, for instance: 211 212 ```yaml 213 # .goreleaser.yml 214 signs: 215 - cmd: sh 216 args: 217 - '-c' 218 - 'echo "${artifact} is signed and I can prove it" | tee ${signature}' 219 artifacts: all 220 ``` 221 222 And it will work just fine. Just make sure to always use the `${signature}` 223 template variable as the result file name and `${artifact}` as the origin file. 224 225 [gon]: https://github.com/mitchellh/gon 226 [cosign]: https://github.com/sigstore/cosign