Skip to contentSkip to conversation

container improvements

PATCH New [email protected] 1 participant 5 messages Sep 21

lore
Share & tools
lore
#0 lore raw

cover container improvements

A recent change in 'cosign' now requires agreeing to a prompt, or setting COSIGN_YES for CI builds.

We were previously declaring --type spdxjson for cosign, which is an SPDX 2.x declaration. Use the more explicit SPDX 3.0 declaration instead.

Add some improvements to the time taken for the "push-containers" step in the container-library job. It shaves a few minutes off of each container run.

#1 lore raw

PATCH 1/4 run-push-containers: Set COSIGN_YES to avoid interactive prompt

From: Tim Orling <[email protected]>

cosign 3.x asks for consent before uploading to the Rekor transparency log, which the autobuilder cannot answer:

By typing 'y', you attest that (1) you are not submitting the personal data of any other person; and (2) you understand and agree to the statement and the Agreement terms at the URLs listed above. Are you sure you would like to continue? [y/N] Error: signing [...]:
recursively signing: signing digest: user declined the prompt

Export COSIGN_YES=true alongside COSIGN_PASSWORD so both 'cosign sign' and 'cosign attest' run non-interactively.

AI-Generated: Claude Opus 5

---
 scripts/run-push-containers | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/run-push-containers +6 -0
