Skip to content

Commit 07dab16

Browse files
committed
this is how to integrate ai-sast
1 parent edf70fa commit 07dab16

3 files changed

Lines changed: 52 additions & 20 deletions

File tree

.github/workflows/ai-sast.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
# Important: For feedback collection to trigger, this file must be on your default branch (e.g. main).
55
# GitHub runs issue_comment workflows from the default branch only.
66
#
7-
# Required: copy this file as .github/workflows/ai-sast.yml, add secrets:
7+
# Required: fork this repo, copy this file as .github/workflows/ai-sast.yml into the repo you want to scan,
8+
# set variable AI_SAST_REPO to your fork (e.g. your-username/ai-sast), add secrets:
89
# GOOGLE_CLOUD_PROJECT, GOOGLE_CREDENTIALS
9-
# Default: checks out rivian/ai-sast. Optional: set AI_SAST_REPO (e.g. for a fork);
10-
# AI_SAST_BASE_BRANCH (default: main); AI_SAST_REF (default: main); runs-on for self-hosted.
10+
# Optional: AI_SAST_BASE_BRANCH (default: main); AI_SAST_REF (default: main); runs-on for self-hosted.
1111
#
1212
# PR scan runs only when the PR diff touches supported file extensions (see paths below).
1313
# workflow_dispatch and issue_comment have no path filter.
@@ -103,10 +103,17 @@ jobs:
103103
- name: Prepare feedback DB directory
104104
run: mkdir -p .ai-sast-db
105105

106+
- name: Require AI_SAST_REPO (use your fork)
107+
run: |
108+
if [ -z "${{ vars.AI_SAST_REPO }}" ]; then
109+
echo "::error::Fork this repository (https://github.com/rivian/ai-sast), then set the repository variable AI_SAST_REPO to your fork (e.g. your-username/ai-sast). Settings → Secrets and variables → Actions → Variables."
110+
exit 1
111+
fi
112+
106113
- name: Checkout AI-SAST
107114
uses: actions/checkout@v4
108115
with:
109-
repository: ${{ vars.AI_SAST_REPO || 'rivian/ai-sast' }}
116+
repository: ${{ vars.AI_SAST_REPO }}
110117
path: ai-sast
111118
ref: ${{ vars.AI_SAST_REF || 'main' }}
112119

@@ -237,10 +244,17 @@ jobs:
237244
- name: Prepare feedback DB directory
238245
run: mkdir -p .ai-sast-db
239246

247+
- name: Require AI_SAST_REPO (use your fork)
248+
run: |
249+
if [ -z "${{ vars.AI_SAST_REPO }}" ]; then
250+
echo "::error::Fork this repository (https://github.com/rivian/ai-sast), then set the repository variable AI_SAST_REPO to your fork (e.g. your-username/ai-sast). Settings → Secrets and variables → Actions → Variables."
251+
exit 1
252+
fi
253+
240254
- name: Checkout AI-SAST
241255
uses: actions/checkout@v4
242256
with:
243-
repository: ${{ vars.AI_SAST_REPO || 'rivian/ai-sast' }}
257+
repository: ${{ vars.AI_SAST_REPO }}
244258
path: ai-sast
245259
ref: ${{ vars.AI_SAST_REF || 'main' }}
246260

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@ AI-SAST is an AI-driven static application security testing tool. Run it in **yo
2828

2929
## Integrate in your repository
3030

31-
1. **Copy the workflow file** into your repo as `.github/workflows/ai-sast.yml`:
31+
1. **Fork this repository** so the workflow uses your fork (and so the project’s fork count reflects adoption).
32+
33+
2. **Copy the workflow file** into the repo you want to scan as `.github/workflows/ai-sast.yml`:
3234
[`.github/workflows/ai-sast.yml`](.github/workflows/ai-sast.yml)
3335

34-
2. **Add repository secrets** (Settings → Secrets and variables → Actions):
36+
3. **Set the repository variable** (Settings → Secrets and variables → Actions → Variables):
37+
`AI_SAST_REPO` = your fork (e.g. `your-username/ai-sast`).
38+
39+
4. **Add repository secrets** (Settings → Secrets and variables → Actions → Secrets):
3540
`GOOGLE_CLOUD_PROJECT`, `GOOGLE_CREDENTIALS`
3641

