Skip to content

Commit fd17bc1

Browse files
authored
fix: missing token handling (#90)
1 parent 2e7145d commit fd17bc1

File tree

2 files changed

+10
-35
lines changed

2 files changed

+10
-35
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Only GitHub Container Registry (ghcr.io) is supported so far.
9090

9191
# Example, Single Build
9292

93-
Build a single subfolder with a Dockerfile in it. Deletes old packages, keeping the last 50. Runs on pull requests (PRs).
93+
Build a single subfolder with a Dockerfile in it. Runs on pull requests (PRs).
9494

9595
```yaml
9696
builds:

action.yml

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -219,53 +219,28 @@ runs:
219219
path: sboms/
220220
if-no-files-found: error
221221

222-
- name: Check attestation permissions
223-
id: check_permissions
222+
- name: Attestation
223+
continue-on-error: true
224+
id: attestation
224225
if: steps.build.outputs.triggered == 'true'
225-
shell: bash
226-
run: |
227-
# Get workflow permissions
228-
PERMISSIONS=$(curl -s -H "Authorization: Bearer ${{ inputs.token }}" \
229-
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/${{ github.workflow }}/permissions")
230-
231-
# Check for both id-token:write and attestations:write permissions
232-
if echo "$PERMISSIONS" | grep -q '"id-token":[[:space:]]*"write"' && \
233-
echo "$PERMISSIONS" | grep -q '"attestations":[[:space:]]*"write"'
234-
then
235-
echo "Both id-token:write and attestations:write permissions are available"
236-
echo "has_permissions=true" >> $GITHUB_OUTPUT
237-
else
238-
echo "Missing required permissions. Both id-token:write and attestations:write are needed for attestation"
239-
fi
240-
241-
- name: Attest
242226
uses: actions/attest@v2.3.0
243-
if: steps.build.outputs.triggered == 'true' && steps.check_permissions.outputs.has_permissions == 'true'
244227
with:
245228
subject-name: ghcr.io/${{ github.event.repository.name }}/${{ inputs.package }}
246229
subject-digest: ${{ steps.build_and_push.outputs.digest }}
247230
predicate-type: 'https://in-toto.io/attestation/release/v0.1'
248231
predicate: '{"purl":"pkg:oci/${{ github.event.repository.name }}/${{ inputs.package }}"}'
249232

233+
- name: Prompt user to fix permissions
234+
if: steps.attestation.outcome == 'failure'
235+
shell: bash
236+
run: |
237+
echo "::warning::Attestation skipped due to missing id-token:write and attestations:write permissions. Please update workflow permissions."
238+
250239
# Action repo needs to be present for cleanup/tests
251240
- name: Checkout local repo to make sure action.yml is present
252241
if: github.repository != inputs.repository
253242
uses: actions/checkout@v4
254243

255-
# Get the digest of the built image from the build-push-action output
256-
- name: Validate digest
257-
env:
258-
IMAGE: ghcr.io/${{ steps.vars.outputs.repo_lower }}/${{ steps.vars.outputs.package_lower }}@${{ steps.build_and_push.outputs.digest }}
259-
id: digest
260-
if: steps.build.outputs.triggered == 'true'
261-
shell: bash
262-
run: |
263-
# Validate digest using docker manifest inspect (faster than docker pull)
264-
if ! docker manifest inspect "$IMAGE" > /dev/null; then
265-
echo "Error: Failed to inspect manifest for $IMAGE" >&2
266-
exit 1
267-
fi
268-
269244
- name: Print summary outputs
270245
shell: bash
271246
run: |

0 commit comments

Comments
 (0)