You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 61c8e89
Browse filesBrowse the repository at this point in the historyBrowse files
Improve documentation for requisite API token permissions (#353)
* Document the API token permissions a run actually needs
The only scope guidance in the repo covered the diff-scans comparison path,
described it as PR/MR-only, and listed `full-scans:list` alongside the two
`diff-scans:*` scopes. The comparison also runs on plain pushes, and the
streaming fallback is itself a full-scans read, so a reader hitting the
`APIAccessDenied` warning was pointed at the wrong permission and told the
condition did not apply to them.
Replace it with the full picture: what every run calls, what diff-producing
runs add, and what each flag adds. Scope names are only published for the
diff-scans path, so the rest are described by endpoint rather than guessed at.
Also document three outcomes that look like failures and are not: the
temporary empty baseline on a first scan, the reachability scan ID being a
`tier1ReachabilityScanId` rather than a full scan ID, and a repository
permission gap exiting 2 — a code the exit table documents as a keyboard
interrupt, and which bypasses `--disable-blocking` and
`--exit-code-on-api-error`.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Name the token scopes and flag the two the setup guide omits
The permission tables described endpoints but deferred on scope names, since
nothing in this repo or the SDK publishes them. The public CI/CD token setup
guide does: nine scopes, which the docs now name and map to the calls they
cover.
That guide omits `diff-scans:create` and `diff-scans:list`. Every
diff-producing run tries the diff-scans endpoints first, so a token
provisioned exactly as documented always fails that call and falls back to the
legacy streaming comparison, with a warning as the only signal. Anyone
following the documented setup hits this.
The converse is also worth stating: `socketcli` makes no triage or
security-policy calls, so three of the nine scopes the guide lists are not
exercised by this CLI.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Correct which runs compare, after the 2.9.0 flow change
now sends only a "diff" event type to create_new_diff and everything else,
default-branch pushes included, to create_full_scan_with_report_url.
The permission docs asserted the opposite -- that plain pushes also reach the
diff-scans path -- which was true when they were written against 2.8.1 and is
not true now. Replace the claim with a table of which runs compare, and keep
the old behavior as a note, since the warning still shows up in logs from
pre-2.9.0 runs with no pull request in sight.
Re-verified the rest against 2.9.7: SDK call surface, the four sys.exit(2)
sites, the temporary empty baseline, and the reachability scan ID are all
unchanged.
* Map each API call to the scope the API checks
The scope tables were inferred from scope names. The API reference
publishes the scope each endpoint checks, so the tables now use those and
the open question about unpublished scopes is resolved: GET organizations,
GET report/supported and the ignore-comment telemetry post check none.
Rechecking the call surface against 2.12.0 also changed the guidance:
- repo:update is never exercised. POST full-scans checks only
full-scans:create, including when it sets the repository head.
- --sbom-file makes no API call; the CycloneDX export it was mapped to
has no caller. License-metadata and full-scan metadata reads are
likewise unreached outside tests.
- diff-scans/from-ids checks full-scans:list as well as
diff-scans:create.
- --reach's manifest upload and tier-1 finalize check
full-scans:create, as do the Coana CLI's reachability calls.
- The exit-2 section now quotes the repo:create hint the CLI logs on a
403.
* Describe which runs compare without pinning it to a release
* Scope the repository lookup to diff-producing runs
Only a diff-producing run that takes its baseline from the repository's
head scan looks the repository up, and so only that run can create it
or exit 2. A full-scan run uploads straight to full-scans, which creates
a missing repository for an organization-wide token. A failed streaming
fallback also only points at full-scans:list when it fails with
Insufficient permissions.
* Correct the supported-patterns failure and the empty-baseline trigger
A failed GET report/supported raises from the SDK and stops the run; the
bundled pattern list only covers a non-error response with no body. An
empty baseline is created when the repository has no head scan, not on
every new branch, since a branch compares against the repository's head
scan.
* Bump to 2.12.2
* Correct how missing scopes behave, and how the baseline is chosen
A missing scope was described as mostly degrading with a warning. Only
the two diff-scans scopes do that. The others fail the run:
- full-scans:list is needed before any comparison. scan_type is always
set, so the baseline is the newest matching scan listed from the
default branch, not the repository's head-scan pointer, and a denied
listing exits with the API-error code. The same listing explains when
an empty baseline is created.
- The scope table now says what happens without each scope.
Calls the tables missed: POST python-cli-runs (and its logs and
finalize calls) on every run, and POST coana-cli/artifacts under
--reach, which accepts full-scans:create or fixes:list. GET
report/supported needs no token, and the streaming fallback endpoint is
deprecated in the API.
Also covered: scope groups, tokens restricted to specific repositories,
comment events, and the flags that force a comparison.
The README exit-code table is left alone. The repository-failure section
keeps the exit-2 details under "2.12.x and earlier", so it stays true
when the exit-code contract changes. The setup-guide paragraphs describe
tokens made from its nine-scope list instead of the guide's current
contents, which are about to change.
* Bump the pinned Socket Python SDK to 3.6.3
socketdev 3.6.3 fixes settings.integration_events(), which requested a
path the API does not route. The CLI does not call it, so nothing
changes at runtime; the pin moves so the CLI ships the current SDK.
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
@@ -930,7 +946,7 @@ When `--enable-gitlab-security` (or `--enable-json` / `--enable-sarif`) is used
930
946
### Requirements
931
947
932
948
- **GitLab Version**: GitLab 12.0 or later (for Security Dashboard support)
933
-
- **Socket API Token**: Set via `$SOCKET_API_TOKEN` environment variable or `--api-token` parameter
949
+
- **Socket API Token**: Set via `SOCKET_SECURITY_API_TOKEN` environment variable or `--api-token` parameter (see [Authentication](#authentication) for the other accepted variable names)
934
950
- **CI/CD Artifacts**: Reports must be uploaded as `dependency_scanning` artifacts
@@ -28,39 +28,197 @@ Both failures follow `--disable-blocking` and `--exit-code-on-api-error`. Before
28
28
`repo:list` ended in the `repo:create` message, and the run exited `2` whatever
29
29
either flag said.
30
30
31
-
## API token scopes for scan comparisons
32
-
33
-
PR/MR runs compare the new scan against the repository's head scan. That comparison
34
-
first uses the diff-scans endpoints, which require an organization token with these
35
-
scopes in addition to whatever the scan itself needs:
36
-
37
-
-`diff-scans:create`
38
-
-`diff-scans:list`
39
-
-`full-scans:list`
40
-
41
-
`full-scans:list` also covers the read of the new full scan that `--strict-blocking`,
42
-
`--enable-gitlab-security` and `--legal-format fossa` use to get alerts on unchanged
43
-
packages.
44
-
45
-
If the token is missing them the scan still succeeds, so this is easy to miss. The only
46
-
signal is a warning, after which the CLI falls back to the older streaming comparison:
31
+
## API token permissions
32
+
33
+
The CLI authenticates with a single Socket organization API token. Most missing scopes
34
+
fail the run with an API error. The two `diff-scans` scopes are the exception: without
35
+
them the run falls back to an older comparison and only logs a warning.
36
+
37
+
### Scopes to grant
38
+
39
+
For a least-privilege CI token, grant these:
40
+
41
+
| Scope | Needed for | Without it |
42
+
|:---|:---|:---|
43
+
|`full-scans:create`| Creating the scan, on every run. `--reach` also locates the analysis engine, uploads manifests and records the reachability scan under it | The run fails |
44
+
|`full-scans:list`| Finding the baseline scan and comparing against it, on every run that compares scans. Also fetching scan contents for `--enable-json`, `--enable-sarif`, `--enable-gitlab-security` and `--generate-license` on a full scan | Those runs fail |
45
+
|`diff-scans:create`| Creating the comparison | The run [falls back](#apiaccessdenied-on-the-scan-comparison) with a warning |
46
+
|`diff-scans:list`| Polling for the comparison, and finding an existing one | The same fallback |
47
+
|`repo:list`| Looking up the repository's default branch, on runs that compare scans without `--base-scan-id` or `--base-commit-sha`| Those runs fail; see [Repository lookup or creation fails](#repository-lookup-or-creation-fails)|
48
+
|`repo:create`| Creating the repository when that lookup finds none | The first comparison for a repository Socket has not seen fails |
49
+
|`packages:list`|`--generate-license` only | Those runs fail |
50
+
51
+
A failed run exits with the API-error code: `3` by default, the value of
52
+
`--exit-code-on-api-error` when set, or `0` with `--disable-blocking`.
53
+
54
+
Scopes are grouped by their prefix, and granting a group grants every scope in it:
55
+
`full-scans` covers `full-scans:create`, `full-scans:list` and `full-scans:delete`. The
56
+
dashboard's token dialog lists each scope under its group. A token with the groups
57
+
`full-scans`, `diff-scans`, `repo` and `packages` therefore works too; it just holds
58
+
more than this CLI uses.
59
+
60
+
The scopes each endpoint checks are listed in the
61
+
[API reference](https://docs.socket.dev/reference). `GET organizations` and the
62
+
telemetry event posted when someone replies to a Socket comment with an ignore command
63
+
check no scope, so any valid token for the organization works. `GET report/supported`
64
+
needs no token at all.
65
+
66
+
**Tokens restricted to specific repositories** can scan those repositories but cannot
67
+
set up a new one. The API rejects them on `POST orgs/{org}/repos`, and
68
+
`POST orgs/{org}/full-scans` does not create a missing repository for them, whatever
69
+
scopes they hold. They are also rejected on `POST orgs/{org}/purl`, so
70
+
`--generate-license` needs a token with organization-wide repository access.
71
+
72
+
### Tokens with the nine-scope CI/CD list
73
+
74
+
The [CI/CD token setup guide](https://docs.socket.dev/docs/create-socket-api-key-for-cicd)
75
+
was written before the diff-scans endpoints existed. Tokens created from its
**That list has neither `diff-scans:create` nor `diff-scans:list`**, and every run
83
+
that compares scans uses both. A token with only those nine scopes always falls back
84
+
to the older comparison path; see
85
+
[the next section](#apiaccessdenied-on-the-scan-comparison). Add the two scopes.
86
+
87
+
The list also has four scopes this CLI never uses: `repo:update`,
88
+
`security-policy:read`, `triage:alerts-list` and `triage:alerts-update`. A token used
89
+
only by `socketcli` can drop them.
90
+
91
+
### API calls by run type
92
+
93
+
Every run:
94
+
95
+
| API call | Scope | Purpose |
96
+
|:---|:---|:---|
97
+
|`GET organizations`| none | Resolve the org ID and slug from the token |
98
+
|`POST python-cli-runs`|`full-scans:create`| Register the run. When log upload is on (`--upload-logs`, or enabled for the organization), `POST python-cli-runs/{id}/logs` and `POST python-cli-runs/{id}/finalize` follow under the same scope. A failure in any of the three is ignored |
|`POST orgs/{org}/full-scans`|`full-scans:create`| Create the new scan. With an organization-wide token, the server creates the repository if it does not exist yet |
101
+
102
+
Comment events with `--scm github` or `--scm gitlab` create no scan.
103
+
104
+
Runs that compare scans (see [which runs compare](#apiaccessdenied-on-the-scan-comparison)) add:
105
+
106
+
| API call | Scope | Purpose |
107
+
|:---|:---|:---|
108
+
|`GET orgs/{org}/repos/{repo}`|`repo:list`| Look up the repository's default branch. Skipped with `--base-scan-id` or `--base-commit-sha`|
109
+
|`POST orgs/{org}/repos`|`repo:create`| Create the repository, **only attempted when the lookup above finds none**|
110
+
|`GET orgs/{org}/full-scans`|`full-scans:list`| Find the baseline: the newest matching scan on the default branch, or with `--base-commit-sha` the scan for that commit or a scanned ancestor. Skipped with `--base-scan-id`|
111
+
|`POST orgs/{org}/full-scans`|`full-scans:create`| Create a temporary empty baseline when no scan matches |
112
+
|`POST orgs/{org}/diff-scans/from-ids`|`diff-scans:create` and `full-scans:list`| Create the comparison (preferred path) |
113
+
|`GET orgs/{org}/diff-scans`|`diff-scans:list`| Find the existing comparison when creation returns 409 |
114
+
|`GET orgs/{org}/diff-scans/{id}`|`diff-scans:list`| Poll for the computed comparison |
115
+
|`GET orgs/{org}/full-scans/diff`|`full-scans:list`| Streaming comparison (fallback path). The API marks this endpoint as deprecated |
|`--reach`|`POST orgs/{org}/coana-cli/artifacts` (locate the analysis engine download, only when it is not cached) |`full-scans:create` or `fixes:list`|
|`--enable-json`, `--enable-sarif`, `--enable-gitlab-security` or `--generate-license` on a full scan |`GET orgs/{org}/full-scans/{id}` (scan contents) |`full-scans:list`|
126
+
|`--strict-blocking`, `--enable-gitlab-security` or `--legal-format fossa` on a run that compares scans |`GET orgs/{org}/full-scans/{id}` (alerts on unchanged packages) |`full-scans:list`|
127
+
128
+
`--reach` also runs the analysis engine with the same token. The engine reports to the
129
+
`tier1-reachability-scan/*` endpoints, which check `full-scans:create`.
130
+
131
+
## `APIAccessDenied` on the scan comparison
132
+
133
+
Any run that compares scans first tries the diff-scans endpoints. A token without the
134
+
`diff-scans:create` and `diff-scans:list` scopes logs a warning and continues on the
135
+
older path:
47
136
48
137
```
49
138
Diff scan comparison failed with APIAccessDenied(Insufficient permissions), falling back to the streaming scan comparison
50
139
```
51
140
52
-
Grant the scopes to use the diff-scans path. It polls with short, bounded requests
53
-
rather than holding one connection open while the backend computes, which is what lets
54
-
large comparisons survive network idle timeouts — notably Azure NAT gateways, which
55
-
reap idle connections after four minutes and surface as an intermittent
56
-
`ConnectionResetError`.
141
+
The scan still succeeds and the diff results are the same, so this is easy to miss.
142
+
143
+
**Which runs compare scans:**
144
+
145
+
| Run | Compares? |
146
+
|:---|:---|
147
+
| Pull request or merge request run with `--scm github` / `--scm gitlab`| Yes |
148
+
| Comment event with `--scm github` / `--scm gitlab`| No. It creates no scan |
149
+
| Any other event with `--scm github` / `--scm gitlab` (branch and default-branch pushes) | No. It creates a full scan |
150
+
| No SCM integration (`--scm api`, the default) | Yes |
151
+
152
+
In the rows that compare, the CLI first looks for a supported manifest among the
153
+
commit's changed files, or among `--files` when that is given. If it finds none, or
154
+
the directory is not a git repository and `--files` is not given, it creates a full
155
+
scan instead. `--ignore-commit-files` in a git repository and `--enable-diff` outside
156
+
one skip that check, so those runs always compare.
157
+
158
+
Before 2.9.0 an SCM-integrated branch push also compared, so a pipeline scanning only
159
+
pushes (`--pr-number 0 --default-branch`) hit this too. If you are diagnosing an older
160
+
run, that is why the warning can appear in a log with no pull request in sight.
161
+
162
+
**Which scope is missing.** The fallback calls `GET orgs/{org}/full-scans/diff`, which
163
+
checks `full-scans:list`. When the fallback succeeds, the missing scope is
164
+
`diff-scans:create`, `diff-scans:list`, or both. A token without `full-scans:list`
165
+
does not get that far: the CLI lists full scans to pick the baseline before it compares
166
+
anything, so the run fails first with `Failed to resolve the matching head scan for
167
+
repo ...` and the API-error exit code. With `--base-scan-id` that lookup is skipped,
168
+
and the run fails at the fallback instead. A fallback that fails another way, such as a
169
+
timeout or a dropped connection, says nothing about scopes.
170
+
171
+
**Why the diff-scans path is preferred.** It polls with short, bounded requests rather
172
+
than holding one connection open while the backend computes, which is what lets large
0 commit comments