# BaghGuard documentation

BaghGuard runs four open-source security scanners across the GitHub
repositories you choose, normalizes everything they report into one schema,
and shows it in a single dashboard. It can also alert you on Slack or by
email, and open fix PRs for a narrow class of dependency issues.

This page is the reference for both people and automated agents. The exact
same text is served three ways, all public and none requiring a session:

| URL | Format | For |
|---|---|---|
| `https://baghguard.com/docs` | HTML | Reading in a browser |
| `https://baghguard.com/docs.md` | Markdown | Agents, scripts, `curl` |
| `https://baghguard.com/llms.txt` | Markdown index | Agents discovering what is here |

## How it works

```
   push to main/master ──> webhook receiver ──┐
                                              │
   every 6 hours ─────────────────────────────┤
                                              v
                              trivy · checkov · gitleaks · grype
                                              │
                                              v
                                   shared results volume
                                              │
                                              v
                                     result normalizer
                                              │
                                              v
                                    findings (PostgreSQL)
                                    │         │         │
                                    v         v         v
                              dashboard   Slack and   fix PRs
                                            email      (beta)
```

1. A scan is triggered, either on the six-hourly schedule or immediately by a
   push to a repo that has the webhook installed.
2. Each scanner clones the selected repositories and writes raw JSON results
   to a shared volume.
3. The normalizer converts all four output formats into one findings schema,
   de-duplicates against what is already stored, and attributes each finding
   to the user who selected that repository.
4. The dashboard, the alerters, and the remediator all read from that one
   findings table.

Findings are per-user. Two people who both select the same public repository
each get their own copy, with their own open/ignored state.

## Quick start

1. **Sign in** at `https://baghguard.com` with your GitHub account.
2. **Wait for approval.** New accounts start on a waitlist; you get an email
   when an admin approves yours.
3. **Select repositories** on the **Repos** tab, then press **Save
   Selection**.
4. **Optionally turn on notifications** in the same page: Slack, email, or
   automatic fix PRs.
5. **Wait for the first scan.** It runs on the next six-hourly cycle, or
   immediately if you install the push webhook.
6. **Read the results** on the **Findings** tab.

## Access and approval

Sign-in is GitHub OAuth only - there are no BaghGuard passwords. The
requested scopes are:

| Scope | Why |
|---|---|
| `public_repo` | Read your public repositories, and push a branch plus open a PR if you enable automatic fix PRs |
| `read:user` | Your username and avatar for the header |
| `user:email` | Your primary address, used to email you about approval and (if enabled) findings |

New accounts are created with status `pending`. While pending you can sign in
but you cannot select repositories or receive findings; the site shows a
waitlist page instead. An admin approves or rejects each account. If yours was
rejected, the waitlist page has a **Request approval again** button.

Sessions are a `pg_session` cookie, valid for 7 days, set `HttpOnly`,
`SameSite=Lax`, `Secure`. **Sign out** clears the session server-side.

## Selecting repositories

The Repos tab lists **public repositories you own**. Private repositories are
not shown and cannot be scanned - the OAuth scope deliberately does not cover
them. Forks and repositories owned by an organization you belong to are also
excluded; the list is filtered to `affiliation=owner`.

- Select any number of repositories and press **Save Selection**. Nothing is
  scanned until you do.
- Your selection takes effect on the next scan cycle, not retroactively.
- Deselecting a repository stops future scans of it. Findings already stored
  stay on your dashboard; mark them ignored if you no longer care about them.

## Scanners and schedule