37-
The workflow checks out **`rivian/ai-sast`** at runtime. One file runs **PR scan** (on pull requests when base branch is `main`), **full scan** (manual "Run workflow"), and **feedback collection** (when someone edits a PR comment and checks a true/false positive box).
42+
The workflow checks out **your fork** at runtime. One file runs **PR scan** (on pull requests when base branch is `main`), **full scan** (manual "Run workflow"), and **feedback collection** (when someone edits a PR comment and checks a true/false positive box).
3843

39-
**Optional:** Set variable `AI_SAST_REPO` (e.g. for a fork); `AI_SAST_BASE_BRANCH` (default `main`); `runs-on: self-hosted` in the workflow for your own runners.
44+
**Optional:** Set `AI_SAST_BASE_BRANCH` (default `main`); `AI_SAST_REF` (default `main`); `runs-on: self-hosted` in the workflow for your own runners.
4045

4146
📚 **Full guide:** [docs/INTEGRATION.md](docs/INTEGRATION.md)
4247

@@ -98,7 +103,7 @@ All configuration is driven by environment variables. The table below lists supp
98103
| Variable | Description | Default |
99104
|----------|-------------|---------|
100105
| **Workflow & scan behavior** | | |
101-
| `AI_SAST_REPO` | GitHub repo to checkout (e.g. `org/ai-sast` or a fork). | `rivian/ai-sast` (in workflow) |
106+
| `AI_SAST_REPO` | Your fork of this repo (e.g. `your-username/ai-sast`). **Required**—fork first, then set this variable. | |
102107
| `AI_SAST_BASE_BRANCH` | Branch that triggers PR scan; PRs targeting this branch are scanned. | `main` |
103108
| `AI_SAST_SEVERITY` | Comma-separated severities to include in PR comments (e.g. `critical,high,medium`). The validator runs only on findings in these severities. | `critical,high` |
104109
| `AI_SAST_UPDATE_SAME_PR_COMMENT` | When `true`, each PR scan run updates the same PR comment with the latest results instead of posting a new comment (reduces noise on multi-commit PRs). When `false` or unset, a new comment is posted every time (default). | `false` |
@@ -158,7 +163,7 @@ All configuration is driven by environment variables. The table below lists supp
158163
- **Auth errors:** Service account needs "Vertex AI User" role; `GOOGLE_CREDENTIALS` must be the full JSON key.
159164
- **No PR comment:** Ensure the PR targets the branch set by `AI_SAST_BASE_BRANCH` (default `main`).
160165
- **Feedback not triggering:** The feedback job runs from your **default branch** (e.g. `main`). Make sure `ai-sast.yml` is merged to that branch—if it only exists on a feature branch, checking boxes in the PR comment won’t trigger the workflow.
161-
- **Using a fork:** Set repository variable `AI_SAST_REPO` to your `org/ai-sast`.
166+
- **Setup:** Fork this repo, then set repository variable `AI_SAST_REPO` to your fork (e.g. `your-username/ai-sast`).
162167

163168
## Support
164169

docs/INTEGRATION.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
# Integrating AI-SAST into Your Repository
22

3-
Run AI-SAST (PR scan + full scan) **in your repo on your runners**. The workflow checks out the ai-sast scanner at runtime—no submodule or manual copy. Your code never runs on ai-sast infrastructure.
3+
Run AI-SAST (PR scan + full scan) **in your repo on your runners**. The workflow checks out your fork of the ai-sast scanner at runtime—no submodule or manual copy. Your code never runs on ai-sast infrastructure.
44

5-
## Required (2 steps)
5+
## Required (4 steps)
66

