Skip to content

Commit 758532a

Browse files
authored
ci: run Snyk scans only when SNYK_TOKEN is configured (cloudnative-pg#10813)
Gate both Snyk integrations on the presence of the SNYK_TOKEN secret. The Docker image scan in continuous-integration.yml previously keyed off the repository fork flag, and the Snyk scanning workflow keyed off the repository owner. Repositories that do not configure the secret now skip the scans automatically. Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
1 parent 58d07b8 commit 758532a

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

.github/workflows/continuous-integration.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ jobs:
451451
catalog_img: ${{ env.CATALOG_IMG }}
452452
push: ${{ env.PUSH }}
453453
images_matrix: ${{ steps.images_matrix.outputs.images_matrix }}
454+
env:
455+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
454456
steps:
455457
- name: Checkout
456458
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
@@ -637,11 +639,9 @@ jobs:
637639

638640
- name: Run Snyk to check Docker image for vulnerabilities
639641
uses: snyk/actions/docker@8e119fbb6c251787721d34ba683ed48eba792766 # master
640-
if: |
641-
!github.event.repository.fork &&
642-
!github.event.pull_request.head.repo.fork
643-
env:
644-
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
642+
# Only run when a Snyk token is configured. Forks and downstream
643+
# repositories without the secret skip this step automatically.
644+
if: env.SNYK_TOKEN != ''
645645
with:
646646
image: ${{ env.CONTROLLER_IMG }}
647647
args: --severity-threshold=high --file=Dockerfile --username=${{ env.REGISTRY_USER }} --password=${{ env.REGISTRY_PASSWORD }}

.github/workflows/snyk.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,23 @@ on:
1111
permissions: read-all
1212

1313
jobs:
14+
# Expose whether a Snyk token is configured so the security job can gate
15+
# on it. The secrets context is not available in a job-level 'if', so it
16+
# is checked here and surfaced as a job output.
17+
check-secret:
18+
name: Check for Snyk token
19+
runs-on: ubuntu-24.04
20+
outputs:
21+
has_token: ${{ steps.check.outputs.has_token }}
22+
steps:
23+
- id: check
24+
env:
25+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
26+
run: echo "has_token=${{ env.SNYK_TOKEN != '' }}" >> "$GITHUB_OUTPUT"
27+
1428
security:
15-
if: ${{ github.repository_owner == 'cloudnative-pg' }}
29+
needs: check-secret
30+
if: ${{ needs.check-secret.outputs.has_token == 'true' }}
1631
name: Security scan
1732
runs-on: ubuntu-24.04
1833
permissions:

0 commit comments

Comments
 (0)