From 2e3d7069eeb6c4857edef62dc9e044e0769d6385 Mon Sep 17 00:00:00 2001 From: Toprak <64380154+Labu1@users.noreply.github.com> Date: Sun, 29 Nov 2026 11:51:46 +0300 Subject: [PATCH] docs: add CircleCI pipeline example and documentation docs/CI.md had copy-paste setups for GitHub Actions, GitLab, Jenkins and pre-commit, but CircleCI users only got the generic "Anything else" snippet. Add examples/ci/circleci-config.yml, modelled on the GitLab job: a cimg/python:3.12 image, pip install secfoo, a gated `secfoo run --agent api` with SARIF and JSONL exports, and store_artifacts for the outputs. CircleCI skips later steps once one fails, so the exit code is saved and applied in a final step after the artifacts are stored. Add a CircleCI section to docs/CI.md covering project environment variables vs. contexts for the API key and the exit codes, and link the example from the README. Fixes #174. --- README.md | 1 + docs/CI.md | 61 ++++++++++++++++++++++++++++++++- examples/ci/circleci-config.yml | 47 +++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 examples/ci/circleci-config.yml diff --git a/README.md b/README.md index 5c4254a..da330c5 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,7 @@ steps: - **GitHub Action** with SARIF upload, job summary and severity outputs: [docs/CI.md](https://github.com/secfoo-com/secfoo/blob/main/docs/CI.md#github-actions) - **pre-commit**: `repo: https://github.com/secfoo-com/secfoo`, hooks `secfoo-secrets` and `secfoo` ([example](https://github.com/secfoo-com/secfoo/blob/main/examples/ci/pre-commit-config.yaml)) - **GitLab CI** job with SARIF artifact: [examples/ci/gitlab-ci.yml](https://github.com/secfoo-com/secfoo/blob/main/examples/ci/gitlab-ci.yml) +- **CircleCI** job with SARIF artifact: [examples/ci/circleci-config.yml](https://github.com/secfoo-com/secfoo/blob/main/examples/ci/circleci-config.yml) - **Docker**: `docker run --rm ghcr.io/secfoo-com/secfoo --help` - **Anywhere else**: `secfoo run ... --json --fail-on high`, then `secfoo findings export --format sarif`. Exit codes `0` clean, `1` run failed, `2` findings gate, `3` cost gate. diff --git a/docs/CI.md b/docs/CI.md index aeee468..dbe5c82 100644 --- a/docs/CI.md +++ b/docs/CI.md @@ -199,6 +199,65 @@ not SARIF, so treat this as the hand-off file for other tools. Full job, including merge-request rules and a container-image variant: [examples/ci/gitlab-ci.yml](../examples/ci/gitlab-ci.yml). +## CircleCI + +```yaml +# .circleci/config.yml +version: 2.1 + +jobs: + secfoo: + docker: + - image: cimg/python:3.12 + steps: + - checkout + - run: pip install --quiet secfoo + - run: + name: secfoo security review + command: | + mkdir -p secfoo-out + code=0 + secfoo run --agent api --target . --depth quick --json --rescan \ + --project-name "${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" \ + --exclude secfoo-out/ \ + --skill sast --skill secret-scanning \ + --fail-on high --max-cost 2.00 > secfoo-out/secfoo-result.json || code=$? + secfoo findings export --format sarif -o secfoo-out/secfoo.sarif + secfoo findings export -o secfoo-out/secfoo-findings.jsonl + echo "$code" > secfoo-exit-code + - store_artifacts: + path: secfoo-out + destination: secfoo + - run: exit "$(cat secfoo-exit-code)" + +workflows: + security-review: + jobs: + - secfoo +``` + +Set `OPENAI_API_KEY` (or `ANTHROPIC_API_KEY` / `GEMINI_API_KEY`) in one of +two places: + +- **Project environment variable**: **Project Settings → Environment + Variables**. Available to every job in that project. +- **Context**: **Organization Settings → Contexts**, add the variable to a + context (for example `secfoo`), then reference it from the workflow with + `- secfoo: { context: secfoo }`. Use this to share one key across + projects or to restrict it to a security group. + +CircleCI masks both in job output, and neither is passed to jobs built from +forked pull requests unless you turn that on. + +CircleCI skips the remaining steps once a step fails, so the review step +records `secfoo run`'s exit code instead of failing straight away: the SARIF +and JSONL exports run, `store_artifacts` uploads `secfoo-result.json`, +`secfoo.sarif` and `secfoo-findings.jsonl` (under **Artifacts**, in +`secfoo/`), and only the last step applies the code. `0` is clean, `1` means +a skill run failed or timed out, `2` means `--fail-on` tripped, and `3` +means `--max-cost` tripped (see the [table above](#secfoo-in-ci)). Full +config: [examples/ci/circleci-config.yml](../examples/ci/circleci-config.yml). + ## Jenkins A declarative pipeline that runs in the published image. It needs the @@ -273,7 +332,7 @@ choice; build `FROM ghcr.io/secfoo-com/secfoo` and `npm install -g `/root/.secfoo`; mount it to keep findings between jobs. See the [Distribution](REFERENCE.md#distribution) notes. -## Anything else (Buildkite, CircleCI, Azure Pipelines, ...) +## Anything else (Buildkite, Azure Pipelines, ...) ```bash pip install secfoo # or: uvx secfoo run ... diff --git a/examples/ci/circleci-config.yml b/examples/ci/circleci-config.yml new file mode 100644 index 0000000..dcef884 --- /dev/null +++ b/examples/ci/circleci-config.yml @@ -0,0 +1,47 @@ +# Merge into your .circleci/config.yml +# +# AI security review as a CircleCI job. Set OPENAI_API_KEY (or +# ANTHROPIC_API_KEY / GEMINI_API_KEY) as a project environment variable +# under Project Settings -> Environment Variables, or in a context under +# Organization Settings -> Contexts (then use the `context:` variant at +# the bottom). +version: 2.1 + +jobs: + secfoo: + docker: + - image: cimg/python:3.12 + steps: + - checkout + - run: + name: Install secfoo + command: pip install --quiet secfoo + - run: + name: secfoo security review + # Exit codes: 0 clean, 1 a run failed, 2 the --fail-on gate tripped, 3 the --max-cost gate tripped. + # The code is saved and applied in the last step, so the artifacts are stored even when a gate trips. + command: | + mkdir -p secfoo-out + code=0 + secfoo run --agent api --target . --depth quick --json --rescan \ + --project-name "${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" \ + --exclude secfoo-out/ \ + --skill sast --skill secret-scanning \ + --fail-on high --max-cost 2.00 > secfoo-out/secfoo-result.json || code=$? + secfoo findings export --format sarif -o secfoo-out/secfoo.sarif + secfoo findings export -o secfoo-out/secfoo-findings.jsonl + echo "$code" > secfoo-exit-code + - store_artifacts: + path: secfoo-out + destination: secfoo + - run: + name: Apply the secfoo gate + command: exit "$(cat secfoo-exit-code)" + +workflows: + security-review: + jobs: + - secfoo + # With the API key in a context named "secfoo", use this instead: + # - secfoo: + # context: secfoo