github.com/inspektor-gadget/inspektor-gadget@v0.28.1/docs/getting-started/verify.md (about) 1 --- 2 title: Verifying 3 weight: 120 4 description: > 5 Verify Inspektor Gadget 6 --- 7 8 Inspektor Gadget container image and release assets are signed using 9 [`cosign`](https://github.com/sigstore/cosign). 10 In this guide, we will see how you can verify them with this tool. 11 Note that, You would need to have `cosign` [v2.0](https://github.com/sigstore/cosign/blob/main/README.md#developer-installation) installed. 12 13 ## Verify the container image manually 14 15 Verifying the container image is pretty straightforward: 16 17 ```bash 18 $ RELEASE='v0.27.0' 19 $ cosign verify --key https://raw.githubusercontent.com/inspektor-gadget/inspektor-gadget/${RELEASE}/inspektor-gadget.pub ghcr.io/inspektor-gadget/inspektor-gadget:${RELEASE} 20 The following checks were performed on each of these signatures: 21 - The cosign claims were validated 22 - Existence of the claims in the transparency log was verified offline 23 - The signatures were verified against the specified public key 24 25 [{"critical":{"identity":{"docker-reference":"ghcr.io/inspektor-gadget/inspektor-gadget"}, ... 26 ] 27 ``` 28 29 Getting the above output followed by a JSON array of payloads, ensures you the 30 container image was signed using our private key. 31 32 ## Verify the container image while deploying 33 34 When deploying Inspektor Gadget using `kubectl gadget deploy`, the image will be automatically verified if the `policy-controller` is deployed on your Kubernetes cluster. 35 To do so, you first need to [install](https://docs.sigstore.dev/policy-controller/installation/) this component. 36 Now, let's deploy Inspektor Gadget in a cluster where the `policy-controller` is present: 37 38 ```bash 39 $ kubectl get pod -n cosign-system 40 NAME READY STATUS RESTARTS AGE 41 policy-controller-webhook-7c7f55dfcf-qkpw4 1/1 Running 0 10s 42 $ kubectl gadget deploy 43 ... 44 1/1 gadget pod(s) ready 45 ... 46 Inspektor Gadget successfully deployed 47 ``` 48 49 As you can see, everything was successfully deployed. 50 Now, let's undeploy Inspektor Gadget and try to deploy an old release which was not signed: 51 52 ```bash 53 $ kubectl gadget undeploy 54 ... 55 Inspektor Gadget successfully removed 56 $ kubectl gadget deploy --image 'ghcr.io/inspektor-gadget/inspektor-gadget:v0.22.0' 57 ... 58 Creating DaemonSet/gadget... 59 Error: problem while creating resource: creating "DaemonSet": admission webhook "policy.sigstore.dev" denied the request: validation failed: failed policy: gadget-image-policy: spec.template.spec.containers[0].image 60 ghcr.io/inspektor-gadget/inspektor-gadget@sha256:9272c2be979a9857971fc8b6f7226e609cadec8352f97e9769081930121ef27f signature key validation failed for authority authority-0 for ghcr.io/inspektor-gadget/inspektor-gadget@sha256:9272c2be979a9857971fc8b6f7226e609cadec8352f97e9769081930121ef27f: no matching signatures 61 ``` 62 63 As this image is not signed, the verification failed and the container was not deployed to the cluster. 64 65 In case the `policy-controller` is not present, a warning message will be printed to inform you the verification will not take place: 66 67 ```bash 68 $ kubectl get pod -n cosign-system 69 No resources found in cosign-system namespace. 70 $ kubectl gadget deploy 71 WARN[0000] No policy controller found, the container image will not be verified 72 ... 73 Inspektor Gadget successfully deployed 74 ``` 75 76 ### Skipping verification 77 78 You can also decide to not verify the image, using `--verify-image=false`. 79 We definitely do not recommend this and you will use this option at your own risk: 80 81 ```bash 82 $ kubectl gadget deploy --verify-image=false 83 WARN[0000] You used --verify-image=false, the container image will not be verified 84 ... 85 Inspektor Gadget successfully deployed 86 ``` 87 88 ### Using custom public key for verification 89 90 To verify the image with a specific key, you can use the `--public-key` flag: 91 92 ```bash 93 $ kubectl gadget deploy --public-key="$(cat pkg/resources/inspektor-gadget.pub)" 94 ``` 95 96 ## Verify the container Source Code Bill Of Materials (SBOMs) 97 98 A Software Bill of Materials (SBOM) is a detailed list of all the components of a software. 99 It facilitates security and license compliance assessments. 100 The Inspektor Gadget project publishes SBOMs in the [CycloneDX format](https://cyclonedx.org/specification/overview/) for all our container images and CLI tools: 101 * SBOMs for container images are attached to the corresponding image and can be found in our [registry](https://github.com/orgs/inspektor-gadget/packages). 102 * SBOMs for CLI tools are available as [release](https://github.com/inspektor-gadget/inspektor-gadget/releases) assets. 103 104 In this section, we will see how you can verify and inspect the SBOMs attached to our container images. 105 To do so, you will need `cosign`, [`oras`](https://oras.land/docs/installation) and Inspektor Gadget public key. 106 107 ```bash 108 # We will demo this for amd64, but it works the same for arm64. 109 $ arch=amd64 110 $ oras discover --platform linux/${arch} --artifact-type example/sbom ghcr.io/inspektor-gadget/inspektor-gadget:latest 111 Discovered 1 artifact referencing latest 112 Digest: sha256:... 113 114 Artifact Type Digest 115 example/sbom sha256:hash_of_sbom_manifest 116 # As we include SBOMs in our multi architecture container image, they are also 117 # signed. 118 # So, let's check the SBOM is signed with our private key: 119 $ cosign verify --key inspektor-gadget.pub ghcr.io/inspektor-gadget/inspektor-gadget@sha256:hash_of_sbom_manifest 120 121 Verification for ghcr.io/inspektor-gadget/inspektor-gadget@sha256:hash_of_sbom_manifest 122 The following checks were performed on each of these signatures: 123 - The cosign claims were validated 124 - Existence of the claims in the transparency log was verified offline 125 - The signatures were verified against the specified public key 126 127 [{"critical":{"identity":{"docker-reference":"ghcr.io/inspektor-gadget/inspektor-gadget"}, ... 128 ] 129 # Let's download the SBOM and look at it: 130 $ oras pull --allow-path-traversal ghcr.io/inspektor-gadget/inspektor-gadget@sha256:hash_of_sbom_manifest 131 Downloading 1d479bb51392 /tmp/gadget-container-image-linux-amd64/sbom_cyclonedx.json 132 Downloaded 1d479bb51392 /tmp/gadget-container-image-linux-amd64/sbom_cyclonedx.json 133 Pulled [registry] ghcr.io/eiffel-fl/inspektor-gadget@sha256:hash_of_sbom_manifest 134 Digest: sha256:hash_of_sbom_manifest 135 $ jq '' /tmp/gadget-container-image-linux-amd64/sbom_cyclonedx.json 136 { 137 "$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json", 138 "bomFormat": "CycloneDX", 139 "specVersion": "1.5", 140 "serialNumber": "urn:uuid:cf132c3d-5960-4536-9c03-9724babd76e9", 141 "version": 1, 142 "metadata": { 143 "timestamp": "2024-03-21T17:22:38Z", 144 "tools": { 145 "components": [ 146 { 147 "type": "application", 148 "author": "anchore", 149 "name": "syft", 150 "version": "1.0.1" 151 } 152 ] 153 }, 154 "component": { 155 "bom-ref": "af63bd4c8601b7f1", 156 "type": "file", 157 "name": "." 158 } 159 }, 160 "components": [ 161 { 162 "bom-ref": "pkg:deb/debian/base-files@12.4+deb12u5?arch=amd64&distro=debian-12&package-id=854ccee33785ad46", 163 "type": "library", 164 "publisher": "Santiago Vila <sanvila@debian.org>", 165 "name": "base-files", 166 ... 167 } 168 ``` 169 170 As the SBOM was signed with our private key, you can now inspect it to track down every dependencies we use to build our container image. 171 172 ## Verify image-based gadgets 173 174 Like our container image, we sign all our image-based gadgets. 175 The signature are verified by default using Inspektor Gadget public key: 176 177 ```bash 178 $ sudo -E ig run ghcr.io/inspektor-gadget/gadget/trace_open:latest 179 RUNTIME.CONTAINERNA… PID UID GID MNTNS_ID E… FD FL… MODE COMM FNAME TIMESTAMP 180 ``` 181 182 Let's try to run an image-based gadget which was not signed: 183 184 ```bash 185 $ sudo -E ig run ghcr.io/inspektor-gadget/gadget/trace_open:v0.27.0 186 Error: fetching gadget information: initializing and preparing operators: instantiating operator "oci": ensuring image: verifying image "ghcr.io/inspektor-gadget/gadget/trace_open:v0.27.0": getting signing information: getting signature: getting signature bytes: ghcr.io/inspektor-gadget/gadget/trace_open:sha256-0c0e2fa72ae70e65351ab7a48a1cd5a68752a94d9c36e7b51e8764a1b7be3d7a.sig: not found 187 ``` 188 189 As the image was not signed, no signature was found in the repository, so the execution is denied. 190 191 You can set your own public key with `--public-key`: 192 193 ```bash 194 $ sudo -E ig run --public-key="$(cat your-key.pub)" ghcr.io/your-repo/gadget/trace_open 195 RUNTIME.CONTAINERNAME PID UID GID MNTNS_ID RET FL… MODE COMM FNAME TIMESTAMP 196 ``` 197 198 If you forget to set your public key, the image-based gadget will be verified using Inspektor Gadget public key and you will get the following error: 199 200 ```bash 201 $ sudo -E ig run ghcr.io/your-repo/gadget/trace_open 202 Error: fetching gadget information: initializing and preparing operators: instantiating operator "oci": ensuring image: verifying image "ghcr.io/your-repo/gadget/trace_open": verifying signature: invalid signature when validating ASN.1 encoded signature 203 ``` 204 205 You can also skip verifying image-based gadget signature with `--verify-image=false`. 206 Note that we do not recommend using this: 207 208 ```bash 209 $ sudo -E ig run --verify-image=false ghcr.io/your-repo/gadget/trace_open 210 WARN[0000] you set --verify-image=false, image will not be verified 211 WARN[0000] you set --verify-image=false, image will not be verified 212 RUNTIME.CONTAINERNAME PID UID GID MNTNS_ID RET FL… MODE COMM FNAME TIMESTAMP 213 ``` 214 215 ## Verify an asset 216 217 Rather than signing all the assets, we only sign the checksums file. 218 So, by verifying this file, you can then verify the assets themselves by 219 checking their checksums. 220 221 ## Verifying the checksums file 222 223 The following snippet show you how to verify the checksums file: 224 225 ```bash 226 $ RELEASE='v0.19.0' 227 $ ASSET="SHA256SUMS" 228 $ URL="https://github.com/inspektor-gadget/inspektor-gadget/releases/download/${RELEASE}" 229 # We need to get the asset itself, its signature file and the corresponding bundle: 230 $ for i in $URL/$ASSET $URL/$ASSET.sig $URL/$ASSET.bundle; do 231 wget $i 232 done 233 ... 234 # We need to get the public key too. 235 $ wget $URL/inspektor-gadget.pub 236 ... 237 $ cosign verify-blob $ASSET --bundle ${ASSET}.bundle --signature ${ASSET}.sig --key inspektor-gadget.pub --offline 238 Verified OK 239 ``` 240 241 As you can see, the checksum file was correctly verified which means this file was indeed signed by us. 242 So, you can use this file to verify other release assets. 243 244 ## Verify an asset 245 246 Once you verified the checksums file, you can now verify the integrity of an asset using such checksums file: 247 248 ```bash 249 $ RELEASE='v0.19.0' 250 $ ASSET="inspektor-gadget-${RELEASE}.yaml" 251 $ URL="https://github.com/inspektor-gadget/inspektor-gadget/releases/download/${RELEASE}" 252 $ wget $URL/$ASSET 253 $ grep $ASSET SHA256SUMS | shasum -a 256 -c -s || echo "Error: ${ASSET} didn't pass the checksum verification. You must not use it!" 254 ```