SLSA for ML models example #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: SLSA for ML models example | |
on: | |
workflow_dispatch: | |
inputs: | |
model_type: | |
description: Name of the model (implies framework) | |
required: true | |
type: choice | |
options: | |
- tensorflow_model.keras | |
- tensorflow_hdf5_model.h5 | |
- tensorflow_hdf5.weights.h5 | |
- pytorch_model.pth | |
- pytorch_full_model.pth | |
- pytorch_jitted_model.pt | |
permissions: read-all | |
jobs: | |
train: | |
name: Train model and save as ${{ github.event.inputs.model_type }} | |
runs-on: ubuntu-latest | |
outputs: | |
hash: ${{ steps.hash.outputs.hash }} | |
steps: | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1 | |
with: | |
python-version: 3.11 | |
cache: pip | |
cache-dependency-path: slsa_for_models/install/requirements.txt | |
- name: Install dependencies | |
run: | | |
set -euo pipefail | |
python -m venv venv | |
source venv/bin/activate | |
python -m pip install --require-hashes -r slsa_for_models/install/requirements.txt | |
- name: Build model | |
env: | |
MODEL_TYPE: ${{ github.event.inputs.model_type }} | |
run: | | |
set -euo pipefail | |
source venv/bin/activate | |
python slsa_for_models/main.py "$MODEL_TYPE" | |
- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 | |
with: | |
path: ${{ github.event.inputs.model_type }} | |
name: ${{ github.event.inputs.model_type }} | |
if-no-files-found: error | |
- id: hash | |
env: | |
MODEL: ${{ github.event.inputs.model_type }} | |
run: | | |
set -euo pipefail | |
sha256sum "$MODEL" > checksum | |
echo "hash=$(cat checksum | base64 -w0)" >> "${GITHUB_OUTPUT}" | |
provenance: | |
needs: [train] | |
permissions: | |
actions: read | |
id-token: write | |
contents: write | |
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0 | |
with: | |
base64-subjects: "${{ needs.train.outputs.hash }}" | |
upload-assets: true # NOTE: This does nothing unless 'upload-tag-name' parameter is also set to an existing tag |