chore: update actions syntax and fix some logic issues #2
Workflow file for this run
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
--- | ||
# Copyright 2024 Specter Ops, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 | ||
# 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. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
name: Docker Content Trust | ||
on: | ||
workflow_call: | ||
inputs: | ||
dockerhub_image_reference: | ||
type: string | ||
required: true | ||
description: > | ||
The full reference to the Docker image that needs to be signed, | ||
including registry, repository name, and tag/digest (e.g. | ||
'organization/image:tag'). This image must already exist in DockerHub | ||
and be accessible with the provided credentials. | ||
docker_content_trust_server: | ||
type: string | ||
default: https://notary.docker.io | ||
secrets: | ||
gh_access_token: | ||
required: true | ||
dockerhub_account: | ||
required: true | ||
dockerhub_token: | ||
required: true | ||
docker_content_trust_repository_key_id: | ||
required: true | ||
docker_content_trust_repository_passphrase: | ||
required: true | ||
docker_content_trust_repository_key: | ||
required: true | ||
docker_content_trust_repository_public_key: | ||
required: true | ||
jobs: | ||
sign-image: | ||
name: Sign Image | ||
runs-on: ubuntu-latest | ||
env: | ||
DOCKER_CONTENT_TRUST: 1 | ||
DOCKER_CONTENT_TRUST_SERVER: ${{ inputs.docker_content_trust_server }} | ||
steps: | ||
- uses: docker/login-action@v3 | ||
name: Authenticate with DockerHub Registry | ||
with: | ||
registry: docker.io | ||
username: ${{ secrets.dockerhub_account }} | ||
password: ${{ secrets.dockerhub_token }} | ||
- name: Prepare Docker Content Trust Credentials | ||
DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE: ${{ secrets.docker_content_trust_repository_passphrase }} | ||
shell: bash | ||
run: | | ||
mkdir -p ~/.docker/trust/private/ | ||
# Writing docker content trust key | ||
# Set appropriate file permissions for the docker content trust key | ||
touch ~/.docker/trust/private/${{ secrets.docker_content_trust_repository_key_id }}.key | ||
chmod 600 ~/.docker/trust/private/${{ secrets.docker_content_trust_repository_key_id }}.key | ||
echo "${{ secrets.docker_content_trust_repository_key }}" > ~/.docker/trust/private/${{ secrets.docker_content_trust_repository_key_id }}.key | ||
# Load docker content trust key | ||
docker trust key load ~/.docker/trust/private/${{ secrets.docker_content_trust_repository_key_id }}.key | ||
# TODO: make sure this works with DOCKER_CONTENT_TRUST set | ||
- name: Pull Image | ||
shell: bash | ||
run: docker pull ${{ inputs.dockerhub_image_reference }} | ||
- name: Signing Image | ||
env: | ||
DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE: ${{ secrets.docker_content_trust_repository_passphrase }} | ||
shell: bash | ||
run: docker trust sign --local ${{ inputs.dockerhub_image_reference }} | ||
- name: Inspect Signed Image | ||
run: docker trust inspect --pretty ${{ inputs.dockerhub_image_reference }} | ||
- name: Remove Prepared Docker Content Trust Credentials | ||
if: always() | ||
shell: bash | ||
run: rm -rvf ~/.docker/trust/private/ |