Fix Docker Hub digest lookup for signed releases #317
No files matched your search
@@ -165,10 +165,32 @@ else:
|
||||
self.wfile.write(payload)
|
||||
|
||||
def do_GET(self):
|
||||
path = urlsplit(self.path).path
|
||||
if path == '/token':
|
||||
expected = 'Basic ' + base64.b64encode(
|
||||
b'offline-user:' + DOCKER_TOKEN.encode()).decode('ascii')
|
||||
if self.headers.get('Authorization') != expected:
|
||||
self._json(401, {})
|
||||
return
|
||||
self._json(200, {'token': 'offline-registry-bearer'})
|
||||
return
|
||||
if path.startswith('/v2/') and '/manifests/sha-' in path:
|
||||
if self.headers.get('Authorization') != 'Bearer offline-registry-bearer':
|
||||
self._json(401, {})
|
||||
return
|
||||
if self.headers.get('Accept') is None:
|
||||
self._json(406, {})
|
||||
return
|
||||
digest = (GPU_AGENT_DIGEST if 'heimdall-agent-gpu' in path else
|
||||
AGENT_DIGEST if 'heimdall-agent' in path else SERVER_DIGEST)
|
||||
self.send_response(200)
|
||||
self.send_header('Docker-Content-Digest', digest)
|
||||
self.send_header('Content-Length', '0')
|
||||
self.end_headers()
|
||||
return
|
||||
if not self._authorized():
|
||||
self._json(401, {})
|
||||
return
|
||||
path = urlsplit(self.path).path
|
||||
commit = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=ROOT, text=True).strip()
|
||||
if '/compare/' in path:
|
||||
self._json(200, {'commits': [{'sha': 'synthetic-merge-commit'}]})
|
||||
@@ -261,6 +283,8 @@ else:
|
||||
'EXPECTED_BUILD_SERVER_URL': origin,
|
||||
'DOCKERHUB_USERNAME': 'offline-user',
|
||||
'DOCKERHUB_TOKEN': DOCKER_TOKEN,
|
||||
'DOCKER_REGISTRY_TOKEN_URL': origin,
|
||||
'DOCKER_REGISTRY_URL': origin,
|
||||
'RELEASE_TOKEN': RELEASE_TOKEN,
|
||||
'RELEASE_SIGNING_KEY_B64': signing_key_b64,
|
||||
'OFFLINE_DOCKER_LOG': str(docker_log),
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Resolve the canonical digest for an immutable Docker Hub repository tag."""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.parse import urlencode
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
|
||||
def endpoint(name, default, path):
|
||||
value = os.environ.get(name, default).rstrip('/')
|
||||
if not value.startswith('https://') or '@' in value:
|
||||
raise SystemExit('Registry endpoint must be HTTPS')
|
||||
return value + path
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
raise SystemExit('usage: dockerhub-tag-digest.py REPOSITORY IMMUTABLE_TAG')
|
||||
repository, tag = sys.argv[1:]
|
||||
if not re.fullmatch(r'[a-z0-9._-]+/[a-z0-9._-]+', repository):
|
||||
raise SystemExit('Invalid Docker Hub repository')
|
||||
if not re.fullmatch(r'sha-[0-9a-f]{40}', tag):
|
||||
raise SystemExit('Expected an immutable full-commit image tag')
|
||||
username = os.environ.get('DOCKERHUB_USERNAME', '')
|
||||
password = os.environ.get('DOCKERHUB_TOKEN', '')
|
||||
if not username or not password:
|
||||
raise SystemExit('Docker Hub credentials are required to resolve image digest')
|
||||
|
||||
token_url = endpoint('DOCKER_REGISTRY_TOKEN_URL', 'https://auth.docker.io',
|
||||
'/token?' + urlencode({'service': 'registry.docker.io',
|
||||
'scope': 'repository:' + repository + ':pull'}))
|
||||
registry_url = endpoint('DOCKER_REGISTRY_URL', 'https://registry-1.docker.io',
|
||||
'/v2/' + repository + '/manifests/' + tag)
|
||||
import base64
|
||||
credentials = base64.b64encode((username + ':' + password).encode()).decode('ascii')
|
||||
try:
|
||||
token_request = Request(token_url, headers={'Authorization': 'Basic ' + credentials,
|
||||
'Accept': 'application/json'})
|
||||
with urlopen(token_request, timeout=30) as response:
|
||||
token_data = json.load(response)
|
||||
bearer = token_data.get('token') or token_data.get('access_token')
|
||||
if not isinstance(bearer, str) or not bearer:
|
||||
raise SystemExit('Docker Hub did not return a registry bearer token')
|
||||
manifest_request = Request(registry_url, headers={
|
||||
'Authorization': 'Bearer ' + bearer,
|
||||
'Accept': ', '.join([
|
||||
'application/vnd.oci.image.index.v1+json',
|
||||
'application/vnd.docker.distribution.manifest.list.v2+json',
|
||||
'application/vnd.oci.image.manifest.v1+json',
|
||||
'application/vnd.docker.distribution.manifest.v2+json',
|
||||
]),
|
||||
})
|
||||
with urlopen(manifest_request, timeout=30) as response:
|
||||
digest = response.headers.get('Docker-Content-Digest', '')
|
||||
except (HTTPError, URLError, TimeoutError, OSError, ValueError):
|
||||
raise SystemExit('Unable to resolve immutable Docker Hub image digest')
|
||||
if not re.fullmatch(r'sha256:[0-9a-f]{64}', digest):
|
||||
raise SystemExit('Docker Hub returned an invalid image digest')
|
||||
print(digest)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -67,9 +67,8 @@ for component in server agent agent-gpu; do
|
||||
docker pull "$image:sha-$sha"
|
||||
revision=$(docker image inspect "$image:sha-$sha" --format '{{index .Config.Labels "org.opencontainers.image.revision"}}')
|
||||
[[ "$revision" == "$sha" ]] || { echo 'Pulled image does not match the versioned source commit' >&2; exit 1; }
|
||||
digests=$(docker image inspect "$image:sha-$sha" --format '{{range .RepoDigests}}{{println .}}{{end}}')
|
||||
[[ "$(printf '%s\n' "$digests" | sed '/^$/d' | wc -l)" == 1 ]] || { echo 'Expected one registry digest for the immutable image tag' >&2; exit 1; }
|
||||
printf '%s\n' "$digests" >> artifacts/image-digests.txt
|
||||
digest=$(python3 scripts/ci/dockerhub-tag-digest.py "$image" "sha-$sha")
|
||||
printf '%s@%s\n' "$image" "$digest" >> artifacts/image-digests.txt
|
||||
done
|
||||
cp artifacts/image-digests.txt artifacts/packages/image-digests.txt
|
||||
(cd artifacts/packages && sha256sum image-digests.txt >> SHA256SUMS)
|
||||
|
||||
@@ -14,7 +14,7 @@ Use this skill for changes to `.gitea/workflows/build.yml`, `scripts/ci/change_s
|
||||
- A push to `main` validates the changed source and builds/scans/pushes only affected images. The affected image gets immutable `sha-<full-sha>` and mutable `latest` tags on Docker Hub. Main pushes do not create Gitea releases.
|
||||
- Runs for the same ref are serialized so a slower older `main` run cannot overwrite a newer `latest` image.
|
||||
- A `MAJOR.MINOR.PATCH` tag (optional prerelease suffix allowed) is a version release. It validates the complete source and builds/scans server, Agent CPU, and Agent GPU images once each. The verified images are pushed to Docker Hub as `sha-<full-sha>` and the application version.
|
||||
- The tag release job does not build or scan Docker images. It pulls the already scanned immutable image refs to collect registry digests, then creates a signed Gitea release containing `heimdall-installers-<version>.zip`, framework-dependent Agent archives, the public key, signed update manifest, and CPU/GPU image digest manifests. Build provenance, image-digest bookkeeping, and checksums stay in CI package output and are not uploaded as end-user release assets. It never uploads Docker image archives to Gitea.
|
||||
- The tag release job does not build or scan Docker images. It pulls the already scanned immutable image refs to verify their source revision, then resolves canonical digests from Docker Hub Registry v2 using the immutable commit tags. It creates a signed Gitea release containing `heimdall-installers-<version>.zip`, framework-dependent Agent archives, the public key, signed update manifest, and CPU/GPU image digest manifests. Local Docker `RepoDigests` can contain multiple values and must not be used as a uniqueness check. Build provenance, image-digest bookkeeping, and checksums stay in CI package output and are not uploaded as end-user release assets. It never uploads Docker image archives to Gitea.
|
||||
- The package script uses fast gzip compression for the framework-dependent release archives to reduce release-job CPU time; keep the archive names and layout stable for Linux and Windows installers.
|
||||
- The installer ZIP preserves the `install/` and `docker/` layout consumed by the Linux and Windows server installers. A raw-branch `.sh` or `.ps1` bootstrap resolves Gitea's latest stable version (or an explicit `HEIMDALL_INSTALLER_VERSION`), verifies the Gitea SHA-256 asset digest, downloads that version's ZIP, and runs its version-pinned script. Versioned bundle scripts pin their source assets and server image to the same tag and do not resolve a moving release. Direct Agent install scripts served by Central continue to download Agent payloads through Central's configured Gitea release API.
|
||||
- Gitea release creation is idempotent by version tag. A release remains draft until every expected asset is uploaded; stable versions publish as releases and versions with a prerelease suffix publish as prereleases.
|
||||
|
||||
Reference in new issue
Block a user