7-
### 1. Copy the workflow file
7+
### 1. Fork this repository
8+
9+
Fork [rivian/ai-sast](https://github.com/rivian/ai-sast) so the workflow uses your fork. This also helps the project’s visibility (fork count) and lets you customize the scanner.
10+
11+
### 2. Copy the workflow file
812

913
- **From this repo:** [`.github/workflows/ai-sast.yml`](../.github/workflows/ai-sast.yml)
10-
- **Save as:** `.github/workflows/ai-sast.yml` in **your** repository.
14+
- **Save as:** `.github/workflows/ai-sast.yml` in the **repository you want to scan** (not necessarily the fork).
1115

1216
This single file runs PR scan, full scan, and feedback collection (when developers check boxes in PR comments). Feedback is stored in a database and included in the Vertex AI prompt on future scans to improve accuracy.
1317

14-
### 2. Add Google secrets
18+
### 3. Set the AI_SAST_REPO variable
19+
20+
In the repository you want to scan: **Settings → Secrets and variables → Actions → Variables**
21+
22+
| Variable | Value |
23+
|----------|--------|
24+
| `AI_SAST_REPO` | Your fork (e.g. `your-username/ai-sast`) |
25+
26+
The workflow will checkout this repo at runtime. If you skip this, the workflow will fail with instructions to fork and set the variable.
27+
28+
### 4. Add Google secrets
1529

16-
In your repository: **Settings → Secrets and variables → Actions → Secrets**
30+
In the same repository: **Settings → Secrets and variables → Actions → Secrets**
1731

1832
| Secret | Description |
1933
|--------|-------------|
2034
| `GOOGLE_CLOUD_PROJECT` | Your GCP project ID |
2135
| `GOOGLE_CREDENTIALS` | Service account JSON (full contents of the key file) |
2236

23-
The workflow checks out **`rivian/ai-sast`** by default. That’s it—PR scan runs on pull requests (when base branch matches), full scan (manual "Run workflow"), and feedback collection (when a PR comment with the AI-SAST scan is edited and checkboxes are used).
37+
That’s it—PR scan runs on pull requests (when base branch matches), full scan (manual "Run workflow"), and feedback collection (when a PR comment with the AI-SAST scan is edited and checkboxes are used).
2438

2539
## Optional
2640

2741
- **LLM provider:** Default is **Vertex AI** (Gemini). To use **AWS Bedrock (Claude)** set variable **`AI_SAST_LLM`** = `bedrock`, and set **`AWS_REGION`** (e.g. `us-east-1`), **`BEDROCK_MODEL_ID`**. Add AWS credentials as secrets (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`) or use an IAM role on the runner. For local **Ollama**, set **`AI_SAST_LLM`** = `ollama`.
28-
- **Using a fork:** Set repository variable **`AI_SAST_REPO`** (e.g. `your-org/ai-sast`) to checkout your fork instead of `rivian/ai-sast`.
2942
- **Default branch for PR scan:** Add variable **`AI_SAST_BASE_BRANCH`** (e.g. `main`, `master`, `develop`). Default is `main` if unset.
3043
- **Scanner ref:** Add variable **`AI_SAST_REF`** (e.g. `main`, `v1.0`) to pin the ai-sast version. Default is `main`.
3144
- **Update same PR comment:** Set **`AI_SAST_UPDATE_SAME_PR_COMMENT`** = `true` to update the existing AI-SAST comment on each scan run instead of posting a new one (reduces noise when multiple commits trigger multiple scans). Default is `false`.
@@ -38,7 +51,7 @@ The workflow checks out **`rivian/ai-sast`** by default. That’s it—PR scan r
3851

3952
## Troubleshooting
4053

41-
- **“repository not found” or checkout fails:** You may be using a fork; set `AI_SAST_REPO` to your `org/ai-sast`.
54+
- **“repository not found” or checkout fails:** Ensure `AI_SAST_REPO` is set to your fork (e.g. `your-username/ai-sast`). You must fork the repo first.
4255
- **No PR comment:** Check that the PR targets the branch set by `AI_SAST_BASE_BRANCH` (or `main`). Check the “Run AI-SAST PR Scan” step logs.
4356
- **Feedback not triggering when you check boxes:** The `issue_comment` event runs the workflow from your **default branch** (e.g. `main`). Ensure `ai-sast.yml` is committed and merged to that branch—if the file exists only on a feature branch, feedback collection will not run.
4457
- **Auth errors:** Ensure the service account has the “Vertex AI User” role and that `GOOGLE_CREDENTIALS` is the **full** JSON key (not a path).

0 commit comments

Comments
 (0)