Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a5df285
Add a generic container workflow
ianlewis Jul 1, 2022
212feb7
fix input
ianlewis Jul 1, 2022
7c9bd64
Merge branch 'main' into 409-feature-add-generic-container-workflow
ianlewis Jul 1, 2022
4821dc2
update hashes
ianlewis Jul 1, 2022
e6a8759
Avoid OIDC client creation errors on PRs
ianlewis Jul 1, 2022
036d351
Merge branch 'fix-detect-workflow-pr' into 409-feature-add-generic-co…
ianlewis Jul 1, 2022
1fba820
Add BUILDER_DIR to generic workflow
ianlewis Jul 1, 2022
9f34ac8
Merge branch 'fix-builder-dir' into 409-feature-add-generic-container…
ianlewis Jul 1, 2022
a41b963
Add BUILDER_DIR
ianlewis Jul 1, 2022
894ddf8
Fix args to builder
ianlewis Jul 1, 2022
b73ab0d
Merge branch 'main' into 409-feature-add-generic-container-workflow
ianlewis Jul 4, 2022
2185bbe
Merge branch 'main' into 409-feature-add-generic-container-workflow
ianlewis Jul 4, 2022
2652586
Merge remote-tracking branch 'origin/409-feature-add-generic-containe…
ianlewis Jul 5, 2022
f4ce48f
Sign the image as well
ianlewis Jul 5, 2022
99f70ed
don't sign for now
ianlewis Jul 5, 2022
d37c7e2
Updates to inputs and domain parsing
ianlewis Jul 5, 2022
9b4cf52
Add basic usage docs for container workflow
ianlewis Jul 5, 2022
8b548af
docs fixes
ianlewis Jul 6, 2022
7276289
Update example to use the image digest
ianlewis Jul 6, 2022
ed01d20
Add a separate digest input
ianlewis Jul 6, 2022
a15cb3d
Add digest input to docs
ianlewis Jul 6, 2022
05e7f7b
Update internal/builders/container/README.md
ianlewis Jul 7, 2022
06ee185
Merge branch 'main' into 409-feature-add-generic-container-workflow
ianlewis Jul 7, 2022
0cf0b49
Update comments
ianlewis Jul 7, 2022
a4a6922
comment out contents:read to test
ianlewis Jul 7, 2022
a7c38dc
comment out contents:read to test
ianlewis Jul 7, 2022
160b320
remove contents:read permissions
ianlewis Jul 7, 2022
c12b0a3
remove contents:read from docs
ianlewis Jul 7, 2022
421f3e3
Merge branch 'main' into 409-feature-add-generic-container-workflow
ianlewis Jul 10, 2022
cb48241
Fix repository domain check
ianlewis Jul 10, 2022
493a82a
Update docs
ianlewis Jul 11, 2022
d0c9e91
fix whitespace
ianlewis Jul 11, 2022
4c43a03
Merge branch 'main' into 409-feature-add-generic-container-workflow
ianlewis Jul 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions .github/workflows/generator_container_slsa3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Copyright 2022 SLSA Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: SLSA container image provenance

env:
# Generator
BUILDER_BINARY: generic-generator
BUILDER_RELEASE_BINARY: slsa-generator-generic-linux-amd64
BUILDER_REPOSITORY: slsa-framework/slsa-github-generator
# Verifier
# NOTE: These VERIFIER_* variables are used for verification of generator
# release binaries when the compile-generator input is false.
VERIFIER_REPOSITORY: slsa-framework/slsa-verifier
VERIFIER_RELEASE_BINARY: slsa-verifier-linux-amd64
VERIFIER_RELEASE_BINARY_SHA256: f92fc4e571949c796d7709bb3f0814a733124b0155e484fad095b5ca68b4cb21
VERIFIER_RELEASE: v1.1.1
# Builder location
BUILDER_DIR: internal/builders

