Skip to content

Latest commit

 

History

History
72 lines (61 loc) · 3.91 KB

ci.md

File metadata and controls

72 lines (61 loc) · 3.91 KB

socket ci

Run a security scan in CI. This alias for socket scan create --report uses the default organization for your Socket API token and exits with a nonzero status if the scan fails your security policy.

socket ci

Use --auto-manifest to include locally generated manifests for supported projects. Run socket ci --help for all options.

For pull requests, socket ci skips the comparison when a clean checkout has an available base commit, at least one supported manifest is discoverable, and no supported manifest or lockfile changed in the PR range. The JSON result is { "ok": true, "skipped": true, "reason": "no-manifest-changes" } so CI can distinguish this successful no-op from a clean scan. The command runs a normal scan when the base commit or file patterns are unavailable, the checkout is dirty, symlinks or submodules make the inputs uncertain, no supported manifests are discoverable, or auto-manifest generation is enabled.

Use --json-format python-v1 to emit a versioned, Python-compatible diff payload for pull request comparisons. The selector returns a usage error before scanning when the run is not in a pull request, because no diff can be calculated. See scan diff for fields and status meanings.

On GitHub pull request runs, pass a GitHub token with pull request write permission in SOCKET_CLI_GITHUB_TOKEN, GITHUB_TOKEN, or GH_TOKEN. The command posts an overview and a security findings comment, and updates them on reruns. Socket renders these comments from the PR diff scan using the Socket API token. The token needs full-scans:list, diff-scans:create, and diff-scans:list for the diff and its comments.

Set SOCKET_CLI_DISABLE_OVERVIEW_COMMENT=true or SOCKET_CLI_DISABLE_SECURITY_COMMENT=true to skip either comment.

GitLab merge request notes are opt-in. Set SOCKET_CLI_ENABLE_GITLAB_MR_NOTES=true in a GitLab merge request pipeline to let socket ci publish and update the same overview and security notes. This opt-in avoids duplicate notes when a managed Socket integration already posts them. The pipeline needs CI_SERVER_URL, CI_API_V4_URL, CI_MERGE_REQUEST_IID, CI_MERGE_REQUEST_PROJECT_ID, and CI_MERGE_REQUEST_PROJECT_URL. Notes are written to the target project, including for merge requests from forks.

For a personal or project access token, set SOCKET_CLI_GITLAB_TOKEN (or GITLAB_TOKEN) to a token with the api scope and at least Developer access to the target project. CI_JOB_TOKEN cannot create merge request notes through GitLab's Notes API (job-token access is limited to selected endpoints), so it is not sufficient for publishing. Do not expose a long-lived access token to untrusted fork pipelines. The Socket API token still needs full-scans:list, diff-scans:create, and diff-scans:list to fetch the diff and rendered comments.

GitLab commit status is also opt-in. Set SOCKET_CLI_ENABLE_GITLAB_COMMIT_STATUS=true to publish a status for the pipeline's CI_PROJECT_ID and CI_COMMIT_SHA. Merge request pipelines use the pipeline commit (including a merge train commit); the status description says either No blocking findings, Blocking findings detected, or Scan did not complete for an API or infrastructure failure. A successful scan status links to the diff report when the Socket API returned a report URL. Status publication errors are reported separately and do not change the scan's exit status. The GitLab access token needs api scope and Developer access to the pipeline project. CI_JOB_TOKEN cannot write commit statuses.

To change the target project's merge policy, also set SOCKET_CLI_ENABLE_GITLAB_MERGE_PIPELINE_CHECK=true. This separately opts in to requiring successful pipelines before merge. It updates the target project (CI_MERGE_REQUEST_PROJECT_ID) and requires Maintainer access. Leave this variable unset if Socket should report scan results without changing project settings.