Skip to content

Commit 5a6a3f8

Browse files
committed
Document exit-code migration and CI failure policies
1 parent 1b80894 commit 5a6a3f8

5 files changed

Lines changed: 94 additions & 14 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ code; see [Exit codes](README.md#exit-codes).
2121

2222
### Changed
2323

24-
- An incomplete scan comparison fails the run with the infrastructure-error
25-
code.
24+
- Incomplete scan comparisons or existing-alert results fail the run with the
25+
infrastructure-error code.
2626
- GitLab security report IDs include the ecosystem, full package coordinate and
2727
advisory ID, so existing findings get new IDs once.
2828

@@ -32,6 +32,9 @@ code; see [Exit codes](README.md#exit-codes).
3232
alerts on unchanged packages.
3333
- `--strict-blocking` no longer lists findings on added packages twice.
3434
- Every CVE on a package is reported, not one per severity.
35+
- GitLab reports keep findings from different ecosystems and namespaces separate.
36+
- PR/MR comments group existing license violations and retain warnings about
37+
omitted findings after individual ignores.
3538
- A token without `repo:list` is reported as a missing scope, not a missing
3639
repository.
3740

‎README.md‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,12 @@ error, so the supervisor's exit status (commonly 124 or 137) takes precedence.
240240
The two flags that affect exit codes can cancel each other out, so the order of
241241
precedence matters:
242242

243-
- **`--disable-blocking` wins for every run that gets past flag parsing.** It
244-
forces exit `0` for security findings, infrastructure errors and interrupts.
245-
If you set it, `--exit-code-on-api-error` has no effect (you'll always get `0`).
246-
It does not apply to usage errors (`2`): a run with invalid flags never scanned
247-
anything, so it always fails.
243+
- **`--disable-blocking` forces exit `0` for findings, infrastructure errors and
244+
interrupts.** It takes precedence over `--exit-code-on-api-error` and
245+
`--strict-blocking`. Usage errors still exit `2`.
248246
- **`--exit-code-on-api-error` only applies when `--disable-blocking` is *not*
249-
set.** It changes the infra-error code (and the generic-error code); it never
250-
touches the security-finding code (`1`).
247+
set.** It changes the infrastructure-error code, including unexpected runtime
248+
failures. Findings (`1`), usage errors (`2`) and Ctrl+C (`130`) keep their codes.
251249

252250
So for the common "don't let Socket outages block my pipeline, but still fail on
253251
real findings" goal, use `--exit-code-on-api-error` **without** `--disable-blocking`:
@@ -266,6 +264,23 @@ scan exit `0` on *both* findings and outages — the `soft_fail: 100` rule would
266264
never match, and real findings would stop blocking. That's usually not what you
267265
want.
268266

267+
### Upgrading to 2.13.0
268+
269+
Update pipeline rules and wrapper scripts that match specific exit codes:
270+
271+
| Outcome | Before 2.13.0 | From 2.13.0 |
272+
|---------|---------------|-------------|
273+
| Invalid flags or configuration | CLI validation: `1`; argparse: `2` | `2` for both; never suppressed by `--disable-blocking` |
274+
| Ctrl+C | `2` | `130`, or `0` with `--disable-blocking` |
275+
| Missing token or other setup failure | Fixed `2` or `3`, depending on the failure | Infrastructure-error code (`3` by default); both exit-code flags now apply |
276+
277+
Blocking findings still exit `1`. With `--strict-blocking`, existing blocking
278+
alerts can now fail jobs that previously passed. GitLab report findings also get
279+
new IDs once; see the [release notes](CHANGELOG.md#2130).
280+
281+
For a compact comparison of failure-handling policies, see
282+
[Exit codes in CI](docs/ci-cd.md#exit-codes-in-ci).
283+
269284
## Common gotchas
270285

271286
See [`docs/troubleshooting.md`](https://github.com/SocketDev/socket-python-cli/blob/main/docs/troubleshooting.md#common-gotchas).

‎docs/ci-cd.md‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,42 @@ steps:
5252
- "results.sarif"
5353
```
5454
55+
## Exit codes in CI
56+
57+
Choose which outcomes may leave your scan step green. The values below are the
58+
CLI's exit status; CI cancellation and external timeouts can have their own status.
59+
60+
| Outcome | Default | `--exit-code-on-api-error 100` | `--disable-blocking` |
61+
|---------|---------|--------------------------------|----------------------|
62+
| No blocking findings | `0` | `0` | `0` |
63+
| Blocking findings | `1` | `1` | `0` |
64+
| Invalid flags or configuration | `2` | `2` | `2` |
65+
| Setup, API or runtime failure | `3` | `100` | `0` |
66+
| Ctrl+C handled by the CLI | `130` | `130` | `0` |
67+
68+
Use a custom infrastructure code with your CI provider's exit-code allowlist; the
69+
[Buildkite example](../README.md#how-these-options-interact) shows this pattern.
70+
For providers without that feature, remap infrastructure errors to `0`:
71+
72+
```bash
73+
# Keep findings blocking; allow setup/API failures to pass.
74+
socketcli --config .socketcli.toml --exit-code-on-api-error 0
75+
76+
# Report-only mode: findings, infrastructure failures and Ctrl+C exit 0.
77+
# Invalid flags/configuration still exit 2.
78+
socketcli --config .socketcli.toml --disable-blocking
79+
```
80+
81+
Combining the flags gives `--disable-blocking` precedence. Avoid blanket shell
82+
`|| true` or job-wide `continue-on-error` when only API failures should be allowed:
83+
they also hide findings and usage errors. Even with exit `0`, a setup/API failure
84+
does not mean a clean scan; check the logs for a completed report.
85+
86+
Findings block only when a [diff comparison runs](#scan-type-by-pipeline).
87+
`--strict-blocking` also checks existing blocking alerts; an incomplete comparison
88+
or incomplete existing-alert data is an infrastructure failure. See the
89+
[2.13.0 migration table](../README.md#upgrading-to-2130) when updating existing CI rules.
90+
5591
## Config file usage in CI
5692

5793
Use `--config .socketcli.toml` or `--config .socketcli.json` to keep pipeline commands small.
@@ -465,7 +501,7 @@ With `--scm github` or `--scm gitlab`, the detected event decides the scan type:
465501

466502
| Event | Scan | Blocks the build |
467503
|:------|:-----|:-----------------|
468-
| Pull request / merge request | Diff scan against the repository's baseline | Yes, on newly introduced alerts |
504+
| Pull request / merge request | Diff scan against the repository's baseline | Yes, on new blocking alerts; also existing blockers with `--strict-blocking` |
469505
| Any other pipeline, including default-branch pushes | Full scan | No |
470506

471507
A full scan has no baseline, so it cannot tell a newly introduced alert from one

‎docs/cli-reference.md‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,16 @@ Sample config files:
430430
### CI/CD usage tips
431431
432432
For CI-specific examples and guidance, see [`ci-cd.md`](ci-cd.md).
433+
Exit statuses and flag precedence are listed in [Exit codes](../README.md#exit-codes),
434+
with pipeline examples in [Exit codes in CI](ci-cd.md#exit-codes-in-ci).
433435
434436
The CLI runs a pinned version of the Coana CLI, the analysis engine; it does **not** auto-update the engine. It downloads the engine from the Socket API on first use and keeps it in `$XDG_CACHE_HOME/socket/coana/v1` (`~/.cache/socket/coana/v1` when `XDG_CACHE_HOME` is unset). Pass `--reach-version latest` to opt into the newest published version. Use `--reach` to enable reachability analysis during a full scan, or add `--only-facts-file` (with `--reach`) to submit only the reachability facts file (`.socket.facts.json`) when creating the full scan.
435437
436438
#### Advanced Configuration
437439
| Parameter | Required | Default | Description |
438440
|:-------------------------|:---------|:--------|:----------------------------------------------------------------------|
439441
| `--ignore-commit-files` | False | False | Compare regardless of which files changed, scanning every manifest |
442+
| `--exit-code-on-api-error` | False | 3 | Remap infrastructure failures, including missing tokens, setup failures, incomplete scan data and unexpected runtime errors. Findings (`1`), usage errors (`2`) and Ctrl+C (`130`) are unaffected. `--disable-blocking` takes precedence. |
440443
| `--disable-blocking` | False | False | Non-blocking CI mode: the CLI exits **0** even when blocking alerts are present (including with `--strict-blocking`). Also exits 0 on infrastructure errors (missing API or SCM token, Socket API failures, uncaught runtime errors) and interrupts, so the job is treated as successful while findings and errors are still logged. Invalid flags still exit **2**. Takes precedence over `--strict-blocking`. |
441444
| `--disable-ignore` | False | False | Disable support for `@SocketSecurity ignore` commands in PR comments. When set, alerts cannot be suppressed via comments and ignore instructions are hidden from comment output. See [Who can ignore an alert](#who-can-ignore-an-alert). |
442445
| `--ignore-authorization` | False | enforce | Who may suppress alerts with `@SocketSecurity ignore`. `enforce` requires write access and honors the command with a warning when the provider cannot report it; `strict` rejects it in that case; `off` honors any commenter. See [Who can ignore an alert](#who-can-ignore-an-alert). |
@@ -641,10 +644,10 @@ Security issues detected by Socket Security:
641644
642645
### Important Notes
643646
644-
- **Diff Mode Only**: The flag only works in diff mode (with SCM integration). In API mode, a warning is logged.
647+
- **Diff Mode Only**: The flag applies when a scan comparison runs, with or without SCM integration. A full scan logs a warning and does not evaluate existing violations; see [Scan type by pipeline](ci-cd.md#scan-type-by-pipeline).
645648
- **Error-Level Only**: Only fails on `error=True` alerts (blocking severity), not warnings.
646649
- **Existing alerts come from the full scan**: The scan comparison doesn't carry alerts on unchanged packages, so the CLI reads them from the new full scan, at the cost of one more API request per run. If that request fails or omits an unchanged package, the run fails with the infrastructure-error code rather than passing without them.
647-
- **PR/MR comments**: Existing alerts are listed in their own table after the new ones, blocking first. `@SocketSecurity ignore` applies to them too. Very large sets are cut off before the comment reaches GitHub's size limit, with a link to the full report.
650+
- **PR/MR comments**: Existing alerts are listed in their own table after the new ones, blocking first, with license violations grouped per package. `@SocketSecurity ignore` applies to them too. Very large sets are cut off before the comment reaches GitHub's size limit, with a link to the full report. Ignoring every displayed alert preserves the warning about omitted findings; `ignore-all` also clears omitted findings.
648651
- **Priority**: `--disable-blocking` takes precedence - if both flags are set, the build will always pass.
649652
- **First Scan**: On the very first scan of a repository, there are no "existing" violations, so behavior is identical to standard mode.
650653
@@ -883,9 +886,16 @@ The GitLab Security Dashboard report and the JSON/SARIF diff outputs use differe
883886
884887
### Alert Ignoring via PR/MR Comments
885888
886-
When using the CLI with SCM integration (`--scm github` or `--scm gitlab`), users can ignore specific alerts by reacting to Socket's PR/MR comments. Ignored alerts are removed from `--enable-json`, `--enable-sarif`, and console output.
889+
In SCM diff mode (`--scm github` or `--scm gitlab`), an authorized
890+
`@SocketSecurity ignore <ecosystem>/<package>@<version>` or
891+
`@SocketSecurity ignore-all` comment removes matching new alerts from the CLI's
892+
reports, including the GitLab report. With `--strict-blocking`, it also removes
893+
matching existing alerts from blocking checks and reports. Without strict blocking,
894+
the GitLab report still includes existing findings.
887895
888-
However, the GitLab Security Dashboard report includes **all** alerts matching your security policy (new and existing), regardless of comment-based ignores. This ensures the Security Dashboard always reflects the full set of known issues. To suppress a vulnerability from the GitLab report, adjust the alert's policy in Socket's dashboard rather than ignoring it via a PR comment.
896+
`--disable-ignore` disables these commands. See [Who can ignore an alert](#who-can-ignore-an-alert)
897+
for authorization rules. To suppress a finding across future PRs, update its policy
898+
or triage state in Socket's dashboard.
889899
890900
### Report Schema
891901
@@ -902,6 +912,10 @@ Socket CLI generates reports compliant with [GitLab Dependency Scanning schema v
902912
903913
**Schema compatibility:** The v15.0.0 schema is supported across all GitLab versions 12.0+ (both self-hosted and cloud). The report includes the `dependency_files` field, which is required by v15.0.0 and accepted as an optional extra by newer schema versions, ensuring maximum compatibility across GitLab instances.
904914
915+
Finding IDs distinguish the ecosystem, full package coordinate and advisory, so
916+
different namespaces or CVEs remain separate findings. Upgrading to 2.13.0 changes
917+
existing finding IDs once; GitLab may show them as newly detected on the first report.
918+
905919
### Performance Notes
906920
907921
When `--enable-gitlab-security` (or `--enable-json` / `--enable-sarif`) is used with a full scan (non-diff mode), the CLI fetches package and alert data from the scan results to populate the report. This adds time proportional to the number of packages in the scan. Without these output flags, no additional data is fetched and scan performance is unchanged.

‎docs/troubleshooting.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Troubleshooting
22

3+
## Unexpected CI exit status
4+
5+
| Symptom | What to check |
6+
|---------|---------------|
7+
| Exit `2`, even with `--disable-blocking` | Fix the flags or configuration reported in the logs. Usage errors are never suppressed. |
8+
| Exit `3` with no reported findings | Check tokens, scopes, baseline lookup and scan-completeness errors. This is a failed evaluation; `--exit-code-on-api-error` can remap its code. |
9+
| Ctrl+C is treated as a configuration error | Update wrapper/CI rules: Ctrl+C changed from `2` to `130` in 2.13.0. |
10+
| Exit `0` despite expected blockers | Check `--disable-blocking`, remapping to `0`, and whether the run produced a full scan instead of a diff. Full scans do not gate on findings. |
11+
12+
See [Exit codes in CI](ci-cd.md#exit-codes-in-ci) for the flag combinations and
13+
[upgrade guidance](../README.md#upgrading-to-2130) for older pipeline rules.
14+
315
## API token scopes for scan comparisons
416

517
PR/MR runs compare the new scan against the repository's head scan. That comparison

0 commit comments

Comments
 (0)