Skip to content

Commit

Permalink
added trivy for vulns and sboms
Browse files Browse the repository at this point in the history
added cosign to sign container image and attestations
upgraded docker related actions
  • Loading branch information
garethahealy committed Dec 2, 2023
1 parent a8e0e9f commit f9f9011
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 10 deletions.
60 changes: 56 additions & 4 deletions .github/workflows/pr-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ jobs:
run: make

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug

Expand All @@ -255,6 +255,23 @@ jobs:
platforms: ${{ matrix.platform }}
push: false
tags: "${{ env.OPERATOR_IMAGE_REPOSITORY }}:latest-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }},${{ env.OPERATOR_IMAGE_REPOSITORY }}:${{ env.OPERATOR_VERSION }}-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}"
load: true

- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
scan-type: image
image-ref: ${{ env.OPERATOR_IMAGE_REPOSITORY }}:latest-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}
format: "cosign-vuln"
output: "operator-cosignvuln.json"

- name: Run Trivy SBOM generator
uses: aquasecurity/[email protected]
with:
scan-type: image
image-ref: ${{ env.OPERATOR_IMAGE_REPOSITORY }}:latest-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}
format: "spdx-json"
output: "operator-spdxjson.json"

- name: Prepare Distribution Artifacts
shell: bash
Expand All @@ -264,13 +281,22 @@ jobs:
# Move and Rename Manager Binary
mv bin/manager dist/${{ env.REPOSITORY_NAME }}-manager-${{ env.OPERATOR_VERSION }}-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}
mkdir attestation
mv operator-*.json attestation
- name: Upload Dist
uses: actions/upload-artifact@v3
with:
name: dist
path: dist

- name: Upload attestation
uses: actions/upload-artifact@v3
with:
name: attestation
path: attestation

build-bundle:
runs-on: ubuntu-latest
name: build-bundle
Expand Down Expand Up @@ -339,10 +365,10 @@ jobs:
run: operator-sdk bundle validate ./bundle --select-optional name=operatorhub

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: "Build Bundle Image"
uses: docker/build-push-action@v3
Expand All @@ -353,6 +379,23 @@ jobs:
platforms: ${{ matrix.platform }}
push: false
tags: "${{ env.BUNDLE_IMAGE_REPOSITORY }}:latest-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }},${{ env.BUNDLE_IMAGE_REPOSITORY }}:${{ env.BUNDLE_VERSION }}-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}"
load: true

- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
scan-type: image
image-ref: ${{ env.BUNDLE_IMAGE_REPOSITORY }}:latest-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}
format: "cosign-vuln"
output: "bundle-cosignvuln.json"

- name: Run Trivy SBOM generator
uses: aquasecurity/[email protected]
with:
scan-type: image
image-ref: ${{ env.BUNDLE_IMAGE_REPOSITORY }}:latest-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}
format: "spdx-json"
output: "bundle-spdxjson.json"

- name: Prepare Distribution Artifacts
shell: bash
Expand All @@ -365,13 +408,22 @@ jobs:
tar -czvf ${{ env.REPOSITORY_NAME }}-bundle-${{ env.OPERATOR_VERSION }}-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}.tar.gz ${{ env.REPOSITORY_NAME }}-bundle-${{ env.OPERATOR_VERSION }}-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}
mv ${{ env.REPOSITORY_NAME }}-bundle-${{ env.OPERATOR_VERSION }}-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}.tar.gz dist
rm -Rf ${{ env.REPOSITORY_NAME }}-bundle-${{ env.OPERATOR_VERSION }}-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}
mkdir attestation
mv bundle-*.json attestation
- name: Upload Dist
uses: actions/upload-artifact@v3
with:
name: dist
path: dist

- name: Upload attestation
uses: actions/upload-artifact@v3
with:
name: attestation
path: attestation

package-helm:
runs-on: ubuntu-latest
name: package-helm
Expand Down
112 changes: 106 additions & 6 deletions .github/workflows/release-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ jobs:
OPERATOR_IMAGE_REGISTRY: ${{ needs.setup.outputs.operator_image_registry }}
BUNDLE_IMAGE_REPOSITORY: "${{ needs.setup.outputs.bundle_image_registry }}/${{ needs.setup.outputs.bundle_image_repository_name }}"
BUNDLE_IMAGE_REGISTRY: ${{ needs.setup.outputs.bundle_image_registry }}
permissions:
contents: read
id-token: write

steps:
- name: Set up Go
Expand All @@ -233,6 +236,18 @@ jobs:
- name: Check out code
uses: actions/checkout@v4

- name: Validate variables
run: |
if [ "${{ needs.setup.outputs.operator_image_registry }}" == "" ]; then
echo "Required setup outputs 'operator_image_registry' is not set. Check setup 'Complete Job' step."
exit 1
fi
if [ "${{ needs.setup.outputs.bundle_image_registry }}" == "" ]; then
echo "Required setup outputs 'bundle_image_registry' is not set. Check setup 'Complete Job' step."
exit 1
fi
- name: Go Build Cache
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -280,21 +295,26 @@ jobs:
run: make

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug

