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 06d9a88
Browse filesBrowse the repository at this point in the historyBrowse files
@@ -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