on:
workflow_call:
secrets:
registry-password:
description: "Password to log in the container registry."
required: true
inputs:
image:
description: "The OCI image name. This must not include a tag or digest."
required: true
type: string
digest:
description: "The OCI image digest. The image digest of the form '<algorithm>:<digest>' (e.g. 'sha256:abcdef...')"
required: true
type: string
registry-username:
description: "Username to log into the container registry."
required: true
type: string
compile-generator:
description: "Build the generator from source. This increases build time by ~2m."
required: false
type: boolean
default: false

jobs:
# detect-env detects the reusable workflow's repository and ref for use later
# in the workflow.
detect-env:
outputs:
repository: ${{ steps.detect.outputs.repository }}
ref: ${{ steps.detect.outputs.ref }}
runs-on: ubuntu-latest
permissions:
id-token: write # Needed to detect the current reusable repository and ref.
steps:
- name: Detect the generator ref
id: detect
uses: slsa-framework/slsa-github-generator/.github/actions/detect-workflow@49e648aa7f5f4f88513b6cd54f6b189516184e6b

# generator builds the generator binary and runs it to generate SLSA
# provenance.
#
# If `compile-generator` is true then the generator is compiled
# from source at the ref detected by `detect-env`.
#
# If `compile-generator` is false, then the generator binary is downloaded
# with the release at the ref detected by `detect-env`. This must be a tag
# reference.
generator:
runs-on: ubuntu-latest
needs: [detect-env]
permissions:
# id-token:write is needed to create an OCID token for keyless signing.
id-token: write
# actions permissions are needed to read info on the workflow and
# workflow run.
actions: read
# packages:write permissions are needed to login and upload attestations.
packages: write
steps:
- name: Generate builder
uses: slsa-framework/slsa-github-generator/.github/actions/generate-builder@49e648aa7f5f4f88513b6cd54f6b189516184e6b
with:
repository: "${{ needs.detect-env.outputs.repository }}"
ref: "${{ needs.detect-env.outputs.ref }}"
go-version: 1.18
binary: "${{ env.BUILDER_BINARY }}"
compile-builder: "${{ inputs.compile-generator }}"
# NOTE: We are using the generic generator.
directory: "${{ env.BUILDER_DIR }}/generic"

- uses: sigstore/cosign-installer@7e0881f8fe90b25e305bbf0309761e9314607e25 # v2.4.0
- name: Login
env:
UNTRUSTED_IMAGE: "${{ inputs.image }}"
UNTRUSTED_USERNAME: "${{ inputs.registry-username }}"
UNTRUSTED_PASSWORD: "${{ secrets.registry-password }}"
run: |
set -euo pipefail

# NOTE: Some docker images are of the form <org>/<name>
# Here we get the first part and check if it has a '.' or ':'
# character in it to see if it's a domain name.
# See: https://stackoverflow.com/questions/37861791/how-are-docker-image-names-parsed#37867949
untrusted_registry="docker.io"
# NOTE: Do not fail the script if grep does not match.
maybe_domain=$(echo "$UNTRUSTED_IMAGE" | cut -f1 -d "/" | { grep -E "\.|:" || true; })
if [ "$maybe_domain" != "" ]; then
untrusted_registry="$maybe_domain"
fi

echo "login to $untrusted_registry"
cosign login "$untrusted_registry" -u "$UNTRUSTED_USERNAME" -p "$UNTRUSTED_PASSWORD"

- name: Create and sign provenance
id: sign-prov
shell: bash
env:
UNTRUSTED_IMAGE: "${{ inputs.image }}"
UNTRUSTED_DIGEST: "${{ inputs.digest }}"
GITHUB_CONTEXT: "${{ toJSON(github) }}"
run: |
set -euo pipefail

# Generate a predicate only.
predicate_name="predicate.json"
./"$BUILDER_BINARY" attest --signature="" --predicate="$predicate_name"

COSIGN_EXPERIMENTAL=1 cosign attest --predicate="$predicate_name" \
--type slsaprovenance \
--force \
"${UNTRUSTED_IMAGE}@${UNTRUSTED_DIGEST}"
Loading