feat(safegres): configurable rules, presets, config-driven scoring, doctor + print-config - #1495
Merged
Conversation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Makes safegres configurable like a linter (design: constructive-io/constructive-planning#1282), on top of the new
confstashloader (constructive-io/dev-utils#97).Depends on publishing
confstashto npm —packages/safegresnow depends onconfstash@^0.0.1, sopnpm install(and CI) will fail until constructive-io/dev-utils#97 is merged and published. Tested locally against a packed confstash tarball; the lockfile is intentionally untouched and should be regenerated after publish.src/rules/registry.ts): metadata for A1–A7, P1, P1b, P5 (defaultSeverity,category,scope: 'table' | 'policy-ast') with prefix-wildcard selectors ('P*').src/config/*):SafegresConfig—extends,rules: { CODE: 'off' | severity | [severity, options] }, per-tableoverrides: [{ tables: ['public.audit_*'], rules }](glob onschema.table),scoring,failOn. Discovered via confstash (safegres.config.{ts,js,mjs,cjs},.safegresrc*,safegres.json, package.json"safegres"). Exact codes beat wildcards; unknown codes/severities throwConfigValidationError.safegres:recommended(today's behavior),strict,multi-tenant,minimal— just partial configs, chainable viaextends.src/score/score.ts): weighted deductions (critical 25 / high 10 / medium 4 / low 1 / info 0), per-rule cap (40), grade bands A+→F, criticals floor the grade at C — all tunable viascoring.Report.score = { value, grade, deductions }; rendered in pretty output.audit(): takesconfig?: SafegresConfig; findings are filtered/restamped by resolved rules (respecting per-table overrides), AST work is skipped when everypolicy-astrule is off, andschemas/rolesfall back to config values.safegres doctor(config discovery + rule validation, pgsql-parser availability, connection, pg_policy access, BYPASSRLS blind spots, any-RLS-tables check; exit 1 on FAIL),safegres print-config [--explain], plus--config/--preset/--rule CODE=setting/--fail-on-score/--fail-on-gradeonaudit.Behavior without a config file is unchanged (all rules at default severities), except reports now include a score.
Tests: 37 passing (21 new in
__tests__/config.test.ts); CLI smoke-tested (doctor,print-config --preset minimal,audit) against postgres-plus:18.Link to Devin session: https://app.devin.ai/sessions/671aac6e50b04e8caacd3f54c1c63bc6
Requested by: @pyramation