Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
445 lines (413 loc) · 17.4 KB
/
Copy pathaction.yml
File metadata and controls
445 lines (413 loc) · 17.4 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
name: "Skylos - Python SAST, Dead Code Detection & PR Gate"
description: "SAST, dead code, secrets, PR gates, and digest-pinned container image vulnerability scans."
author: "Skylos (founder@skylos.dev)"
branding:
icon: "shield"
color: "blue"
inputs:
path:
description: "Path to scan (default: current directory)"
required: false
default: "."
image:
description: "Optional repository@sha256:digest to scan instead of source code; requires an installed Trivy"
required: false
default: ""
image-platform:
description: "Required with image: deployment os/architecture[/variant], for example linux/amd64"
required: false
default: ""
image-fail-on:
description: "Image severity threshold for mode gate: low, medium, high, or critical"
required: false
default: "high"
mode:
description: "Scan mode: 'scan' (report only), 'gate' (fail on issues), or source-only 'review' (PR comments + gate)"
required: false
default: "gate"
diff:
description: "On pull requests, scan and gate only the lines the PR changes ('auto', the default), so findings already in the repository don't fail it. 'false' scans the whole repository. With a shallow checkout the action fetches the history it needs; set fetch-depth: 0 on actions/checkout to skip that."
required: false
default: "auto"
analysis:
description: "Analysis types to run (space-separated): dead-code security quality ai-defects secrets sca (aliases: dependency, dependencies)"
required: false
default: "dead-code security"
confidence:
description: "Minimum confidence threshold (0-100)"
required: false
default: "60"
postgres-policy:
description: "In gate or review mode, check changed production PostgreSQL migrations using the pull request or merge queue base policy. Requires fetch-depth: 0."
required: false
default: "false"
token:
description: "Optional legacy Skylos API token for uploads. Prefer GitHub OIDC with id-token: write when running in GitHub Actions."
required: false
python-version:
description: "Python version to use"
required: false
default: "3.11"
max-comments:
description: "Maximum inline PR review comments per pull request (default: 15). Later pushes comment only on new findings and edit the one summary comment"
required: false
default: "15"
upload-sarif:
description: "Also write skylos.sarif and upload it to GitHub code scanning (source scans only; needs permissions: security-events: write)"
required: false
default: "false"
verify-security:
description: "Ask an AI model to check high-severity security findings (several runs each) before upload and record an evidence level on each in Skylos Cloud. Set the model provider's key on this step's env from a secret (e.g. ANTHROPIC_API_KEY or OPENAI_API_KEY). Display only: blocking is unchanged."
required: false
default: "false"
verify-model:
description: "Model for verify-security (default gpt-4.1), e.g. claude-sonnet-4-6"
required: false
default: ""
sarif-category:
description: "Code scanning category for the uploaded SARIF (distinguishes multiple Skylos runs in one repo)"
required: false
default: "skylos"
outputs:
findings-count:
description: "Number of listed source findings or reported container vulnerabilities"
value: ${{ steps.scan.outputs.findings_count || steps.image_scan.outputs.findings_count }}
gate-passed:
description: "Whether the requested gate passed (true/false)"
value: ${{ steps.postgres_policy.outcome == 'failure' && 'false' || steps.gate.outputs.passed || steps.image_scan.outputs.passed }}
report-path:
description: "Path to the JSON report file"
value: ${{ steps.scan.outputs.report || steps.image_scan.outputs.report }}
runs:
using: "composite"
steps:
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
with:
python-version: ${{ inputs.python-version }}
- name: Detect Go sources
id: go_sources
if: inputs.image == ''
shell: bash
env:
SKYLOS_PATH: ${{ inputs.path }}
run: |
if find "$SKYLOS_PATH" -type f -name '*.go' -print -quit 2>/dev/null | grep -q .; then
echo "present=true" >> "$GITHUB_OUTPUT"
else
echo "present=false" >> "$GITHUB_OUTPUT"
fi
- name: Set up Go
if: steps.go_sources.outputs.present == 'true'
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff
with:
go-version: "1.26.11"
cache: false
- name: Build Skylos Go engine
if: steps.go_sources.outputs.present == 'true'
shell: bash
env:
SKYLOS_ACTION_PATH: ${{ github.action_path }}
run: |
ENGINE_DIR="$RUNNER_TEMP/skylos-go-engine"
ENGINE_NAME="skylos-go"
if [ "$RUNNER_OS" = "Windows" ]; then
ENGINE_NAME="skylos-go.exe"
fi
mkdir -p "$ENGINE_DIR"
(
cd "$SKYLOS_ACTION_PATH/skylos/engines/go"
GOCACHE="$RUNNER_TEMP/skylos-go-build-cache" \
GOPATH="$RUNNER_TEMP/skylos-go-gopath" \
go build -trimpath -o "$ENGINE_DIR/$ENGINE_NAME" ./cmd/skylos-go
)
- name: Install Skylos
shell: bash
env:
SKYLOS_ACTION_PATH: ${{ github.action_path }}
run: python -I -m pip install "${SKYLOS_ACTION_PATH}[dart,postgres]"
- name: Run Skylos Image Scan
id: image_scan
if: inputs.image != ''
shell: bash
env:
SKYLOS_IMAGE: ${{ inputs.image }}
SKYLOS_IMAGE_PLATFORM: ${{ inputs.image-platform }}
SKYLOS_IMAGE_FAIL_ON: ${{ inputs.image-fail-on }}
SKYLOS_MODE: ${{ inputs.mode }}
run: |
if [[ -z "${RUNNER_TEMP:-}" ]]; then
echo "::error::RUNNER_TEMP is required for image reports"
exit 2
fi
if ! REPORT_DIR=$(python -I -c 'import pathlib,sys,tempfile; root=pathlib.Path(sys.argv[1]).resolve(strict=True); print(tempfile.mkdtemp(prefix="skylos-image-", dir=root))' "$RUNNER_TEMP"); then
echo "::error::Could not create a private image report directory"
exit 2
fi
REPORT="$REPORT_DIR/report.json"
echo "report=$REPORT" >> "$GITHUB_OUTPUT"
if [[ "$SKYLOS_MODE" != "scan" && "$SKYLOS_MODE" != "gate" ]]; then
echo "passed=false" >> "$GITHUB_OUTPUT"
echo "::error::Image scans support mode scan or gate, not review"
exit 2
fi
if [[ -z "$SKYLOS_IMAGE_PLATFORM" ]]; then
echo "passed=false" >> "$GITHUB_OUTPUT"
echo "::error::image-platform is required when image is set"
exit 2
fi
if [[ "$SKYLOS_MODE" == "gate" ]]; then
case "$SKYLOS_IMAGE_FAIL_ON" in
low|medium|high|critical) ;;
*)
echo "passed=false" >> "$GITHUB_OUTPUT"
echo "::error::image-fail-on must be low, medium, high, or critical"
exit 2
;;
esac
fi
ARGS=(image scan "$SKYLOS_IMAGE" --platform "$SKYLOS_IMAGE_PLATFORM" --output "$REPORT")
if [[ "$SKYLOS_MODE" == "gate" ]]; then
ARGS+=(--fail-on "$SKYLOS_IMAGE_FAIL_ON")
fi
set +e
python -I -m skylos.cli "${ARGS[@]}"
SCAN_STATUS=$?
set -e
if [[ ! -f "$REPORT" ]]; then
echo "passed=false" >> "$GITHUB_OUTPUT"
echo "::error::Image scan did not write a report"
exit 2
fi
if ! COUNT=$(python -I -c 'import json,sys; data=json.load(open(sys.argv[1],encoding="utf-8")); findings=data["container_vulnerabilities"]; assert isinstance(findings,list); print(len(findings))' "$REPORT"); then
echo "passed=false" >> "$GITHUB_OUTPUT"
echo "::error::Image scan report could not be read"
exit 2
fi
echo "findings_count=$COUNT" >> "$GITHUB_OUTPUT"
echo "### Skylos Image Scan Results" >> "$GITHUB_STEP_SUMMARY"
echo "Found **$COUNT** reported container vulnerability finding(s)." >> "$GITHUB_STEP_SUMMARY"
if [[ "$SKYLOS_MODE" == "gate" ]]; then
if [[ "$SCAN_STATUS" -eq 0 ]]; then
echo "passed=true" >> "$GITHUB_OUTPUT"
else
echo "passed=false" >> "$GITHUB_OUTPUT"
fi
fi
if [[ "$SCAN_STATUS" -eq 2 ]]; then
echo "::error::Image scan was incomplete; refusing a clean result"
exit 2
fi
if [[ "$SCAN_STATUS" -eq 1 && "$SKYLOS_MODE" == "gate" ]]; then
exit 1
fi
if [[ "$SCAN_STATUS" -ne 0 ]]; then
echo "::error::Image scan failed with exit code $SCAN_STATUS"
exit 2
fi
- name: Run Skylos Scan
id: scan
if: inputs.image == ''
shell: bash
env:
SKYLOS_PATH: ${{ inputs.path }}
SKYLOS_ANALYSIS: ${{ inputs.analysis }}
SKYLOS_CONFIDENCE: ${{ inputs.confidence }}
SKYLOS_TOKEN: ${{ inputs.token }}
SKYLOS_UPLOAD_SARIF: ${{ inputs.upload-sarif }}
SKYLOS_DIFF_MODE: ${{ inputs.diff }}
SKYLOS_GO_BIN: ${{ format('{0}/skylos-go-engine/skylos-go{1}', runner.temp, runner.os == 'Windows' && '.exe' || '') }}
run: |
REPORT="skylos-report.json"
echo "report=$REPORT" >> "$GITHUB_OUTPUT"
SARIF_ARGS=()
if [ "$SKYLOS_UPLOAD_SARIF" = "true" ]; then
SARIF_ARGS=(--sarif skylos.sarif)
echo "sarif=skylos.sarif" >> "$GITHUB_OUTPUT"
fi
# Pull requests: scan only the changed lines, with the policy of the
# target branch, as `skylos cicd init` workflows do.
DIFF_ARGS=()
if [ "${GITHUB_EVENT_NAME:-}" = "pull_request" ] && [ "$SKYLOS_DIFF_MODE" != "false" ] \
&& [[ "${GITHUB_BASE_REF:-}" =~ ^[A-Za-z0-9._/-]+$ ]]; then
BASE="origin/$GITHUB_BASE_REF"
# Both fetches are best effort: without them the scan covers everything.
if ! git fetch --no-tags --quiet origin "+refs/heads/$GITHUB_BASE_REF:refs/remotes/$BASE" 2>/dev/null; then
echo "::debug::Could not fetch $BASE"
fi
if ! git merge-base "$BASE" HEAD >/dev/null 2>&1 \
&& [ "$(git rev-parse --is-shallow-repository 2>/dev/null)" = "true" ]; then
if ! git fetch --no-tags --quiet --unshallow origin 2>/dev/null; then
echo "::debug::Could not fetch the full history"
fi
fi
if MERGE_BASE="$(git merge-base "$BASE" HEAD 2>/dev/null)"; then
export SKYLOS_POLICY_BASE="$MERGE_BASE"
DIFF_ARGS=(--diff-base "$BASE" --diff "$BASE")
echo "diff_base=$BASE" >> "$GITHUB_OUTPUT"
else
echo "::notice::Skylos scanned the whole repository: no common history with $BASE. Set fetch-depth: 0 on actions/checkout to check only this pull request's changes."
fi
fi
# Build flags from analysis types
FLAGS=""
if echo "$SKYLOS_ANALYSIS" | grep -q "security"; then
FLAGS="$FLAGS --danger"
fi
if echo "$SKYLOS_ANALYSIS" | grep -q "quality"; then
FLAGS="$FLAGS --quality"
fi
if echo "$SKYLOS_ANALYSIS" | grep -q "ai-defects"; then
FLAGS="$FLAGS --ai-defects"
fi
if echo "$SKYLOS_ANALYSIS" | grep -q "secrets"; then
FLAGS="$FLAGS --secrets"
fi
if [[ "$SKYLOS_ANALYSIS" =~ (^|[[:space:]])(dependency|dependencies|sca)($|[[:space:]]) ]]; then
FLAGS="$FLAGS --sca"
fi
# Run scan
set +e
python -I -m skylos.cli "$SKYLOS_PATH" \
--confidence "$SKYLOS_CONFIDENCE" \
$FLAGS \
"${SARIF_ARGS[@]}" \
"${DIFF_ARGS[@]}" \
--json > "$REPORT"
SCAN_STATUS=$?
set -e
if [ "$SCAN_STATUS" -ne 0 ] && [ "$SCAN_STATUS" -ne 2 ]; then
echo "::error::Skylos scan failed with exit code $SCAN_STATUS"
exit "$SCAN_STATUS"
fi
python -I -m skylos.cicd.scan_summary "$REPORT"
if [ "$SCAN_STATUS" -eq 2 ]; then
echo "::error::Skylos analysis was incomplete; refusing a clean result"
exit 2
fi
- name: Upload SARIF to GitHub Code Scanning
if: ${{ !cancelled() && inputs.image == '' && inputs.upload-sarif == 'true' && steps.scan.outputs.sarif != '' && hashFiles('skylos.sarif') != '' }}
uses: github/codeql-action/upload-sarif@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
with:
sarif_file: skylos.sarif
category: ${{ inputs.sarif-category }}
- name: Upload to Skylos Dashboard
if: inputs.image == ''
shell: bash
env:
SKYLOS_TOKEN: ${{ inputs.token }}
SKYLOS_PATH: ${{ inputs.path }}
SKYLOS_ANALYSIS: ${{ inputs.analysis }}
SKYLOS_CONFIDENCE: ${{ inputs.confidence }}
SKYLOS_VERIFY_SECURITY: ${{ inputs.verify-security }}
SKYLOS_VERIFY_MODEL_INPUT: ${{ inputs.verify-model }}
SKYLOS_GO_BIN: ${{ format('{0}/skylos-go-engine/skylos-go{1}', runner.temp, runner.os == 'Windows' && '.exe' || '') }}
run: |
# Upload works with SKYLOS_TOKEN or tokenless via GitHub OIDC. With
# neither, an upload can only fail: skip it rather than scan again.
if [ -z "$SKYLOS_TOKEN" ] && [ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ]; then
echo "::notice::Skylos Cloud upload skipped: no token input and no GitHub OIDC. To upload, add permissions: id-token: write (with the Skylos GitHub App installed) or the token input."
exit 0
fi
FLAGS=""
if echo "$SKYLOS_ANALYSIS" | grep -q "security"; then
FLAGS="$FLAGS --danger"
fi
if echo "$SKYLOS_ANALYSIS" | grep -q "quality"; then
FLAGS="$FLAGS --quality"
fi
if echo "$SKYLOS_ANALYSIS" | grep -q "ai-defects"; then
FLAGS="$FLAGS --ai-defects"
fi
if echo "$SKYLOS_ANALYSIS" | grep -q "secrets"; then
FLAGS="$FLAGS --secrets"
fi
if [[ "$SKYLOS_ANALYSIS" =~ (^|[[:space:]])(dependency|dependencies|sca)($|[[:space:]]) ]]; then
FLAGS="$FLAGS --sca"
fi
# Plan 7.3: AI evidence levels ride along with the upload (display only).
if [ "$SKYLOS_VERIFY_SECURITY" = "true" ]; then
FLAGS="$FLAGS --verify-security"
if [ -n "$SKYLOS_VERIFY_MODEL_INPUT" ]; then
if [[ ! "$SKYLOS_VERIFY_MODEL_INPUT" =~ ^[A-Za-z0-9._:/-]{1,100}$ ]]; then
echo "::error::verify-model may only contain letters, digits and . _ : / -"
exit 2
fi
FLAGS="$FLAGS --verify-model $SKYLOS_VERIFY_MODEL_INPUT"
fi
fi
python -I -m skylos.cli "$SKYLOS_PATH" \
--confidence "$SKYLOS_CONFIDENCE" \
$FLAGS \
--upload || echo "Upload failed (non-fatal)"
- name: Post GitHub Annotations
if: always() && inputs.image == ''
shell: bash
run: |
python -I -m skylos.cli cicd annotate \
--input skylos-report.json \
--max 50 || true
- name: Post PR Review Comments
if: inputs.image == '' && github.event_name == 'pull_request' && (inputs.mode == 'review')
shell: bash
env:
GH_TOKEN: ${{ github.token }}
SKYLOS_MAX_COMMENTS: ${{ inputs.max-comments }}
run: |
if ! [[ "$SKYLOS_MAX_COMMENTS" =~ ^[0-9]+$ ]]; then
echo "::error::max-comments must be a non-negative integer"
exit 1
fi
python -I -m skylos.cli cicd review \
--input skylos-report.json \
--max-comments "$SKYLOS_MAX_COMMENTS" || true
- name: Check changed production PostgreSQL migrations
id: postgres_policy
if: inputs.image == '' && inputs.postgres-policy == 'true' && (github.event_name == 'pull_request' || github.event_name == 'merge_group') && (inputs.mode == 'gate' || inputs.mode == 'review')
shell: bash
env:
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
HEAD_SHA: ${{ github.sha }}
run: |
python -I -m skylos.cli cicd postgres-check --base "$BASE_SHA" --head "$HEAD_SHA"
- name: Quality Gate
id: gate
if: inputs.image == '' && (inputs.mode == 'gate' || inputs.mode == 'review')
shell: bash
env:
SKYLOS_PATH: ${{ inputs.path }}
SKYLOS_DIFF_BASE_REF: ${{ steps.scan.outputs.diff_base }}
run: |
DIFF_ARGS=()
if [ -n "$SKYLOS_DIFF_BASE_REF" ]; then
DIFF_ARGS=("$SKYLOS_PATH" --diff-base "$SKYLOS_DIFF_BASE_REF")
fi
set +e
python -I -m skylos.cli cicd gate \
"${DIFF_ARGS[@]}" \
--input skylos-report.json \
--summary
RESULT=$?
set -e
if [ $RESULT -eq 0 ]; then
echo "passed=true" >> "$GITHUB_OUTPUT"
else
echo "passed=false" >> "$GITHUB_OUTPUT"
exit "$RESULT"
fi
- name: Upload Report Artifact
if: always() && inputs.image == ''
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: skylos-report
path: skylos-report.json
if-no-files-found: error
retention-days: 30
- name: Upload Image Report Artifact
if: always() && inputs.image != '' && steps.image_scan.outputs.report != ''
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: skylos-image-report
path: ${{ steps.image_scan.outputs.report }}
if-no-files-found: error
retention-days: 30