| Scanner | What it finds | Runs at (UTC) |
|---|---|---|
| [Trivy](https://github.com/aquasecurity/trivy) | Dependency CVEs and infrastructure-as-code misconfiguration | Every 6 hours, on the hour |
| [Checkov](https://github.com/bridgecrewio/checkov) | Terraform and other IaC policy violations | Every 6 hours, 15 minutes past |
| [Gitleaks](https://github.com/gitleaks/gitleaks) | Secrets committed to the repository | Every 6 hours, 30 minutes past |
| [Grype](https://github.com/anchore/grype) | Vulnerable dependencies | Every 6 hours, 45 minutes past |

The scanners are staggered on purpose so four clones of every selected
repository do not start at the same moment.

Severity notes worth knowing when you read the dashboard:

- Trivy is configured to report **MEDIUM and above**, so it will not surface
  LOW-severity CVEs.
- Every Gitleaks finding is recorded as **HIGH** - a committed secret is
  treated as serious regardless of what kind of secret it is.
- Checkov findings without a severity of their own default to **MEDIUM**.
- Grype passes through whatever severity its vulnerability database reports.

## Push-triggered scans

Scheduled scans mean a new vulnerability can sit unreported for up to six
hours. A webhook closes that gap by running all four scanners as soon as you
push.

| Setting | Value |
|---|---|
| Payload URL | `https://baghguard.com/webhook` |
| Content type | `application/json` |
| Secret | Issued by BaghGuard - ask before you add the webhook |
| Events | Just the `push` event |

Only pushes to `main` or `master` trigger a scan; pushes to any other branch
are acknowledged and ignored. Every delivery must carry a valid
`X-Hub-Signature-256` HMAC or it is rejected with `401`.

Responses you will see in GitHub's **Recent Deliveries** tab:

```json
{"status": "ok", "message": "Triggered 4 scanners",
 "scanners": ["trivy-scanner", "checkov-scanner",
              "gitleaks-scanner", "grype-scanner"]}
```

```json
{"status": "skipped", "message": "Ignoring push to refs/heads/feature-x"}
```

```json
{"status": "ok", "message": "Pong!"}
```

A push-triggered scan runs the same scanners over the same repository list as
the scheduled one - it does not scan only the repository that was pushed.

## The findings dashboard

The **Findings** tab shows everything found across your selected
repositories.

- **Stat tiles** across the top: total open findings and a count per severity.
- **Three breakdowns**: by severity, by scanner, and by repository.
- **Open backlog, last 30 days**: how your open findings have trended, so you
  can tell a growing backlog from a shrinking one.
- **Filters**: Open/Ignored, severity chips, and a search box that matches
  repository, package, CVE ID, description, and file path.

Each finding carries the scanner that reported it, a severity, the CVE ID
where there is one, the affected package, the file and line, a description,
and a fix version when one is known.

Every finding is either:

| Status | Meaning |
|---|---|
| `open` | Counted in the tiles and charts, eligible for alerts and fix PRs |
| `ignored` | Hidden from the default view and excluded from alerts; still stored, and you can switch back at any time |

Ignoring is per-user, so it never hides a finding from anyone else who has
selected the same repository. There is no "resolved" state to set by hand -
re-scanning a fixed repository simply stops re-reporting the finding.

## Notifications

Both channels are configured per-user at the bottom of the Repos tab, and both
alert only on **CRITICAL and HIGH open findings**.

| Channel | What you configure | Cadence |
|---|---|---|
| Slack | An incoming webhook URL | Checked every 60 seconds |
| Email | One or more addresses, comma-separated | A digest, once every 24 hours |

Each cycle alerts on findings first seen since the previous cycle, so a
finding you have already been told about is not repeated. Ignored findings are
never alerted on.

Enabling Slack without a webhook URL, or email without at least one valid
address, is rejected when you save.

## Automatic fix PRs (Beta)

If you tick **Open fix PRs automatically**, BaghGuard will raise pull requests
for the narrow class of findings it can fix mechanically and safely.

A finding is eligible only when **all** of these hold:

- Severity is CRITICAL or HIGH.
- It came from Trivy or Grype (dependency scanners).
- The vulnerability database reports a known fix version.
- The affected file is a `requirements.txt`, and the vulnerable package is a
  plain pin in it, such as `flask==2.0.1`.

Anything else - npm, Go modules, a version resolved through a lockfile, a
range rather than a pin - is out of scope and is left for you.

What the PR looks like:

| | |
|---|---|
| Branch | `baghguard/fix-<package>-<version>` |
| Title | `[BaghGuard] Fix <SEVERITY> <CVE list> in <package>` |
| Change | One line in one `requirements.txt`, bumped to the fix version |
| Body | Which CVEs it covers, the version it moves to, and the scanner descriptions |

Things to be clear about before enabling it:

- **BaghGuard never merges.** It opens the PR; you review, run your CI, and
  merge or close it.
- **The PR is authored by you**, using the GitHub token from your sign-in.
  There is no bot account, so your repository's CI runs with your permissions
  as it normally would.
- **One PR per pin, not per CVE.** Several CVEs against the same package
  collapse into one PR that bumps to a version clearing all of them.
- **One attempt per finding.** If opening a PR fails, or the pin is not in a
  shape it can patch, that finding is recorded and never retried - it will not
  churn your repository with repeated attempts.
- Eligible findings are picked up within about five minutes.

## Using BaghGuard in CI

Separately from the hosted service there is a standalone GitHub Action that
runs the same four scanners inside your own workflow and fails the build above
a severity threshold you pick:

```yaml
name: CI
on: [push, pull_request]

jobs:
  security-scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: sitardaniel/pipelineguard-action@main
        with:
          fail-on: HIGH
```

| Input | Default | Description |
|---|---|---|
| `path` | `.` | Directory to scan, relative to the repository root |
| `fail-on` | `HIGH` | Minimum severity that fails the build: `CRITICAL`, `HIGH`, `MEDIUM`, `LOW`, or `NONE` to report without failing |
| `scanners` | `trivy,checkov,gitleaks,grype` | Comma-separated; drop the ones that do not apply to your repository |

The action is self-contained: it needs no BaghGuard account, sends nothing to
`https://baghguard.com`, and writes its results to the workflow run summary. Results from
it do **not** appear on your dashboard.

## Data, permissions, and security

Stored per user: GitHub numeric ID, username, avatar URL, primary email
address, the OAuth access token, the repositories you selected, your
notification settings, and your findings.

The access token is stored because scans and fix PRs happen asynchronously,
after your browser session is gone. Signing out ends your session but does not
revoke the token - to fully disconnect, revoke BaghGuard from
[GitHub's authorized OAuth apps settings](https://github.com/settings/applications).

Other things worth knowing:

- Findings are scoped to their owner in the database, not just hidden in the
  UI. There is no endpoint that returns another user's findings.
- Webhook deliveries are authenticated with an HMAC signature; unsigned or
  wrongly signed requests are rejected.
- The site is HTTPS-only; HTTP redirects, and certificates come from Let's
  Encrypt.
- Admin endpoints are restricted to a fixed allowlist of GitHub usernames
  configured on the server, not to a role you can grant yourself.

To report a security problem in BaghGuard itself, see
[SECURITY.md](https://github.com/sitardaniel/pipelineguard-app/blob/main/SECURITY.md)
rather than opening a public issue.

## HTTP endpoints

Everything except the public routes needs the `pg_session` cookie. Routes
marked "approved" additionally reject accounts still on the waitlist.

| Method | Path | Auth | Purpose |
|---|---|---|---|
| GET | `/health` | public | Liveness check, returns `{"status":"healthy"}` |
| GET | `/docs` | public | This page |
| GET | `/docs.md` | public | This page as Markdown |
| GET | `/llms.txt` | public | Documentation index for agents |
| GET | `/login` | public | Starts GitHub OAuth |
| GET | `/auth/callback` | public | OAuth redirect target |
| GET | `/logout` | session | Ends the session, redirects to `/` |
| GET | `/` | approved | Repository selection page |
| GET | `/findings` | approved | Findings dashboard |
| POST | `/save` | approved | Save selected repositories and notification settings |
| POST | `/findings/status` | approved | Set one finding to `open` or `ignored` |
| POST | `/request-again` | session | Ask for another approval review after a rejection |
| GET | `/admin` | admin | Waitlist review page |
| POST | `/admin/approve` | admin | Approve one account |
| POST | `/admin/reject` | admin | Reject one account |
| POST | `/admin/approve-all` | admin | Approve every pending account |
| POST | `/admin/notify-waitlist` | admin | Email the waitlist that BaghGuard is live |
| POST | `/webhook` | HMAC | GitHub push events |

`POST /save` takes:

```json
{
  "repos": ["https://github.com/you/your-repo"],
  "notify": {
    "slack_enabled": true,
    "slack_webhook": "https://hooks.slack.com/services/...",
    "email_enabled": true,
    "email_to": ["you@example.com"],
    "remediate_enabled": false
  }
}
```

and returns `{"status": "ok", "count": 1}`.

`POST /findings/status` takes `{"id": "<finding-uuid>", "status": "ignored"}`
and returns `{"status": "ok"}`. `status` must be `open` or `ignored`.

Errors from any JSON route are `{"error": "<message>"}` with a `4xx`/`5xx`
code.

## Notes for agents

If you are an automated agent working on behalf of a BaghGuard user:

- **Start from `https://baghguard.com/docs.md`.** It is the same content as this page in
  Markdown, and it is public - fetch it directly rather than trying to scrape
  the HTML.
- **There are no API tokens.** Every route other than `/health`, `/docs`,
  `/docs.md`, `/llms.txt`, and the OAuth entry points requires a `pg_session`
  cookie that only an interactive GitHub OAuth login can produce. You cannot
  provision your own access; if you need a signed-in session, the person you
  are working for has to complete the login.
- **Most routes return HTML, not JSON.** Only `/save`, `/findings/status`,
  `/health`, and the `/admin/*` routes speak JSON. The findings themselves are
  embedded in the `/findings` page as a JSON array, not exposed as a separate
  endpoint.
- **Scoping is server-side.** Every query is filtered by the session's user.
  Do not construct requests that try to read another account's findings; they
  will not work, and attempting it is not a supported use of the service.
- **Safe to do unattended** on a user's behalf, once they have a session:
  reading findings, marking a finding ignored, changing which repositories are
  selected.
- **Ask a human first** before: enabling automatic fix PRs, merging a fix PR
  BaghGuard opened, changing notification recipients, or anything under
  `/admin`.
- **Be gentle.** These are single-instance services. Poll no faster than the
  underlying cadence is worth - findings only change when a scan completes,
  which is at most every six hours unless a push triggers one.

## Troubleshooting

| Symptom | Likely cause | What to do |
|---|---|---|
| Signed in, but the site shows a waitlist page | Your account is still `pending` | Wait for approval; you will get an email |
| A repository is missing from the Repos tab | It is private, a fork, or owned by an organization | Only public repositories you own can be scanned |
| No findings after selecting repositories | The first scheduled scan has not run yet | Wait for the next six-hourly cycle, or install the push webhook |
| No Slack alerts | Webhook URL is wrong, or the findings are below CRITICAL/HIGH | Re-check the URL on the Repos tab; only CRITICAL and HIGH are alerted |
| Email alerts arrive late | Email is a daily digest, not real-time | Use Slack if you need alerts within a minute |
| No fix PR for a fixable CVE | Not a `requirements.txt` pin, no known fix version, or one was already attempted | Fix that pin by hand; each finding is only attempted once |
| A push does not trigger a scan | Pushed to a branch other than `main`/`master`, or the HMAC secret does not match | Check GitHub's Recent Deliveries for the response body |

## Support

- **Access requests, questions, and the webhook secret**: open an issue on
  [pipelineguard-app](https://github.com/sitardaniel/pipelineguard-app/issues).
- **A security problem in BaghGuard itself**: do not open a public issue - use
  a private [GitHub Security Advisory](https://github.com/sitardaniel/pipelineguard-app/security/advisories/new),
  as described in
  [SECURITY.md](https://github.com/sitardaniel/pipelineguard-app/blob/main/SECURITY.md).


Source: [pipelineguard-app](https://github.com/sitardaniel/pipelineguard-app)
(services), [pipelineguard-gitops](https://github.com/sitardaniel/pipelineguard-gitops)
(Kubernetes manifests),
[pipelineguard-action](https://github.com/sitardaniel/pipelineguard-action)
(the CI action).
