Skip to content

Commit 06869b4

Browse files
committed
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.
1 parent 1d0fcd9 commit 06869b4

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

‎docs/troubleshooting.md‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ For a least-privilege CI token, grant these:
1212

1313
| Scope | Needed for |
1414
|:---|:---|
15-
| `repo:list` | Looking up the repository and its head scan, on every run |
16-
| `repo:create` | Creating the repository on its first scan. Without it, a scan of a repository Socket has not seen yet exits `2`; see [below](#a-missing-repository-permission-can-exit-2) |
17-
| `full-scans:create` | Creating the scan, on every run. `--reach` also uploads manifests and finalizes the reachability scan under this scope |
15+
| `repo:list` | Looking up the repository's head scan to compare against, on diff-producing runs without `--base-scan-id` or `--base-commit-sha` |
16+
| `repo:create` | Creating the repository when that lookup finds none. Without it, the first comparison for a repository Socket has not seen yet exits `2`; see [below](#a-missing-repository-permission-can-exit-2) |
17+
| `full-scans:create` | Creating the scan, on every run. On a full-scan run with an organization-wide token, the upload also creates a missing repository under this scope. `--reach` also uploads manifests and finalizes the reachability scan under it |
1818
| `full-scans:list` | Every comparison, the `--base-commit-sha` lookup, and fetching scan contents for `--enable-json`, `--enable-sarif`, `--enable-gitlab-security` and `--generate-license` on a full scan |
1919
| `diff-scans:create` | Creating the comparison on a diff-producing run |
2020
| `diff-scans:list` | Polling for the comparison, and finding an existing one |
@@ -53,14 +53,15 @@ Every run:
5353
|:---|:---|:---|
5454
| `GET organizations` | none | Resolve the org ID and slug from the token |
5555
| `GET report/supported` | none | Fetch supported manifest patterns. On failure the CLI uses a bundled list that covers fewer ecosystems |
56-
| `GET orgs/{org}/repos/{repo}` | `repo:list` | Look up the repository and its head scan |
57-
| `POST orgs/{org}/repos` | `repo:create` | Create the repository, **only attempted if the lookup above fails** |
58-
| `POST orgs/{org}/full-scans` | `full-scans:create` | Create the new scan, and the temporary empty baseline on a first scan |
56+
| `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 |
5957

6058
Diff-producing runs (see [which runs compare](#apiaccessdenied-on-the-scan-comparison)) add:
6159

6260
| API call | Scope | Purpose |
6361
|:---|:---|:---|
62+
| `GET orgs/{org}/repos/{repo}` | `repo:list` | Look up the repository's head scan as the baseline. Skipped with `--base-scan-id` or `--base-commit-sha` |
63+
| `POST orgs/{org}/repos` | `repo:create` | Create the repository, **only attempted if the lookup above fails** |
64+
| `POST orgs/{org}/full-scans` | `full-scans:create` | Create a temporary empty baseline when the repository has no head scan yet |
6465
| `POST orgs/{org}/diff-scans/from-ids` | `diff-scans:create` and `full-scans:list` | Create the comparison (preferred path) |
6566
| `GET orgs/{org}/diff-scans` | `diff-scans:list` | Find the existing comparison when creation returns 409 |
6667
| `GET orgs/{org}/diff-scans/{id}` | `diff-scans:list` | Poll for the computed comparison |
@@ -105,7 +106,9 @@ run, that is why the warning can appear in a log with no pull request in sight.
105106
**Which scope is missing.** The fallback calls `GET orgs/{org}/full-scans/diff`, which
106107
checks `full-scans:list`. If the fallback produces results, the token already has
107108
`full-scans:list`, so the missing grant is `diff-scans:create`, `diff-scans:list`, or
108-
both. If the fallback also fails, `full-scans:list` is missing too.
109+
both. If the fallback also fails with `Insufficient permissions`, `full-scans:list`
110+
is missing too. A fallback that fails another way, such as a timeout or a dropped
111+
connection, says nothing about scopes.
109112

110113
**Why the diff-scans path is preferred.** It polls with short, bounded requests rather
111114
than holding one connection open while the backend computes, which is what lets large
@@ -121,17 +124,20 @@ total before assuming either path is at fault.
121124

122125
## A missing repository permission can exit 2
123126

124-
If the repository lookup fails, the CLI assumes the repo does not exist yet and tries
127+
A diff-producing run looks up the repository to find the head scan it compares
128+
against. If that lookup fails, the CLI assumes the repo does not exist yet and tries
125129
to create it. When the token cannot do either, the run exits with code **2** — which
126130
[the exit code table](../README.md#exit-codes) otherwise documents as a keyboard
127131
interrupt. That exit also bypasses `--disable-blocking` and `--exit-code-on-api-error`,
128132
so it fails the pipeline even when you have asked for infrastructure errors to be
129133
non-blocking.
130134

131-
This usually happens on the first scan of a repository Socket has not seen, when the
132-
token lacks `repo:create`. A token without `repo:list` can end up here even for
133-
a repository that exists, because its lookup fails and the CLI then tries to create it. The log shows `API failure while creating repository`, and on a
134-
403 adds:
135+
This usually happens on the first comparison for a repository Socket has not seen,
136+
when the token lacks `repo:create`. A token without `repo:list` can end up here even
137+
for a repository that exists, because its lookup fails and the CLI then tries to
138+
create it. Full-scan runs, such as SCM-integrated branch pushes, and runs with
139+
`--base-scan-id` or `--base-commit-sha` skip the lookup, so they never take this
140+
path. The log shows `API failure while creating repository`, and on a 403 adds:
135141

136142
```
137143
A 403 here usually means the API token is missing the repo:create scope.

0 commit comments

Comments
 (0)