|
| 1 | +# Agent Guidelines |
| 2 | + |
| 3 | +## Build & Test |
| 4 | +- **Build Lambda**: `GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -C cmd/lambda -o ../../dist/bootstrap` |
| 5 | +- **Test all**: `make test` (runs with `-race -count=1`) |
| 6 | +- **Test single package**: `go test -race -count=1 ./internal/filters` |
| 7 | +- **Test single function**: `go test -race -count=1 ./internal/filters -run TestFilterEngine_FindMatchingRule_RunsOnExample` |
| 8 | +- **Run sample locally**: `go run -C cmd/sample .` (requires `.env` file and AWS credentials for auto-close testing) |
| 9 | +- **Lint**: `go vet ./...` and `gofmt -l .` |
| 10 | + |
| 11 | +## Code Style |
| 12 | +- **Imports**: stdlib, then blank line, then third-party, then local (e.g., `internal/`) |
| 13 | +- **Naming**: Go standard - `PascalCase` exports, `camelCase` private, `ALL_CAPS` for env vars prefixed with `APP_` |
| 14 | +- **Error handling**: return errors up the stack; use `fmt.Errorf` for wrapping |
| 15 | +- **Structs**: define types in package, constructors as `New()` or `NewTypeName()`; all methods must be public (PascalCase) |
| 16 | +- **Interfaces**: keep minimal (e.g., `SecurityHubEvent` has 2 methods) |
| 17 | +- **Formatting**: use `gofmt` (tabs for indentation) |
| 18 | +- **Comments**: rare, lowercase, short, concise; code should be self-documenting |
| 19 | +- **Code smells**: keep to minimum; prefer clear naming over comments |
| 20 | + |
| 21 | +## Architecture |
| 22 | +- `cmd/lambda/main.go` - Lambda handler entry point |
| 23 | +- `cmd/sample/main.go` - Local development runner using fixtures |
| 24 | +- `internal/app/` - Core application logic and configuration |
| 25 | +- `internal/events/` - OCSF event parsing and Slack message formatting |
| 26 | +- `internal/filters/` - Auto-close rule engine and filter matching logic |
| 27 | +- `internal/actions/` - Finding update actions (auto-close via BatchUpdateFindingsV2) |
| 28 | +- `internal/notifiers/` - Optional notification integrations (Slack) |
| 29 | +- `fixtures/samples.json` - Sample Security Hub v2 OCSF findings for testing |
| 30 | + |
| 31 | +## Important Notes |
| 32 | +- This project is specifically for **AWS Security Hub v2** which uses OCSF (Open Cybersecurity Schema Framework) format |
| 33 | +- It is NOT compatible with the original AWS Security Hub (now called Security Hub CSPM) ASFF format |
| 34 | +- Security Hub v2 centralizes findings from GuardDuty, Inspector, Macie, IAM Access Analyzer, and Security Hub CSPM |
| 35 | +- Events use OCSF fields like `finding_info`, `metadata`, `severity`, `class_name`, etc. |
| 36 | +- Auto-close rules use **BatchUpdateFindingsV2** API (not BatchUpdateFindings) |
| 37 | +- Slack integration is **optional** - bot works without Slack if only auto-close is needed |
| 38 | +- Rules are evaluated in order; first match wins |
| 39 | +- Filter matching uses AND logic - all specified filters must match |
0 commit comments