-
Notifications
You must be signed in to change notification settings - Fork 8
Adopt zizmor GitHub Actions security scanning tool #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
82f9c9c
Add create release branch action
blink1073 e40f6cd
cleanup
blink1073 a0dc7ec
Add udpate branch script
blink1073 6686d4e
fix silk handling
blink1073 a246211
fix sbom handling
blink1073 b92d769
debug
blink1073 9e7885f
fix image
blink1073 d5f074b
fix and debug
blink1073 07f4f94
debug
blink1073 12922d5
debug
blink1073 cb7640e
debug
blink1073 cc0a6b4
try again
blink1073 32bf864
cleanup
blink1073 014002d
fix up release handling
blink1073 3944d31
uncomment
blink1073 6a9cedd
remove extra file
blink1073 c6d6e09
Apply recommended security fixes
blink1073 744d044
add workflow
blink1073 cfa8d81
Merge branch 'main' of github.com:mongodb-labs/drivers-github-tools i…
blink1073 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ jobs: | |
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: actions/setup-python@v5 | ||
| - uses: pre-commit/[email protected] | ||
| with: | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| name: GitHub Actions Security Analysis with zizmor 🌈 | ||
|
|
||
| on: | ||
| push: | ||
| branches: ["main"] | ||
| pull_request: | ||
| branches: ["**"] | ||
|
|
||
| jobs: | ||
| zizmor: | ||
| name: zizmor latest via Cargo | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| security-events: write | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
| - name: Setup Rust | ||
| uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
| - name: Get zizmor | ||
| run: cargo install zizmor | ||
| - name: Run zizmor 🌈 | ||
| run: zizmor --format sarif . > results.sarif | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Upload SARIF file | ||
| uses: github/codeql-action/upload-sarif@v3 | ||
| with: | ||
| sarif_file: results.sarif | ||
| category: zizmor |
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| name: Create Release Branch | ||
| description: Create a release branch and update branch metadata | ||
| inputs: | ||
| # User provided inputs. | ||
| branch_name: | ||
| description: The name of the new branch | ||
| required: true | ||
| version: | ||
| description: The version to set on the branch | ||
| required: true | ||
| base_ref: | ||
| description: The base reference for the branch | ||
| push_changes: | ||
| description: Whether to push the changes | ||
| default: "true" | ||
| # Workflow provided inputs. | ||
| version_bump_script: | ||
| description: The script used to bump the version | ||
| required: true | ||
| evergreen_project: | ||
| description: The name of the evergreen project for the new branch | ||
| required: true | ||
| release_workflow_path: | ||
| description: The path to the release workflow file | ||
| default: .github/workflows/release.yml | ||
| sbom_file_path: | ||
| description: The path of the sbom-lite file | ||
| default: sbom.json | ||
| silk_group_prefix: | ||
| description: The prefix to use for the silk asset group, defaults to the repo name | ||
| artifactory_image: | ||
| description: Image to use for artifactory | ||
| default: artifactory.corp.mongodb.com/release-tools-container-registry-public-local | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Create a release branch and update branch metadata | ||
| shell: bash | ||
| env: | ||
| BRANCH: ${{ inputs.branch_name }} | ||
| BASE_REF: ${{ inputs.base_ref }} | ||
| SBOM_FILE_PATH: ${{ inputs.sbom_file_path }} | ||
| RELEASE_WORKFLOW_PATH: ${{ inputs.release_workflow_path }} | ||
| EVERGREEN_PROJECT: ${{ inputs.evergreen_project }} | ||
| SILK_PREFIX: ${{ inputs.silk_group_prefix }} | ||
| ARTIFACTORY_IMAGE: ${{ inputs.artifactory_image }} | ||
| run: ${{ github.action_path }}/create-branch.sh | ||
| - uses: mongodb-labs/drivers-github-tools/bump-version@v2 | ||
| with: | ||
| version: ${{ inputs.version }} | ||
| version_bump_script: ${{ inputs.version_bump_script }} | ||
| commit_template: "Prep branch ${{ inputs.branch_name }}" | ||
| push_commit: ${{ inputs.push_changes }} |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #! /bin/bash | ||
| set -eu | ||
|
|
||
| echo "Create or checkout the branch." | ||
| OWNER_REPO="${GITHUB_REPOSITORY}" | ||
| git ls-remote --exit-code --heads https://github.com/${OWNER_REPO}.git refs/heads/$BRANCH || { | ||
| git branch $BRANCH $BASE_REF | ||
| } | ||
| git fetch origin $BRANCH || true | ||
| git checkout $BRANCH | ||
|
|
||
| echo "Get silk creds." | ||
| # shellcheck disable=SC2046 | ||
| export $(grep -v '^#' $SILKBOMB_ENVFILE | xargs -0) | ||
|
|
||
| echo "Get a silk token." | ||
| SILK_JWT_TOKEN=$(curl -s -X POST "https://silkapi.us1.app.silk.security/api/v1/authenticate" \ | ||
| -H "accept: application/json" -H "Content-Type: application/json" \ | ||
| -d '{ "client_id": "'${SILK_CLIENT_ID}'", "client_secret": "'${SILK_CLIENT_SECRET}'" }' \ | ||
| | jq -r '.token') | ||
|
|
||
| echo "Get the silk asset group prefix." | ||
| if [ -z "${SILK_PREFIX:-}" ]; then | ||
| REPO="${OWNER_REPO##*/}" | ||
| SILK_PREFIX=${REPO} | ||
| fi | ||
| SILK_GROUP="${SILK_PREFIX}-${BRANCH}" | ||
|
|
||
| echo "Create the silk asset group." | ||
| json_payload=$(cat <<EOF | ||
| { | ||
| "active": true, | ||
| "name": "${SILK_GROUP}", | ||
| "code_repo_url": "https://github.com/${OWNER_REPO}", | ||
| "branch": "${BRANCH}", | ||
| "metadata": { | ||
| "sbom_lite_path": "${SBOM_FILE_PATH}" | ||
| }, | ||
| "file_paths": [], | ||
| "asset_id": "$SILK_GROUP" | ||
| } | ||
| EOF | ||
| ) | ||
| curl -X 'POST' \ | ||
| 'https://silkapi.us1.app.silk.security/api/v1/raw/asset_group' \ | ||
| -H "accept: application/json" -H "Authorization: ${SILK_JWT_TOKEN}" \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d "$json_payload" | ||
|
|
||
| echo "SILK_ASSET_GROUP=$SILK_GROUP" >> $GITHUB_STEP_SUMMARY | ||
|
|
||
| echo "Create a temp sbom." | ||
| TMP_SBOM=sbom-for-${BRANCH}.json | ||
| podman run --platform="linux/amd64" --rm -v "$(pwd)":/pwd \ | ||
| ${ARTIFACTORY_IMAGE}/silkbomb:1.0 \ | ||
| update --sbom-out /pwd/${TMP_SBOM} | ||
|
|
||
| echo "Get the new timestamp and serial number." | ||
| set -x | ||
| SERIAL=$(jq -r '.serialNumber' ${TMP_SBOM}) | ||
| TIMESTAMP=$(jq -r '.metadata.timestamp' ${TMP_SBOM}) | ||
| rm ${TMP_SBOM} | ||
|
|
||
| cat ${SBOM_FILE_PATH} | ||
| echo "Replace the values in the existing sbom." | ||
| cat <<< "$(jq --indent 4 '.serialNumber = "'${SERIAL}'"' ${SBOM_FILE_PATH})" > ${SBOM_FILE_PATH} | ||
| cat <<< "$(jq --indent 4 '.metadata.timestamp = "'${TIMESTAMP}'"' ${SBOM_FILE_PATH})" > ${SBOM_FILE_PATH} | ||
| cat ${SBOM_FILE_PATH} | ||
|
|
||
| echo "Update the workflow with the silk asset group and evergreen project." | ||
| sed -i 's/SILK_ASSET_GROUP:.*/SILK_ASSET_GROUP: '${SILK_GROUP}'/' ${RELEASE_WORKFLOW_PATH} | ||
| sed -i 's/EVERGREEN_PROJECT:.*/EVERGREEN_PROJECT: '${EVERGREEN_PROJECT}'/' ${RELEASE_WORKFLOW_PATH} | ||
|
|
||
| echo "Add the changed files." | ||
| git --no-pager diff | ||
| git add ${SBOM_FILE_PATH} ${RELEASE_WORKFLOW_PATH} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't this already added by #59?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drat, forgot to create a new branch, reverting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, pulling from main resolved it.