index 5dd35af..3ed43ae 100755
@@ -164,6 +164,11 @@ script = [
 # The real value, if the key is encrypted, must be present in the build
 # environment.
 #
+# COSIGN_YES answers the transparency-log consent prompt ("Are you sure you
+# would like to continue? [y/N]") that cosign shows before uploading to Rekor.
+# Without it the non-interactive autobuilder gets "user declined the prompt"
+# and the step fails. It covers both 'sign' and 'attest'.
+#
 # sign_image() signs by digest ($2) so cosign does not warn about signing a
 # mutable tag, while still pinning the index a consumer verifies. The digest
 # MUST be the digest the tag resolves to:
@@ -196,6 +201,7 @@ sys.stdout.write(base64.b64decode(t).decode() if t else "")' "%s" "$_host")
     done""" % (" ".join(registries), auth_config)
     script += [
         "export COSIGN_PASSWORD=\"${COSIGN_PASSWORD:-}\"",
+        "export COSIGN_YES=true",
         "_COSIGN_READY=0",
         "prepare_cosign() {",
         "    if [ \"$_COSIGN_READY\" = 1 ]; then return 0; fi",
Signature · 1 line
2.47.3
#2 lore raw

PATCH 2/4 run-push-containers: Declare SPDX 3 predicate type for attestations

In reply to [email protected]

From: Tim Orling <[email protected]>

cosign's 'spdxjson' alias hardcodes the SPDX 2.x predicate type
https://spdx.dev/Document, but create_image_sbom_spdx emits SPDX 3.0.1. Pass the in-toto SPDX 3 URI https://spdx.dev/Document/v3 explicitly on both attest and verify-attestation; for a non-alias type cosign embeds the JSON predicate verbatim, which is what the JSON-LD document needs.

AI-Generated: Claude Opus 5

---
 scripts/run-push-containers | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
scripts/run-push-containers +13 -3
index 3ed43ae..fd606c0 100755
@@ -19,7 +19,7 @@
 #                              successfully pushed image is signed with
 #                              cosign (otherwise signing is skipped). Also
 #                              gates SPDX SBOM attestation: each pushed image
-#                              gets a 'cosign attest --type spdxjson'
+#                              gets an in-toto SPDX 3.x ('cosign attest')
 #                              attestation of its SPDX SBOM (per-arch on the
 #                              multi-arch path, top manifest on single-arch).
 #   CONTAINER_COSIGN_PUB     - cosign public key path; when set, each
@@ -69,6 +69,10 @@ cosign_key = utils.getconfigvar("CONTAINER_COSIGN_KEY", ourconfig, args.target,
 # Public key for verifying attestations; when unset, attestations are made but
 # not verified.
 cosign_pub = utils.getconfigvar("CONTAINER_COSIGN_PUB", ourconfig, args.target, args.stepnum)
+# in-toto predicate type URI for SPDX 3.x documents. Must be identical on
+# 'attest' and 'verify-attestation', or verification finds no matching
+# attestation.
+SPDX_PREDICATE_TYPE = "https://spdx.dev/Document/v3"
 
 utils.printheader("Pushing container images %s" % list(container_images.keys()))
 
@@ -269,7 +273,13 @@ sys.stdout.write(base64.b64decode(t).decode() if t else "")' "%s" "$_host")
         "    prepare_cosign",
         "    case \" $_ATTESTED_REFS \" in *\" $1 \"*) return 0 ;; esac",
         "    _ATTESTED_REFS=\"$_ATTESTED_REFS $1\"",
-        "    _att_out=$(oe-run-native cosign-native cosign attest --key %s --type spdxjson --predicate \"$2\" \"$1\" 2>&1) || {" % cosign_key,
+        # --type is the in-toto predicate type URI, not cosign's 'spdxjson'
+        # alias: that alias hardcodes https://spdx.dev/Document, which is the
+        # SPDX 2.x predicate. create_image_sbom_spdx emits SPDX 3.0.1, so we
+        # pass the v3 URI explicitly. For an unknown (non-alias) type cosign
+        # parses the predicate as JSON and embeds it verbatim, which is what
+        # we want for the SPDX 3 JSON-LD document.
+        "    _att_out=$(oe-run-native cosign-native cosign attest --key %s --type %s --predicate \"$2\" \"$1\" 2>&1) || {" % (cosign_key, SPDX_PREDICATE_TYPE),
         "        case \"$_att_out\" in",
         "            *\"already exists\"*|*createLogEntryConflict*) echo \"cosign: attestation for $1 already in transparency log\" ;;",
         "            *) echo \"$_att_out\" >&2; return 1 ;;",
@@ -279,7 +289,7 @@ sys.stdout.write(base64.b64decode(t).decode() if t else "")' "%s" "$_host")
     ]
     if cosign_pub:
         script += [
-            "    oe-run-native cosign-native cosign verify-attestation --key %s --type spdxjson \"$1\" >/dev/null \\" % cosign_pub,
+            "    oe-run-native cosign-native cosign verify-attestation --key %s --type %s \"$1\" >/dev/null \\" % (cosign_pub, SPDX_PREDICATE_TYPE),
             "        && echo \"cosign: verified attestation for $1\" \\",
             "        || { echo \"ERROR: attestation verification failed for $1\" >&2; return 1; }",
         ]
Signature · 1 line
2.47.3
#3 lore raw

PATCH 3/4 run-push-containers: Cache native sysroots to cut bitbake startups

In reply to [email protected]

From: Tim Orling <[email protected]>

Every oe-run-native invocation re-runs bitbake-getvar to locate the native sysroot, paying a full cooker startup and metadata parse each time. Resolve it once per tool in prepare_skopeo()/prepare_cosign() and pass OECORE_NATIVE_SYSROOT through the _skopeo()/_cosign() wrappers.

For one multiarch container with 4 tags, 1 registry and 2 platforms this drops bitbake startups from 19 to 11.

AI-Generated: Claude Opus 5

---
 scripts/run-push-containers | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)
scripts/run-push-containers +19 -10
index fd606c0..702335b 100755
@@ -138,10 +138,16 @@ script = [
     "    %s-$(arch) --config %s memres restart </dev/null" % (runtime, auth_config),
     "    _VM_STARTED=1",
     "}",
+    # oe-run-native re-runs 'bitbake-getvar STAGING_DIR_NATIVE' (a full parse)
+    # on every call unless OECORE_NATIVE_SYSROOT is set, so prepare_*() resolves
+    # it once and these wrappers pass it in. Empty falls back to the query.
+    "_SKOPEO_SYSROOT=",
+    "_skopeo() { OECORE_NATIVE_SYSROOT=\"$_SKOPEO_SYSROOT\" oe-run-native skopeo-native skopeo \"$@\"; }",
     "_SKOPEO_READY=0",
     "prepare_skopeo() {",
     "    if [ \"$_SKOPEO_READY\" = 1 ]; then return 0; fi",
     "    bitbake skopeo-native -c addto_recipe_sysroot",
+    "    _SKOPEO_SYSROOT=$(bitbake-getvar -q -r skopeo-native --value STAGING_DIR_NATIVE)",
     "    _SKOPEO_READY=1",
     "}",
 ]
@@ -201,24 +207,27 @@ sys.stdout.write(base64.b64decode(t).decode() if t else "")' "%s" "$_host")
         fi
         _cuser=${_creds%%%%:*}
         _cpass=${_creds#*:}
-        printf '%%s' "$_cpass" | oe-run-native cosign-native cosign login "$_host" -u "$_cuser" --password-stdin
+        printf '%%s' "$_cpass" | _cosign login "$_host" -u "$_cuser" --password-stdin
     done""" % (" ".join(registries), auth_config)
     script += [
         "export COSIGN_PASSWORD=\"${COSIGN_PASSWORD:-}\"",
         "export COSIGN_YES=true",
+        "_COSIGN_SYSROOT=",
+        "_cosign() { OECORE_NATIVE_SYSROOT=\"$_COSIGN_SYSROOT\" oe-run-native cosign-native cosign \"$@\"; }",
         "_COSIGN_READY=0",
         "prepare_cosign() {",
         "    if [ \"$_COSIGN_READY\" = 1 ]; then return 0; fi",
         "    bitbake cosign-native -c addto_recipe_sysroot",
+        "    _COSIGN_SYSROOT=$(bitbake-getvar -q -r cosign-native --value STAGING_DIR_NATIVE)",
         login_block,
         "    _COSIGN_READY=1",
         "}",
         # Resolve the lone manifest digest of a single-arch reference. Correct
         # only when there is no manifest list (single-arch / child manifest);
-        # the multi-arch path passes explicit digests instead. oe-run-native
-        # prints 'Getting sysroot...' to stdout, so grep the digest out.
+        # the multi-arch path passes explicit digests instead. oe-run-native can
+        # still print 'Getting sysroot...', so grep the digest out.
         "resolve_digest() {",
-        "    oe-run-native skopeo-native skopeo inspect --authfile %s --format '{{.Digest}}' docker://$1 | grep -oE 'sha256:[0-9a-f]{64}' | tail -n1" % auth_config,
+        "    _skopeo inspect --authfile %s --format '{{.Digest}}' docker://$1 | grep -oE 'sha256:[0-9a-f]{64}' | tail -n1" % auth_config,
         "}",
         # Track digests already signed in this run so the same artefact is
         # signed only once (see sign_image).
@@ -226,8 +235,8 @@ sys.stdout.write(base64.b64decode(t).decode() if t else "")' "%s" "$_host")
         # $1 = <registry>/<image>:<tag> just pushed; $2 = its digest (the index
         # digest from 'skopeo copy --digestfile' on the multi-arch path). When
         # $2 is empty (single-arch), resolve the lone manifest digest with
-        # 'skopeo inspect' — correct there since there is no list. oe-run-native
-        # prints 'Getting sysroot...' to stdout, so grep the digest out.
+        # 'skopeo inspect' — correct there since there is no list. The digest
+        # is grepped out of resolve_digest's output (see there).
         "sign_image() {",
         "    prepare_skopeo",
         "    prepare_cosign",
@@ -241,7 +250,7 @@ sys.stdout.write(base64.b64decode(t).decode() if t else "")' "%s" "$_host")
         # transparency-log conflict ('already exists' / HTTP 409, which also
         # recurs on rebuilds that reproduce the same digest) as success so
         # signing stays idempotent instead of aborting the step.
-        "    _sign_out=$(oe-run-native cosign-native cosign sign --recursive --key %s \"$_SIG_REF\" 2>&1) || {" % cosign_key,
+        "    _sign_out=$(_cosign sign --recursive --key %s \"$_SIG_REF\" 2>&1) || {" % cosign_key,
         "        case \"$_sign_out\" in",
         "            *\"already exists\"*|*createLogEntryConflict*) echo \"cosign: $_SIG_REF already in transparency log, treating as signed\" ;;",
         "            *) echo \"$_sign_out\" >&2; return 1 ;;",
@@ -279,7 +288,7 @@ sys.stdout.write(base64.b64decode(t).decode() if t else "")' "%s" "$_host")
         # pass the v3 URI explicitly. For an unknown (non-alias) type cosign
         # parses the predicate as JSON and embeds it verbatim, which is what
         # we want for the SPDX 3 JSON-LD document.
-        "    _att_out=$(oe-run-native cosign-native cosign attest --key %s --type %s --predicate \"$2\" \"$1\" 2>&1) || {" % (cosign_key, SPDX_PREDICATE_TYPE),
+        "    _att_out=$(_cosign attest --key %s --type %s --predicate \"$2\" \"$1\" 2>&1) || {" % (cosign_key, SPDX_PREDICATE_TYPE),
         "        case \"$_att_out\" in",
         "            *\"already exists\"*|*createLogEntryConflict*) echo \"cosign: attestation for $1 already in transparency log\" ;;",
         "            *) echo \"$_att_out\" >&2; return 1 ;;",
@@ -289,7 +298,7 @@ sys.stdout.write(base64.b64decode(t).decode() if t else "")' "%s" "$_host")
     ]
     if cosign_pub:
         script += [
-            "    oe-run-native cosign-native cosign verify-attestation --key %s --type %s \"$1\" >/dev/null \\" % (cosign_pub, SPDX_PREDICATE_TYPE),
+            "    _cosign verify-attestation --key %s --type %s \"$1\" >/dev/null \\" % (cosign_pub, SPDX_PREDICATE_TYPE),
             "        && echo \"cosign: verified attestation for $1\" \\",
             "        || { echo \"ERROR: attestation verification failed for $1\" >&2; return 1; }",
         ]
@@ -419,7 +428,7 @@ for recipe, image in container_images.items():
     for registry in registries:
         script += [
             "        for _tag in $_TAGS; do",
-            "            oe-run-native skopeo-native skopeo copy --all%s --dest-authfile %s oci:${_OCI_MULTIARCH_OUTPUT} docker://%s/%s:${_tag}" % (digestfile, auth_config, registry, image),
+            "            _skopeo copy --all%s --dest-authfile %s oci:${_OCI_MULTIARCH_OUTPUT} docker://%s/%s:${_tag}" % (digestfile, auth_config, registry, image),
         ]
         if cosign_key:
             script.append("            sign_image %s/%s:${_tag} \"$(cat \"$_DGSTFILE\")\"" % (registry, image))
Signature · 1 line
2.47.3
#4 lore raw

PATCH 4/4 config.json: Keep the bitbake server warm for containers-library

In reply to [email protected]

From: Tim Orling <[email protected]>

The push-containers step makes ~11 bitbake invocations per container. Without BB_SERVER_TIMEOUT each starts its own cooker and reparses the whole layer stack. Set it to 600, as buildperf and metrics already do.

AI-Generated: Claude Opus 5

---
 config.json | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
config.json +2 -1
index 22fc16d..d4b2ec2 100644
@@ -1890,7 +1890,8 @@
             "extravars" : [
                 "require conf/distro/include/meta-virt-host.conf",
                 "DISTRO_FEATURES:append = ' usrmerge'",
-                "INIT_MANAGER = 'systemd'"
+                "INIT_MANAGER = 'systemd'",
+                "BB_SERVER_TIMEOUT = '600'"
             ],
             "EXTRACMDS" : ["sed -i '/meta-virt-host.conf/d' ${HELPERBUILDDIR}/conf/auto.conf"],
             "vcontainer" : "${VCONTAINER_TARBALL_URL}",
Signature · 1 line
2.47.3