-
-
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
Open
samrose
wants to merge
24
commits into
develop
Choose a base branch
from
image-audit
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+199,173
−7
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
cdf1684
feat: audit feature
samrose fe4c7ae
feat: shallow dirs
samrose 6972602
feat: include dirs
samrose a65149c
fix: deal with various dirs
samrose b119054
fix: excludes
samrose 58fb784
feat: baseline test
samrose 4a36d4f
tests: upload baseline
samrose 71de57f
fix: move audit to end of image build
samrose 26bdd9f
feat: supascan
samrose ce3c706
fix: cleanup
samrose cae38c4
fix: upload
samrose c31da66
fix: consolidate installation etc
samrose f843d8e
fix: install
samrose 272b3c8
fix: sudo for validate
samrose c43a005
fix: ubuntu user path
samrose da38ee3
feat: organize into ami build and deployed
samrose 2e66734
fix: rename
samrose aa7dd82
fix: package not present at ami build
samrose 248cedd
fix: include users, groups perms
samrose 67c2eab
fix: align perms with build stage
samrose 484b4d8
fix: restore sh files undo formatting
samrose 3aca36a
chore: restore version in package
samrose 1229684
fix: update conf.d
samrose 5a3efcb
chore: rename task
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 |
108 changes: 108 additions & 0 deletions
108
audit-specs/baselines/ami-build/files-postgres-config.yml
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,108 @@ | ||
| # 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 and pgsodium_root.key are created at deploy time | ||
| /etc/postgresql-custom/custom-overrides.conf: | ||
| exists: true | ||
| filetype: file | ||
| owner: postgres | ||
| group: postgres | ||
| mode: '0664' | ||
| /etc/postgresql-custom/generated-optimizations.conf: | ||
| exists: true | ||
| filetype: file | ||
| owner: postgres | ||
| group: postgres | ||
| mode: '0664' | ||
| /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?