- name: Setup cosign
uses: sigstore/cosign-installer@v3

- name: Login to Operator Registry
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ${{ env.OPERATOR_IMAGE_REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- name: "Build Operator Image"
uses: docker/build-push-action@v3
id: build_push
with:
context: .
file: "./ci.Dockerfile"
Expand All @@ -303,6 +323,42 @@ jobs:
push: true
tags: "${{ env.OPERATOR_IMAGE_REPOSITORY }}:latest-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }},${{ env.OPERATOR_IMAGE_REPOSITORY }}:${{ env.OPERATOR_VERSION }}-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}"

- name: Sign Operator Image
id: sign_operator
env:
IMAGE_URI: ${{ env.OPERATOR_IMAGE_REPOSITORY }}@${{ steps.build_push.outputs.digest }}
run: |
cosign sign --yes ${IMAGE_URI}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
env:
TRIVY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
TRIVY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
with:
scan-type: image
image-ref: ${{ env.OPERATOR_IMAGE_REPOSITORY }}@${{ steps.build_push.outputs.digest }}
format: "cosign-vuln"
output: "cosign-vuln.json"

- name: Run Trivy SBOM generator
uses: aquasecurity/[email protected]
env:
TRIVY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
TRIVY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
with:
scan-type: image
image-ref: ${{ env.OPERATOR_IMAGE_REPOSITORY }}@${{ steps.build_push.outputs.digest }}
format: "spdx-json"
output: "spdx-json.json"

- name: Attach attestations for Operator Image
env:
IMAGE_URI: ${{ env.OPERATOR_IMAGE_REPOSITORY }}@${{ steps.build_push.outputs.digest }}
run: |
cosign attest --yes --type vuln --predicate cosign-vuln.json ${IMAGE_URI}
cosign attest --yes --type spdx --predicate spdx-json.json ${IMAGE_URI}
- name: Prepare Distribution Artifacts
shell: bash
run: |
Expand Down Expand Up @@ -376,6 +432,10 @@ jobs:
OPERATOR_IMAGE_REGISTRY: ${{ needs.setup.outputs.operator_image_registry }}
BUNDLE_IMAGE_REPOSITORY: "${{ needs.setup.outputs.bundle_image_registry }}/${{ needs.setup.outputs.bundle_image_repository_name }}"
BUNDLE_IMAGE_REGISTRY: ${{ needs.setup.outputs.bundle_image_registry }}
permissions:
contents: read
id-token: write

steps:
- name: Set up Go
uses: actions/setup-go@v4
Expand Down Expand Up @@ -435,20 +495,24 @@ jobs:
run: operator-sdk bundle validate ./bundle --select-optional name=operatorhub

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Setup cosign
uses: sigstore/cosign-installer@v3

- name: Login to Bundle Registry
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ${{ env.BUNDLE_IMAGE_REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- name: "Build Bundle Image"
uses: docker/build-push-action@v3
id: build_push
with:
context: .
file: ./bundle.Dockerfile
Expand All @@ -457,6 +521,42 @@ jobs:
push: true
tags: "${{ env.BUNDLE_IMAGE_REPOSITORY }}:latest-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }},${{ env.BUNDLE_IMAGE_REPOSITORY }}:${{ env.BUNDLE_VERSION }}-${{ steps.setup-build-step.outputs.platform_os }}-${{ steps.setup-build-step.outputs.platform_arch }}"

- name: Sign Bundle Image
id: sign_bundle
env:
IMAGE_URI: ${{ env.BUNDLE_IMAGE_REPOSITORY }}@${{ steps.build_push.outputs.digest }}
run: |
cosign sign --yes ${IMAGE_URI}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
env:
TRIVY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
TRIVY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
with:
scan-type: image
image-ref: ${{ env.BUNDLE_IMAGE_REPOSITORY }}@${{ steps.build_push.outputs.digest }}
format: "cosign-vuln"
output: "cosign-vuln.json"

- name: Run Trivy SBOM generator
uses: aquasecurity/[email protected]
env:
TRIVY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
TRIVY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
with:
scan-type: image
image-ref: ${{ env.BUNDLE_IMAGE_REPOSITORY }}@${{ steps.build_push.outputs.digest }}
format: "spdx-json"
output: "spdx-json.json"

- name: Attach attestations for Bundle Image
env:
IMAGE_URI: ${{ env.BUNDLE_IMAGE_REPOSITORY }}@${{ steps.build_push.outputs.digest }}
run: |
cosign attest --yes --type vuln --predicate cosign-vuln.json ${IMAGE_URI}
cosign attest --yes --type spdx --predicate spdx-json.json ${IMAGE_URI}
- name: Prepare Distribution Artifacts
shell: bash
run: |
Expand Down

0 comments on commit f9f9011

Please sign in to comment.