|
| 1 | +name: image-signed-cosign(latest,daily)-malicious |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + |
| 5 | +env: |
| 6 | + REGISTRY: ghcr.io |
| 7 | + IMAGE_NAME: ${{ github.repository }} |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + packages: write |
| 15 | + id-token: write |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 |
| 20 | + |
| 21 | + - name: The malicious step |
| 22 | + run: | |
| 23 | + echo "# This is a malicious update" >> app.py |
| 24 | +
|
| 25 | + - name: Install Cosign |
| 26 | + |
| 27 | + |
| 28 | + - name: Setup Docker buildx |
| 29 | + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf |
| 30 | + |
| 31 | + - name: Log into registry ${{ env.REGISTRY }} |
| 32 | + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c |
| 33 | + with: |
| 34 | + registry: ${{ env.REGISTRY }} |
| 35 | + username: ${{ github.actor }} |
| 36 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + - name: Extract Docker metadata |
| 39 | + id: meta |
| 40 | + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 |
| 41 | + with: |
| 42 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 43 | + tags: | |
| 44 | + type=raw,value=latest |
| 45 | + type=raw,value=daily |
| 46 | +
|
| 47 | + - name: Build and push Docker image |
| 48 | + id: build-and-push |
| 49 | + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a |
| 50 | + with: |
| 51 | + context: . |
| 52 | + push: ${{ github.event_name != 'pull_request' }} |
| 53 | + tags: ${{ steps.meta.outputs.tags }} |
| 54 | + labels: ${{ steps.meta.outputs.labels }} |
| 55 | + cache-from: type=gha |
| 56 | + cache-to: type=gha,mode=max |
| 57 | + |
| 58 | + - name: Sign the published Docker image |
| 59 | + env: |
| 60 | + TAGS: ${{ steps.meta.outputs.tags }} |
| 61 | + DIGEST: ${{ steps.build-and-push.outputs.digest }} |
| 62 | + run: | |
| 63 | + cosign version |
| 64 | + echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} |
0 commit comments