Skip to content

Commit 90071ec

Browse files
authored
Merge pull request #21 from GitHubSecurityLab/jarlob/attestation
Add attestation
2 parents 6f3beaa + 4d9e2e7 commit 90071ec

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

.github/workflows/release.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ on:
99
default: 'latest'
1010

1111
permissions:
12-
contents: read
13-
packages: write
12+
id-token: write
13+
contents: read
14+
attestations: write
15+
packages: write
16+
17+
env:
18+
REGISTRY: ghcr.io
19+
USER: githubsecuritylab
20+
IMAGE_NAME: seclab-taskflow-agent
1421

1522
jobs:
1623
release:
@@ -25,6 +32,22 @@ jobs:
2532
python-version: '3.11'
2633

2734
- name: Create release
35+
id: docker_build
36+
run: |
37+
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
38+
python release_tools/publish_docker.py release.txt main.py ${{ env.REGISTRY }}/${{ env.USER }}/${{ env.IMAGE_NAME }} ${{ github.event.inputs.release_tag }}
39+
DIGEST=$(cat /tmp/digest.txt)
40+
echo "digest=$DIGEST" >> $GITHUB_OUTPUT
41+
42+
- name: Generate artifact attestation
43+
uses: actions/attest-build-provenance@v3
44+
with:
45+
subject-name: ${{ env.REGISTRY }}/${{ env.USER }}/${{ env.IMAGE_NAME }}
46+
subject-digest: '${{ steps.docker_build.outputs.digest }}'
47+
push-to-registry: true
48+
49+
- name: Verify
50+
env:
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2852
run: |
29-
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u GitHubSecurityLab --password-stdin
30-
python release_tools/publish_docker.py release.txt main.py ghcr.io/githubsecuritylab/seclab-taskflow-agent ${{ github.event.inputs.release_tag }}
53+
gh attestation verify oci://ghcr.io/${{ env.USER }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.release_tag }} -R ${{ github.repository }}

release_tools/publish_docker.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ def write_dockerfile(dest_dir, entrypoint):
8282
with open(os.path.join(dest_dir, "Dockerfile"), "w") as f:
8383
f.write(dockerfile)
8484

85+
def get_image_digest(image_name, tag):
86+
result = subprocess.run(
87+
["docker", "buildx", "imagetools", "inspect", f"{image_name}:{tag}"],
88+
stdout=subprocess.PIPE, check=True, text=True
89+
)
90+
for line in result.stdout.splitlines():
91+
if line.strip().startswith("Digest:"):
92+
return line.strip().split(":", 1)[1].strip()
93+
return None
94+
8595
def build_and_push_image(dest_dir, image_name, tag):
8696
# Build
8797
subprocess.run([
@@ -92,6 +102,10 @@ def build_and_push_image(dest_dir, image_name, tag):
92102
"docker", "push", f"{image_name}:{tag}"
93103
], check=True)
94104
print(f"Pushed {image_name}:{tag}")
105+
digest = get_image_digest(image_name, tag)
106+
print(f"Image digest: {digest}")
107+
with open("/tmp/digest.txt", "w") as f:
108+
f.write(digest)
95109

96110
if __name__ == "__main__":
97111
if len(sys.argv) != 5:

0 commit comments

Comments
 (0)