Skip to content

feat(aws): automatic rescans per connector (off by default) - #94

Merged
akashmaurya3160 merged 2 commits into
authsec-stagingfrom
feat/aws-scheduled-scans
Oct 20, 2026
Merged

akashmaurya3160 merged 2 commits into
authsec-stagingfrom
feat/aws-scheduled-scans

Conversation

@akashmaurya3160

@akashmaurya3160 akashmaurya3160 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

A connected AWS account can rescan itself daily or weekly. A scheduler loop in the backend queues the same scan "Scan now" queues (trigger = 'scheduled'); the existing scan worker runs it. No new AWS access, nothing installed in the customer's account.

How

  • New table cloud_scan_schedule (migration 139 + 001_bootstrap.sql, identical blocks), RLS-enabled.
  • Scheduler: FOR UPDATE SKIP LOCKED claim (safe on many replicas), advance-then-enqueue, per-connector jitter, auto-pause after 3 failed scheduled scans, resume via PUT.
  • GET/PUT /discovery/aws/connectors/:id/schedule. Revoking a connector disables its schedule.
  • Ships dark: nothing runs unless AUTHSEC_AWS_SCHEDULED_SCANS=true. The endpoints still read and write, and report scheduler_active: false.
  • A scan already running at the due time retries in 1h, not a full interval (a week on weekly).
  • PUT reads and writes under a row lock, so it cannot overwrite a slot the scheduler just claimed.

Spec: .claude/specs/SPEC-aws-scheduled-scans.md (updated to match the code).

Tested

  • go build ./..., go vet, unit tests pass.
  • Real Postgres (tests/awsschedule, needs TEST_DATABASE_URL): 6/6 pass. Covers the full schedule life, 4 replicas queueing one scan, pause/resume, off and revoked, interval limits, and the busy-connector retry.
  • check-tenant-exempt.sh: unchanged (72 / baseline 72).
  • Not run: schema-parity.sh (needs a built binary and psql). The bootstrap block was diffed against migration 139 and is identical.

Not proven (before turning it on)
Scan duration on a large account against the 1-hour role session, behaviour with many connectors due at once, AWS throttling at daily cadence, and customer CloudTrail volume. Rollout per the spec: one internal workspace at daily for a week first.
Notes

  • Migration 139 was the next free number against staging at d442ce3. Re-check if another migration lands first.
  • UI is a separate PR in Authsec-ui and needs this one.

A connector can rescan itself daily or weekly. A scheduler loop in the backend
queues the same scan "Scan now" queues (trigger "scheduled"); the existing scan
worker runs it. No new AWS access.

- cloud_scan_schedule table (migration 139 + bootstrap), RLS-enabled
- scheduler: SKIP LOCKED claim (safe on many replicas), advance-then-enqueue,
  per-connector jitter, pause after 3 failed scheduled scans, resume via PUT
- a scan already running at the due time retries in 1h, not a full interval
- PUT locks the schedule row so it cannot overwrite a slot the scheduler claimed
- GET/PUT /discovery/aws/connectors/:id/schedule; revoke disables the schedule
- gated by AUTHSEC_AWS_SCHEDULED_SCANS (default off)

Tested against real Postgres (tests/awsschedule): replicas, pause/resume,
revoked, interval limits, busy-connector retry.
An administrator can now pick when a schedule runs: a time of day on a quarter
hour, a timezone, and for weekly a weekday. Omitted, behaviour is unchanged
(one interval after the schedule was turned on).

- migration 140 (+ bootstrap): time_of_day_minutes, timezone, day_of_week,
  all optional, with CHECK constraints; existing rows are untouched
- internal/scanslot: pure next-slot logic. One slot per local day, correct
  across daylight-saving changes (a time that does not exist runs at the end of
  the gap, a repeated one runs once). Standalone tests across eight zones.
- scheduler keeps the chosen time after each run; the connector jitter is added
  after it, so a scan starts within 30 minutes after the chosen time
- PUT .../schedule accepts time_of_day, timezone, day_of_week; 422 names the
  bad parameter; weekly with a time requires day_of_week
- changing only the time moves the next scan without resetting the failure streak
- Put keeps its signature (PutWithTiming is the new entry point)
- DB tests added (tests/awsschedule/schedule_time_db_test.go)
@akashmaurya3160
akashmaurya3160 force-pushed the feat/aws-scheduled-scans branch from 623946e to 18cac46 Compare October 20, 2026 03:04
@akashmaurya3160
akashmaurya3160 merged commit 3980193 into authsec-staging Oct 20, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant