-
Notifications
You must be signed in to change notification settings - Fork 2
218 lines (196 loc) Β· 8.25 KB
/
Copy pathsecurity.yml
File metadata and controls
218 lines (196 loc) Β· 8.25 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
name: Security
on:
pull_request:
branches: [main]
paths:
- 'go.mod'
- 'go.sum'
- 'package.json'
- 'package-lock.json'
- 'web/package.json'
- 'web/package-lock.json'
- 'Dockerfile*'
- 'helm/**'
- 'internal/**'
- 'web/**'
- '.gitleaks.toml'
- 'renovate.json'
- 'scripts/check-security-workflow-pins.go'
- 'scripts/check-security-workflow-pins_test.go'
- '.github/workflows/security.yml'
schedule:
- cron: "0 4 * * 1"
workflow_dispatch:
inputs:
runner:
description: 'Runner to use (manual runs only)'
type: choice
options:
- arc-runner
- ubuntu-latest
default: arc-runner
permissions:
contents: read
security-events: write
env:
# renovate: datasource=docker depName=aquasec/trivy
TRIVY_IMAGE: aquasec/trivy@sha256:62b1e65e8869bc4b4c6aa4fa2b21595256c7c2f6018a9d9ad61caf87187c1969 # 0.74.0
# renovate: datasource=docker depName=zricethezav/gitleaks
GITLEAKS_IMAGE: zricethezav/gitleaks@sha256:ebfeb6fd4f2c37fa371d3731ebfa662fdf80f93cd37d3b4771bb82263edff8d0 # v8.27.2
jobs:
security:
name: Security Scan
runs-on: ${{ inputs.runner || 'arc-runner' }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
with:
go-version: "1.25"
- uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
with:
version: v3.16.0
- name: Verify workflow supply-chain pins
run: |
go run ./scripts/check-security-workflow-pins.go
go test ./scripts -run TestWorkflowPinChecker
- name: Verify rendered ingress security behavior
shell: bash
run: |
TLS_RENDERED="$(helm template security helm/teslasync \
--set ingress.enabled=true \
--set ingress.tls[0].secretName=teslasync-tls \
--set ingress.tls[0].hosts[0]=teslasync.local)"
grep -Fq 'nginx.ingress.kubernetes.io/force-ssl-redirect: "true"' <<<"$TLS_RENDERED"
grep -Fq 'nginx.ingress.kubernetes.io/ssl-redirect: "true"' <<<"$TLS_RENDERED"
grep -Fq 'CORS_ORIGINS: "https://teslasync.local"' <<<"$TLS_RENDERED"
grep -Fq 'https://fonts.googleapis.com' <<<"$TLS_RENDERED"
grep -Fq "media-src 'self' blob:" <<<"$TLS_RENDERED"
HTTP_RENDERED="$(helm template security helm/teslasync --set ingress.enabled=true)"
if grep -q 'force-ssl-redirect\|ssl-redirect' <<<"$HTTP_RENDERED"; then
echo "plain-HTTP ingress must not force a TLS redirect" >&2
exit 1
fi
if helm template security helm/teslasync \
--set ingressRoute.enabled=true \
--set ingressRoute.tls.enabled=true > /dev/null 2>&1; then
echo "Traefik TLS must reject an unspecified public CSRF origin" >&2
exit 1
fi
TRAEFIK_RENDERED="$(helm template security helm/teslasync \
--set ingressRoute.enabled=true \
--set ingressRoute.tls.enabled=true \
--set config.webEndpoint=https://teslasync.example.com)"
grep -Fq 'stsSeconds: 63072000' <<<"$TRAEFIK_RENDERED"
grep -Fq 'https://fonts.googleapis.com' <<<"$TRAEFIK_RENDERED"
grep -Fq "media-src 'self' blob:" <<<"$TRAEFIK_RENDERED"
- name: Run govulncheck
run: |
go install golang.org/x/vuln/cmd/govulncheck@v1.7.0
govulncheck ./...
- name: Scan dependencies and filesystem secrets
run: |
docker run --rm -v "$(pwd):/src" -w /src "${TRIVY_IMAGE}" fs \
--timeout 30m \
--scanners vuln,secret \
--skip-dirs .git \
--skip-dirs node_modules \
--skip-dirs web/node_modules \
--skip-dirs .cache \
--skip-dirs web/.cache \
--skip-dirs web/test-results \
--skip-dirs web/playwright-report \
--skip-dirs coverage \
--skip-dirs web/coverage \
--skip-dirs dist \
--skip-dirs web/dist \
--skip-files .gitleaks.toml \
--severity CRITICAL,HIGH \
--exit-code 1 \
--format table .
- name: Scan Helm IaC configuration
run: |
docker run --rm -v "$(pwd):/src" -w /src "${TRIVY_IMAGE}" config \
--severity CRITICAL,HIGH \
--exit-code 1 \
--format table helm/teslasync
- name: Scan checkout for exposed secrets
run: |
docker run --rm -v "$(pwd):/repo:ro" "${GITLEAKS_IMAGE}" \
detect --source=/repo --config=/repo/.gitleaks.toml --no-git --redact --no-banner
- name: Verify Gitleaks policy catches secrets
shell: bash
run: |
# Keep fixtures under the workspace so Docker bind-mounts work on
# self-hosted runners where host /tmp is not visible inside Docker.
fixture="$(pwd)/.gitleaks-policy-fixture"
rm -rf "$fixture"
mkdir -p "$fixture"
trap 'rm -rf "$fixture"' EXIT
write_private_key() {
printf '%s %s\n%s\n%s %s\n' \
'-----BEGIN' 'PRIVATE KEY-----' \
'MIIEpgIBAAKCAQEA7Q0qj5WmCqvTNSiP1w3M9yKf9c2V8zR4' \
'-----END' 'PRIVATE KEY-----' > "$1"
}
run_detect() {
local source_dir="$1"
docker run --rm \
-v "$(pwd)/.gitleaks.toml:/config.toml:ro" \
-v "$fixture:/fixture:ro" \
"${GITLEAKS_IMAGE}" \
detect --source="/fixture/${source_dir}" --config=/config.toml --no-git --redact --no-banner
}
n=0
for fixture_path in production.go internal/negative_test.go web/src/negative.test.ts; do
n=$((n + 1))
case_dir="pk-${n}"
mkdir -p "$fixture/$case_dir/$(dirname "$fixture_path")"
write_private_key "$fixture/$case_dir/$fixture_path"
if run_detect "$case_dir"; then
echo "Gitleaks failed to detect generated $fixture_path" >&2
exit 1
fi
done
write_stopword_fixture() {
printf 'const %s = "%s%s"\n' "$1" "$2" "$3" > "$4"
}
n=0
for fixture_path in source-stopword.go web/src/stopword.test.ts; do
n=$((n + 1))
case_dir="stripe-${n}"
mkdir -p "$fixture/$case_dir/$(dirname "$fixture_path")"
write_stopword_fixture token 'sk_live_' 'abcdef1234' "$fixture/$case_dir/$fixture_path"
if run_detect "$case_dir"; then
echo "Gitleaks failed to detect generated Stripe-like $fixture_path" >&2
exit 1
fi
done
n=0
for fixture_path in source-refresh.go web/src/refresh.test.ts; do
n=$((n + 1))
case_dir="refresh-${n}"
mkdir -p "$fixture/$case_dir/$(dirname "$fixture_path")"
write_stopword_fixture refresh_token 'rt_fake_refresh_token_for_seed_data_only_' 'abc123def456' "$fixture/$case_dir/$fixture_path"
if run_detect "$case_dir"; then
echo "Gitleaks failed to detect generated refresh-token $fixture_path" >&2
exit 1
fi
done
mkdir -p "$fixture/allowlist-control/test-results"
write_private_key "$fixture/allowlist-control/test-results/ignored.pem"
docker run --rm \
-v "$(pwd)/.gitleaks.toml:/config.toml:ro" \
-v "$fixture:/fixture:ro" \
"${GITLEAKS_IMAGE}" \
detect --source=/fixture/allowlist-control --config=/config.toml --no-git --redact --no-banner
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "20"
- name: Initialize CodeQL
uses: github/codeql-action/init@b1bff81932f5cdfc8695c7752dcee935dcd061c8 # v4.33.0
with:
languages: go,javascript-typescript
- name: CodeQL autobuild
uses: github/codeql-action/autobuild@b1bff81932f5cdfc8695c7752dcee935dcd061c8 # v4.33.0
- name: CodeQL analysis
uses: github/codeql-action/analyze@b1bff81932f5cdfc8695c7752dcee935dcd061c8 # v4.33.0