-
Notifications
You must be signed in to change notification settings - Fork 15
feat(scanners): additional findings processor #7518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a7faa3e
config
lcampbell2 edc43a5
database
lcampbell2 e1c0234
model
lcampbell2 950ae58
runner
lcampbell2 945e9ca
main
lcampbell2 84c5a2c
ops + docs
lcampbell2 8cc6924
make fmt
lcampbell2 958e269
fix cloudbuild ci path
lcampbell2 ff32d45
remove unneeded schemaVersion from README
lcampbell2 9960dac
fix occurrenceCount typo
lcampbell2 b446b43
move derived finding key to separate value in finding doc
lcampbell2 51e0405
rm actions.go
lcampbell2 4520be3
add handler for sub.Drain()
lcampbell2 001e613
remove test seams in prod code
lcampbell2 ace6f7c
refactor unit tests and add integration tests
lcampbell2 2aa4b80
migrate legacy nats subscription to jetstream consumer
lcampbell2 62455c9
add integration testing to cloudbuild
lcampbell2 d6d23c3
drop shared docker volume path as GCB implicitly shares between steps
lcampbell2 a3c71cb
upgrade nats.go package
lcampbell2 11d8b07
add missing err handlers and fixed graceful shutdown
lcampbell2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| NATS_URL= | ||
| NATS_STREAM= | ||
| NATS_SUBJECT= | ||
| NATS_CONSUMER_DURABLE= | ||
| NATS_QUEUE_GROUP= | ||
| NATS_ACK_WAIT= | ||
| NATS_MAX_DELIVER= | ||
| NATS_MAX_ACK_PENDING= | ||
|
|
||
| DB_URL= | ||
| DB_USER= | ||
| DB_NAME= | ||
| DB_PASS= | ||
|
|
||
| LOG_LEVEL= | ||
| LOG_PRETTY= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| FROM golang:1.25.0-alpine3.22 AS build | ||
|
|
||
| WORKDIR /src | ||
|
|
||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
|
|
||
| COPY . . | ||
| RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/findings-processor ./cmd/service | ||
|
|
||
| FROM alpine:3.22 | ||
|
|
||
| RUN addgroup -S app && adduser -S app -G app | ||
| USER app | ||
|
|
||
| WORKDIR /app | ||
| COPY --from=build /out/findings-processor /app/findings-processor | ||
|
|
||
| ENTRYPOINT ["/app/findings-processor"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| .PHONY: help run test test-race test-integration build fmt fmt-check vet lint tidy ci | ||
|
|
||
| GO ?= go | ||
| SERVICE_BIN ?= findings-processor | ||
| BUILD_DIR ?= bin | ||
|
|
||
| help: | ||
| @printf "Targets:\n" | ||
| @printf " make run - Run the service\n" | ||
| @printf " make test - Run all tests\n" | ||
| @printf " make test-race - Run tests with race detector\n" | ||
| @printf " make test-integration - Run integration tests (requires Docker)\n" | ||
| @printf " make build - Build service binary\n" | ||
| @printf " make fmt - Format Go files\n" | ||
| @printf " make fmt-check - Check formatting (no changes)\n" | ||
| @printf " make vet - Run go vet\n" | ||
| @printf " make lint - Run fmt-check + vet\n" | ||
| @printf " make tidy - Tidy modules\n" | ||
| @printf " make ci - Lint, test, build\n" | ||
|
|
||
| run: | ||
| $(GO) run ./cmd/service | ||
|
|
||
| test: | ||
| $(GO) test ./... | ||
|
|
||
| test-integration: | ||
| $(GO) test -tags integration ./... | ||
|
|
||
| test-race: | ||
| $(GO) test -race ./... | ||
|
|
||
| build: | ||
| mkdir -p $(BUILD_DIR) | ||
| CGO_ENABLED=0 $(GO) build -o $(BUILD_DIR)/$(SERVICE_BIN) ./cmd/service | ||
|
|
||
| fmt: | ||
| $(GO) fmt ./... | ||
|
|
||
| fmt-check: | ||
| @test -z "$$($(GO)fmt -l .)" || (printf "Unformatted files found. Run 'make fmt'.\n" && exit 1) | ||
|
|
||
| vet: | ||
| $(GO) vet ./... | ||
|
|
||
| lint: fmt-check vet | ||
|
|
||
| tidy: | ||
| $(GO) mod tidy | ||
|
|
||
| ci: lint test build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Findings Processor | ||
|
|
||
| Consumes finding events from NATS JetStream and upserts normalized finding documents into ArangoDB `additionalFindings`. | ||
|
|
||
| ## What it does | ||
|
|
||
| - Subscribes to `scans.findings.*` (configurable) | ||
| - Validates incoming payloads | ||
| - Writes findings to ArangoDB | ||
| - Acknowledges messages with explicit `Ack` / `Nak` / `Term` behavior | ||
|
|
||
| ## Event contract (current) | ||
|
|
||
| Expected JSON fields: | ||
|
|
||
| - Required: `source`, `findingType`, `domainKey`, `subject`, `confidence`, `observedAt` | ||
| - Optional: `severity`, `reasonCode`, `evidence`, `attributes` | ||
|
|
||
| `observedAt` must be RFC3339. | ||
|
|
||
| ## Local development | ||
|
|
||
| 1. Copy env template: | ||
|
|
||
| ```bash | ||
| cp .env.example .env | ||
| ``` | ||
|
|
||
| 2. Fill required vars in `.env` (at minimum DB and NATS settings). | ||
|
|
||
| 3. Run service: | ||
|
|
||
| ```bash | ||
| go run ./cmd/service | ||
| ``` | ||
|
|
||
| ## Environment variables | ||
|
|
||
| | Variable | Default | Notes | | ||
| | ----------------------- | ----------------------- | ---------------------------- | | ||
| | `NATS_URL` | `nats://localhost:4222` | NATS server URL | | ||
| | `NATS_STREAM` | `SCANS` | JetStream stream name | | ||
| | `NATS_SUBJECT` | `scans.findings.*` | Subscription subject | | ||
| | `NATS_CONSUMER_DURABLE` | `findings-processor` | Durable consumer name | | ||
| | `NATS_ACK_WAIT` | `30s` | Ack timeout | | ||
| | `NATS_MAX_DELIVER` | `10` | Max redeliveries | | ||
| | `NATS_MAX_ACK_PENDING` | `256` | Max pending unacked messages | | ||
| | `DB_URL` | `http://localhost:8529` | ArangoDB URL | | ||
| | `DB_USER` | _(none)_ | ArangoDB user | | ||
| | `DB_NAME` | _(none)_ | ArangoDB database | | ||
| | `DB_PASS` | _(empty)_ | ArangoDB password | | ||
| | `LOG_LEVEL` | `info` | Zerolog global level | | ||
| | `LOG_PRETTY` | `true` | Human-readable logs | | ||
|
|
||
| ## Docker | ||
|
|
||
| Build: | ||
|
|
||
| ```bash | ||
| docker build -t findings-processor . | ||
| ``` | ||
|
|
||
| Run: | ||
|
|
||
| ```bash | ||
| docker run --rm --env-file .env findings-processor | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| steps: | ||
| - name: "golang:1.25" | ||
| id: ci-checks | ||
| dir: scanners/findings-processor | ||
| entrypoint: "bash" | ||
| args: | ||
| - "-c" | ||
| - | | ||
| make ci | ||
|
|
||
| - name: "golang:1.25" | ||
| id: integration-tests | ||
| dir: scanners/findings-processor | ||
| entrypoint: "bash" | ||
| args: | ||
| - "-c" | ||
| - | | ||
| make test-integration | ||
|
|
||
| - name: "gcr.io/cloud-builders/docker" | ||
| id: generate-image-name | ||
| entrypoint: "bash" | ||
| dir: scanners/findings-processor | ||
| args: | ||
| - "-c" | ||
| - | | ||
| echo "northamerica-northeast1-docker.pkg.dev/track-compliance/tracker/findings-processor:$(echo $BRANCH_NAME | sed 's/[^a-zA-Z0-9]/-/g')-$SHORT_SHA-$(date +%s)" > /workspace/imagename | ||
|
|
||
| - name: "gcr.io/cloud-builders/docker" | ||
| id: build | ||
| entrypoint: "bash" | ||
| dir: scanners/findings-processor | ||
| args: | ||
| - "-c" | ||
| - | | ||
| image=$(cat /workspace/imagename) | ||
| docker build -t $image . | ||
|
|
||
| - name: "gcr.io/cloud-builders/docker" | ||
| id: push-if-master | ||
| entrypoint: "bash" | ||
| dir: scanners/findings-processor | ||
| args: | ||
| - "-c" | ||
| - | | ||
| if [[ "$BRANCH_NAME" == "master" ]] | ||
| then | ||
| image=$(cat /workspace/imagename) | ||
| docker push $image | ||
| else | ||
| exit 0 | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "github.com/canada-ca/tracker/scanners/findings-processor/internal/config" | ||
| "github.com/canada-ca/tracker/scanners/findings-processor/internal/runner" | ||
| "github.com/rs/zerolog/log" | ||
| ) | ||
|
|
||
| func main() { | ||
| cfg, err := config.Load() | ||
| if err != nil { | ||
| log.Fatal().Err(err).Msg("failed to load config") | ||
| } | ||
| config.SetupLogger(cfg) | ||
|
|
||
| if err := runner.Run(cfg); err != nil { | ||
| log.Fatal().Err(err).Msg("findings processor failed") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| module github.com/canada-ca/tracker/scanners/findings-processor | ||
|
|
||
| go 1.25.0 | ||
|
|
||
| require ( | ||
| github.com/joho/godotenv v1.5.1 | ||
| github.com/kelseyhightower/envconfig v1.4.0 | ||
| github.com/nats-io/nats.go v1.52.0 | ||
| github.com/rs/zerolog v1.34.0 | ||
| github.com/testcontainers/testcontainers-go v0.44.0 | ||
| github.com/testcontainers/testcontainers-go/modules/nats v0.44.0 | ||
| ) | ||
|
|
||
| require ( | ||
| dario.cat/mergo v1.0.2 // indirect | ||
| github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect | ||
| github.com/Microsoft/go-winio v0.6.2 // indirect | ||
| github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e // indirect | ||
| github.com/cenkalti/backoff/v4 v4.3.0 // indirect | ||
| github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||
| github.com/containerd/errdefs v1.0.0 // indirect | ||
| github.com/containerd/errdefs/pkg v0.3.0 // indirect | ||
| github.com/containerd/log v0.1.0 // indirect | ||
| github.com/containerd/platforms v0.2.1 // indirect | ||
| github.com/cpuguy83/dockercfg v0.3.2 // indirect | ||
| github.com/davecgh/go-spew v1.1.1 // indirect | ||
| github.com/dchest/siphash v1.2.3 // indirect | ||
| github.com/distribution/reference v0.6.0 // indirect | ||
| github.com/docker/go-connections v0.7.0 // indirect | ||
| github.com/docker/go-units v0.5.0 // indirect | ||
| github.com/ebitengine/purego v0.10.1 // indirect | ||
| github.com/felixge/httpsnoop v1.1.0 // indirect | ||
| github.com/go-logr/logr v1.4.3 // indirect | ||
| github.com/go-logr/stdr v1.2.2 // indirect | ||
| github.com/go-ole/go-ole v1.3.0 // indirect | ||
| github.com/google/uuid v1.6.0 // indirect | ||
| github.com/kkdai/maglev v0.2.0 // indirect | ||
| github.com/lufia/plan9stats v0.0.0-20260330125221-c963978e514e // indirect | ||
| github.com/magiconair/properties v1.8.10 // indirect | ||
| github.com/mattn/go-colorable v0.1.13 // indirect | ||
| github.com/mattn/go-isatty v0.0.20 // indirect | ||
| github.com/moby/docker-image-spec v1.3.1 // indirect | ||
| github.com/moby/go-archive v0.2.0 // indirect | ||
| github.com/moby/moby/api v1.55.0 // indirect | ||
| github.com/moby/moby/client v0.5.0 // indirect | ||
| github.com/moby/patternmatcher v0.6.1 // indirect | ||
| github.com/moby/sys/sequential v0.7.0 // indirect | ||
| github.com/moby/sys/user v0.4.0 // indirect | ||
| github.com/moby/sys/userns v0.1.0 // indirect | ||
| github.com/moby/term v0.5.2 // indirect | ||
| github.com/opencontainers/go-digest v1.0.0 // indirect | ||
| github.com/opencontainers/image-spec v1.1.1 // indirect | ||
| github.com/pkg/errors v0.9.1 // indirect | ||
| github.com/pmezard/go-difflib v1.0.0 // indirect | ||
| github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect | ||
| github.com/shirou/gopsutil/v4 v4.26.6 // indirect | ||
| github.com/sirupsen/logrus v1.9.4 // indirect | ||
| github.com/stretchr/testify v1.11.1 // indirect | ||
| github.com/tklauser/go-sysconf v0.4.0 // indirect | ||
| github.com/tklauser/numcpus v0.12.0 // indirect | ||
| github.com/yusufpapurcu/wmi v1.2.4 // indirect | ||
| go.opentelemetry.io/auto/sdk v1.2.1 // indirect | ||
| go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.69.0 // indirect | ||
| go.opentelemetry.io/otel v1.44.0 // indirect | ||
| go.opentelemetry.io/otel/metric v1.44.0 // indirect | ||
| go.opentelemetry.io/otel/trace v1.44.0 // indirect | ||
| golang.org/x/net v0.56.0 // indirect | ||
| golang.org/x/text v0.40.0 // indirect | ||
| gopkg.in/yaml.v3 v3.0.1 // indirect | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/arangodb/go-driver/v2 v2.3.1 | ||
| github.com/klauspost/compress v1.18.6 // indirect | ||
| github.com/nats-io/nkeys v0.4.15 // indirect | ||
| github.com/nats-io/nuid v1.0.1 // indirect | ||
| golang.org/x/crypto v0.54.0 // indirect | ||
| golang.org/x/sys v0.47.0 // indirect | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.