-
-
Notifications
You must be signed in to change notification settings - Fork 220
feat: supascan audit feature #1963
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
+199,162
−7
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b96d85f
feat: audit feature
samrose b56234b
feat: shallow dirs
samrose 320b294
feat: include dirs
samrose 356f12c
fix: deal with various dirs
samrose e1e63a6
fix: excludes
samrose 41ab10e
feat: baseline test
samrose 83050ad
tests: upload baseline
samrose 7e8e56a
fix: move audit to end of image build
samrose cae06fe
feat: supascan
samrose f876fba
fix: cleanup
samrose a0b1f57
fix: upload
samrose fe287cc
fix: consolidate installation etc
samrose 54d89a1
fix: install
samrose ca6f8bb
fix: sudo for validate
samrose dec5bbd
fix: ubuntu user path
samrose a67ec29
feat: organize into ami build and deployed
samrose 95c94e7
fix: rename
samrose c2f5f66
fix: package not present at ami build
samrose ac812e9
fix: include users, groups perms
samrose f54487f
fix: align perms with build stage
samrose f6c5b31
fix: restore sh files undo formatting
samrose f8ccc0a
chore: restore version in package
samrose 93b364b
fix: update conf.d
samrose 6265138
chore: rename task
samrose d87f82b
fix: rm post-deploy dris
samrose 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,37 @@ | ||
| #!/bin/bash | ||
| # Baseline Validation Check | ||
| # | ||
| # This script validates that the machine matches the committed baseline | ||
| # specifications using supascan (pre-installed via nix profile for ubuntu user). | ||
| # | ||
| # Usage: supascan_ami.sh [baselines-dir] | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| BASELINES_DIR="${1:-/tmp/ansible-playbook/audit-specs/baselines/ami-build}" | ||
|
|
||
| echo "============================================================" | ||
| echo "Baseline Validation" | ||
| echo "============================================================" | ||
| echo "" | ||
| echo "Baselines directory: $BASELINES_DIR" | ||
| echo "" | ||
|
|
||
| # Check baselines directory exists | ||
| if [[ ! -d $BASELINES_DIR ]]; then | ||
| echo "ERROR: Baselines directory not found: $BASELINES_DIR" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Add ubuntu user's nix profile to PATH | ||
| export PATH="/home/ubuntu/.nix-profile/bin:$PATH" | ||
|
|
||
| # Verify supascan is available | ||
| if ! command -v supascan &>/dev/null; then | ||
| echo "ERROR: supascan not found in PATH" | ||
| echo "PATH: $PATH" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Run supascan validate (it calls sudo goss internally for privileged checks) | ||
| exec supascan validate --verbose "$BASELINES_DIR" | ||
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
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
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,33 @@ | ||
| # Machine Baselines | ||
|
|
||
| This directory contains captured baselines from real machines. | ||
|
|
||
| ## Generating a Baseline | ||
|
|
||
| On your target machine: | ||
| ```bash | ||
| sudo nix run github:supabase/ubuntu-cis-audit#cis-generate-spec -- baseline.yaml | ||
| ``` | ||
|
|
||
| ## Naming Convention | ||
|
|
||
| Use descriptive names that identify the machine type or environment: | ||
| - `production-db-baseline.yaml` - Production database server | ||
| - `staging-api-baseline.yaml` - Staging API server | ||
| - `postgres-baseline.yaml` - Standard PostgreSQL server config | ||
|
|
||
| ## Using Baselines | ||
|
|
||
| Copy your baseline to this directory and commit to git. Then use GOSS to audit other machines: | ||
|
|
||
| ```bash | ||
| # On target machine | ||
| goss --gossfile audit-specs/baselines/production-db-baseline.yaml validate | ||
| ``` | ||
|
|
||
| ## Baseline Sources | ||
|
|
||
| Document where each baseline came from: | ||
|
|
||
| - `postgres-baseline.yaml` - Generated from db-pdnxwzxvlrfwogpyaltm on 2025-11-22 | ||
| - `production-baseline.yaml` - Generated from prod-server-001 on 2025-11-20 |
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,97 @@ | ||
| # File baseline: postgres-config | ||
| # PostgreSQL configuration files for AMI build | ||
| # Uses string names for owner/group (not numeric IDs) | ||
| file: | ||
| # Main PostgreSQL config directory | ||
| /etc/postgresql: | ||
| exists: true | ||
| filetype: directory | ||
| owner: postgres | ||
| group: postgres | ||
| mode: '0775' | ||
| /etc/postgresql/postgresql.conf: | ||
| exists: true | ||
| filetype: file | ||
| owner: root | ||
| group: root | ||
| mode: '0644' | ||
| /etc/postgresql/pg_hba.conf: | ||
| exists: true | ||
| filetype: file | ||
| owner: root | ||
| group: postgres | ||
| mode: '0664' | ||
| /etc/postgresql/pg_ident.conf: | ||
| exists: true | ||
| filetype: file | ||
| owner: root | ||
| group: postgres | ||
| mode: '0644' | ||
| /etc/postgresql/logging.conf: | ||
| exists: true | ||
| filetype: file | ||
| owner: root | ||
| group: postgres | ||
| mode: '0644' | ||
|
|
||
| # Custom PostgreSQL config directory | ||
| /etc/postgresql-custom: | ||
| exists: true | ||
| filetype: directory | ||
| owner: postgres | ||
| group: postgres | ||
| mode: '0775' | ||
| # Note: platform-defaults.conf, pgsodium_root.key, custom-overrides.conf, and | ||
| # generated-optimizations.conf are created at deploy time (not during AMI build) | ||
| /etc/postgresql-custom/supautils.conf: | ||
| exists: true | ||
| filetype: file | ||
| owner: postgres | ||
| group: postgres | ||
| mode: '0664' | ||
| /etc/postgresql-custom/conf.d: | ||
| exists: true | ||
| filetype: directory | ||
| owner: postgres | ||
| group: postgres | ||
| mode: '0775' | ||
| /etc/postgresql-custom/conf.d/wal-g.conf: | ||
| exists: true | ||
| filetype: file | ||
| owner: postgres | ||
| group: postgres | ||
| mode: '0664' | ||
| /etc/postgresql-custom/conf.d/read_replica.conf: | ||
| exists: true | ||
| filetype: file | ||
| owner: postgres | ||
| group: postgres | ||
| mode: '0664' | ||
|
|
||
| # Extension custom scripts directory | ||
| /etc/postgresql-custom/extension-custom-scripts: | ||
| exists: true | ||
| filetype: directory | ||
| owner: postgres | ||
| group: postgres | ||
| mode: '0775' | ||
| /etc/postgresql-custom/extension-custom-scripts/before-create.sql: | ||
| exists: true | ||
| filetype: file | ||
| owner: postgres | ||
| group: postgres | ||
| mode: '0775' | ||
|
|
||
| # PostgREST config directory | ||
| /etc/postgrest: | ||
| exists: true | ||
| filetype: directory | ||
| owner: postgrest | ||
| group: postgrest | ||
| mode: '0775' | ||
| /etc/postgrest/base.conf: | ||
| exists: true | ||
| filetype: file | ||
| owner: postgrest | ||
| group: postgrest | ||
| mode: '0644' |
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 @@ | ||
| # File baseline: postgres-data | ||
| # PostgreSQL data directory for AMI build | ||
| # Uses string names for owner/group (not numeric IDs) | ||
| file: | ||
| # PostgreSQL data directory | ||
| /var/lib/postgresql: | ||
| exists: true | ||
| filetype: directory | ||
| owner: postgres | ||
| group: postgres | ||
| mode: '0755' | ||
| # Note: /var/lib/postgresql/data is a symlink during AMI build (points to /data/...) | ||
| # The actual data directory is created at deploy time | ||
| /var/lib/postgresql/data: | ||
| exists: true | ||
| filetype: symlink | ||
| owner: root | ||
| group: root | ||
| mode: '0777' |
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,77 @@ | ||
| # File baseline: security | ||
| # Critical security-related files for AMI build | ||
| # Uses string names for owner/group (not numeric IDs) | ||
| file: | ||
| # fail2ban configuration directory | ||
| /etc/fail2ban: | ||
| exists: true | ||
| filetype: directory | ||
| owner: root | ||
| group: root | ||
| mode: '0755' | ||
| /etc/fail2ban/jail.local: | ||
| exists: true | ||
| filetype: file | ||
| owner: root | ||
| group: root | ||
| mode: '0644' | ||
|
|
||
| # AppArmor | ||
| /etc/apparmor.d: | ||
| exists: true | ||
| filetype: directory | ||
| owner: root | ||
| group: root | ||
| mode: '0755' | ||
|
|
||
| # UFW firewall | ||
| /etc/ufw: | ||
| exists: true | ||
| filetype: directory | ||
| owner: root | ||
| group: root | ||
| mode: '0755' | ||
| /etc/ufw/ufw.conf: | ||
| exists: true | ||
| filetype: file | ||
| owner: root | ||
| group: root | ||
| mode: '0644' | ||
|
|
||
| # SSH configuration | ||
| /etc/ssh/sshd_config: | ||
| exists: true | ||
| filetype: file | ||
| owner: root | ||
| group: root | ||
| mode: '0644' | ||
|
|
||
| # PAM configuration | ||
| /etc/pam.d: | ||
| exists: true | ||
| filetype: directory | ||
| owner: root | ||
| group: root | ||
| mode: '0755' | ||
|
|
||
| # Sudoers | ||
| /etc/sudoers: | ||
| exists: true | ||
| filetype: file | ||
| owner: root | ||
| group: root | ||
| mode: '0440' | ||
| /etc/sudoers.d: | ||
| exists: true | ||
| filetype: directory | ||
| owner: root | ||
| group: root | ||
| mode: '0750' | ||
|
|
||
| # Security limits | ||
| /etc/security/limits.conf: | ||
| exists: true | ||
| filetype: file | ||
| owner: root | ||
| group: root | ||
| mode: '0644' |
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,30 @@ | ||
| # File baseline: ssl | ||
| # SSL certificate and key directories for AMI build | ||
| # Uses string names for owner/group (not numeric IDs) | ||
| file: | ||
| # System SSL directory | ||
| /etc/ssl: | ||
| exists: true | ||
| filetype: directory | ||
| owner: root | ||
| group: root | ||
| mode: '0755' | ||
| /etc/ssl/certs: | ||
| exists: true | ||
| filetype: directory | ||
| owner: root | ||
| group: root | ||
| mode: '0755' | ||
| /etc/ssl/private: | ||
| exists: true | ||
| filetype: directory | ||
| owner: root | ||
| group: postgres | ||
| mode: '0750' | ||
| /etc/ssl/openssl.cnf: | ||
| exists: true | ||
| filetype: file | ||
| owner: root | ||
| group: root | ||
| mode: '0644' | ||
| # Note: /etc/ssl/adminapi is created at deploy time, not during AMI build |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can we use
/usr/bin/env bashhere?