Repository navigation
139 lines (133 loc) · 5.83 KB
/
Copy pathsecurity-scan.yaml
File metadata and controls
139 lines (133 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Security scan
# Nightly Trivy scans: every image the chart deploys (the artifacthub.io/images
# annotation, which hack/chart-images.sh keeps equal to values.yaml) and the
# manifests each ci/ scenario renders. Results go to code scanning once the
# repository is public; until then they're in the job logs and summaries.
# Code scanning only gets findings someone can act on: medium or above for the
# manifests; high or above with a fixed version for images. The job summaries
# keep unfixed high and critical findings visible.
on:
schedule:
- cron: "37 4 * * *"
workflow_dispatch:
permissions:
contents: read
env:
# Run from the image, pinned by digest, rather than an installer action.
TRIVY_IMAGE: docker.io/aquasec/trivy:0.75.0@sha256:af6acf9a6b85dfe389a1941505c0ce9efef52a4719635e1a962f022a3d855daa
jobs:
prepare:
name: Images and visibility
runs-on: ${{ format('gcrunner={0}-prepare-{1}/machine=c3d-standard-4', github.run_id, strategy.job-index) }}
outputs:
images: ${{ steps.images.outputs.images }}
public: ${{ steps.repo.outputs.public }}
steps:
- uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: List the chart's images
id: images
run: |
hack/chart-images.sh --check
images=$(yq -o json -I 0 '.annotations["artifacthub.io/images"] | from_yaml' charts/appwrite/Chart.yaml)
echo "$images" | jq .
echo "images=${images}" >> "$GITHUB_OUTPUT"
# Scheduled events carry no repository in their payload, so ask the API.
- name: Repository visibility
id: repo
env:
GH_TOKEN: ${{ github.token }}
run: |
visibility=$(gh api "repos/${GITHUB_REPOSITORY}" --jq .visibility)
echo "public=$([[ "$visibility" == public ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"
images:
name: Image ${{ matrix.image.name }}
needs: prepare
runs-on: ${{ format('gcrunner={0}-images-{1}/machine=c3d-standard-4', github.run_id, strategy.job-index) }}
permissions:
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
image: ${{ fromJSON(needs.prepare.outputs.images) }}
steps:
- uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
with:
egress-policy: audit
- name: trivy image
env:
IMAGE: ${{ matrix.image.image }}
run: |
trivy() {
docker run --rm -v "${RUNNER_TEMP}:/out" -v trivy-cache:/root/.cache "$TRIVY_IMAGE" "$@"
}
trivy image --scanners vuln --format json --output /out/image.json "$IMAGE"
jq '(.Results[]? | select(.Vulnerabilities) | .Vulnerabilities) |= map(select(.FixedVersion // "" | length > 0))' \
"${RUNNER_TEMP}/image.json" > "${RUNNER_TEMP}/fixable.json"
trivy convert --severity HIGH,CRITICAL --format sarif --output /out/image.sarif /out/fixable.json
{
echo "### ${IMAGE}"
echo '```'
trivy convert --format table --severity HIGH,CRITICAL /out/image.json
echo '```'
} | tee -a "$GITHUB_STEP_SUMMARY"
- name: Upload to code scanning
if: needs.prepare.outputs.public == 'true'
uses: github/codeql-action/upload-sarif@24c54180a607b1449ed407dd24f251e4e9147c8d # v4.38.3
with:
sarif_file: ${{ runner.temp }}/image.sarif
category: trivy-image-${{ matrix.image.name }}
config:
name: Rendered manifests
needs: prepare
runs-on: ${{ format('gcrunner={0}-config-{1}/machine=c3d-standard-4', github.run_id, strategy.job-index) }}
permissions:
contents: read
security-events: write
steps:
- uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
with:
egress-policy: audit
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1
with:
version: v4.3.0
- name: Render every ci/ scenario
run: |
mkdir -p rendered
for f in charts/appwrite/ci/*-values.yaml; do
name=$(basename "$f" -values.yaml)
helm template appwrite charts/appwrite -n appwrite -f "$f" > "rendered/${name}.yaml"
done
ls -l rendered
- name: trivy config
run: |
trivy() {
docker run --rm -v "${GITHUB_WORKSPACE}:/work" -w /work -v trivy-cache:/root/.cache "$TRIVY_IMAGE" "$@"
}
# KSV-0125 (images from untrusted registries) flags every container:
# the chart pulls from docker.io, ghcr.io and quay.io by design.
# .github/trivy-ignore.rego: by-design findings, each scoped to one resource.
printf '%s\n' KSV-0125 > trivy-ignore.txt
trivy config --ignorefile trivy-ignore.txt --ignore-policy .github/trivy-ignore.rego \
--format json --output trivy-config.json rendered
trivy convert --severity MEDIUM,HIGH,CRITICAL --format sarif --output trivy-config.sarif trivy-config.json
{
echo '### Rendered manifests'
echo '```'
trivy convert --format table --severity MEDIUM,HIGH,CRITICAL trivy-config.json
echo '```'
} | tee -a "$GITHUB_STEP_SUMMARY"
- name: Upload to code scanning
if: needs.prepare.outputs.public == 'true'
uses: github/codeql-action/upload-sarif@24c54180a607b1449ed407dd24f251e4e9147c8d # v4.38.3
with:
sarif_file: trivy-config.sarif
category: trivy-config