Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
61 changes: 60 additions & 1 deletion docs/CI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ...
Expand Down
47 changes: 47 additions & 0 deletions examples/ci/circleci-config.yml
Original file line number Diff line number Diff line change
@@ -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