diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5f02750..6a45dfb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -70,3 +70,36 @@ jobs: env: PDBCORE_TEST_DATABASE_URL: postgres://pdbcore:pdbcore@localhost:5434/pdbcore_test run: go test -race -count=1 ./testutil/ ./pgexec/ ./watch/ ./introspect/ ./postgis/ ./contrib/ ./metrics/ + + downstream: + name: downstream (${{ matrix.repo }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + repo: [pdbq, pdbr] + steps: + - uses: actions/checkout@v4 + with: + path: pdbcore + - uses: actions/checkout@v4 + with: + repository: suprbdev/${{ matrix.repo }} + path: ${{ matrix.repo }} + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache-dependency-path: | + pdbcore/go.sum + ${{ matrix.repo }}/go.sum + - name: Point ${{ matrix.repo }} at this checkout of pdbcore + working-directory: ${{ matrix.repo }} + run: | + go mod edit -replace github.com/suprbdev/pdbcore=../pdbcore + go mod tidy + - name: Vet + working-directory: ${{ matrix.repo }} + run: go vet ./... + - name: Unit and golden tests (race) + working-directory: ${{ matrix.repo }} + run: go test -race ./... diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c55ef82..09ab3ce 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -6,6 +6,8 @@ on: permissions: contents: write + id-token: write + attestations: write env: GO_VERSION: "1.26" @@ -20,6 +22,18 @@ jobs: go-version: ${{ env.GO_VERSION }} - name: Tests (race) run: go test -race ./... + - name: SBOM (CycloneDX) + env: + VERSION: ${{ github.ref_name }} + run: | + go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v1.9.0 + mkdir -p dist + cyclonedx-gomod mod -json -licenses -output "dist/pdbcore_${VERSION#v}_sbom.cdx.json" . + - name: Attest build provenance + if: ${{ !env.ACT }} + uses: actions/attest-build-provenance@v2 + with: + subject-path: dist/*.cdx.json - name: Create GitHub release # Skipped under act (local workflow testing); act sets ACT=true. # Library module: notes only, no binaries. @@ -29,4 +43,5 @@ jobs: run: | gh release create "$GITHUB_REF_NAME" \ --title "$GITHUB_REF_NAME" \ - --generate-notes + --generate-notes \ + dist/* diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2d726f1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,260 @@ +# Changelog + +All notable changes to this project are documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) +as described in [docs/compatibility.md](docs/compatibility.md). + +Entries up to and including the latest 0.x release below were seeded from the +GitHub release notes; the Unreleased section is maintained by hand and +becomes the release notes of the next tag. + +## [Unreleased] + +### Added + +- SECURITY.md, CONTRIBUTING.md, CHANGELOG.md and a versioning, deprecation and + supported-versions policy ([docs/compatibility.md](docs/compatibility.md)). +- Release artifacts are accompanied by a CycloneDX SBOM, a keyless cosign + signature of the checksums and GitHub build provenance attestations. +- Compatibility policy: pdbcore stays v0.x and is the engine for pdbq and + pdbr, with no external compatibility promise. +- A CI job builds and tests pdbq and pdbr at their `main` against the pull + request. + +## [0.18.0] - 2026-11-23 + +### Breaking: identity and strict config + +- `confx`: `rls` is replaced by `auth` / `roles` / `claims`; `ValidateIdentity`, `AuthConfig(Auth, Roles)`; `DefaultClaimsPrefix` = `jwt.claims`; optional `claims.json_setting`. +- `auth`: `New` returns `(*Authenticator, error)` and rejects unknown modes, jwt without a key source and headers mode without trusted proxies; typed `auth.Mode`; empty `AnonymousRole` → `ErrAuthRequired` (`auth.Challenge` for `WWW-Authenticate`); `SkipRoleSwitch` replaces `Enabled`; leeway and role claim paths. +- Strict `confx.Load`: unknown keys (file and prefixed env) are errors with moved-to / did-you-mean hints; generic typed `Plugins[S]` settings. +- `httpx`: `CORSPolicy{Origins, AllowMethods, ExposeHeaders}`; CORS appends to `Vary`. +- `pgexec`: SQLSTATE class 21 is user input; per-claim settings only with a non-empty prefix. + +### Changes +* feat(auth)!: split auth, roles and claims config; strict config (#83) + +## [0.17.0] - 2026-11-23 + +### Breaking: catalog format 10 + +- `GeneratedIdentity` is split into `GeneratedIdentityAlways` / `GeneratedIdentityByDefault`; `Column.Generated` is replaced by `GeneratedAlways()`, `OmittableOnInsert()` and `Identity()`. +- `Catalog.Hash()` no longer mutates the catalog and ignores the PostgreSQL minor version. +- Functions are ordered by schema, name and argument types, so overload keep-first is stable. +- `introspect/testdata/catalog_format.golden` fails the build if the JSON shape changes without a `CatalogFormatVersion` bump. +- Cache envelopes record their writer (`cache.Writer`); typed errors `*cache.FormatVersionError` and `cache.ErrCorrupt`. +- PostgreSQL < 14 is refused (`*introspect.UnsupportedServerError`, and in `pgexec.Connect`). + +### Changes +* feat(introspect)!: catalog format 10 (identity kind, deterministic overloads, pure Hash) (#82) + +## [0.16.0] - 2026-11-23 + +### Highlights + +- **Extension-owned relations are skipped** (PostGIS `geometry_columns`, `geography_columns`, `raster_columns`, `raster_overviews`, `spatial_ref_sys`, …), like extension-owned functions. +- **Constraint columns**: `Index.ExpressionColumns` (columns used by key expressions and partial-index predicates), `Table.Checks`, and `Table.ConstraintReferences` / `ConstraintColumns` for integrity-error sanitizers. +- **Index operator classes**: `Index.OpClasses` / `OpClass(i)`, `contrib.IndexHint.Serves(method, opClass)`. +- **`NOT NULL … NOT VALID`** (PostgreSQL 18+): `Column.NotNull` requires a validated constraint; `ForeignKey.NotValid` / `MayDangle()`. +- **Headline bound**: `contrib.HeadlineDocumentSQL`, `MaxHeadlineDocument`, `HeadlineDocumentCost`. +- `CatalogFormatVersion` 9. + +### Changes +* fix(introspect): skip extension-owned relations; record expression and predicate columns (#75) +* feat(introspect): NOT VALID constraints and index operator classes (#74) + +## [0.15.0] - 2026-11-23 + +### Highlights + +- **cube**: `contains` / `containedBy` / `overlaps`, `l2` / `l1` / `chebyshev` distances (ordering, scores) and GiST-served `DistanceLessThan` thresholds; JSON point/box codec. +- **earthdistance**: earth columns as `{lat, lon}`, `earthDistance` score in metres, `Expr.OrderSQL` (cube `<->` chord distance for KNN ordering and keyset cursors), `earthDistanceLessThan` with an `earth_box` prefilter; point `<@>` miles surface. +- **Raster**: `IsRaster`, header accessors (width, height, bands, SRID, pixel size, envelope), `RasterValueSQL` (`ST_Value` at a bound point and band), `RasterSummaryStatsSQL`, `RasterIntersectsSQL`; cost weights. "Raster and geometry do not have the same SRID" is classified as user input. + +### Changes +* feat(contrib): cube and earthdistance; feat(postgis): raster columns (#70) + +## [0.14.0] - 2026-11-23 + +### Highlights + +- **GeoJSON precision**: `OutputPrecisionSQL` / `OutputJSONPrecisionSQL` render `ST_AsGeoJSON(ref, $n::int4)` with the digits bound (`CheckPrecision`: 0–15). +- **Buffer**: `BufferSQL` (`ST_Buffer(ref, $n::float8)`; metres on geography), `CheckBuffer`. +- **jsonb full-text search**: `jsonsearch` vocabulary gives json/jsonb columns the `matches*` operators and rank over `to_tsvector([config,] col)`. +- **Headlines**: `Op.HeadlineSQL` renders `ts_headline` with the match's own tsquery; `ParseHeadlineOptions` validates and bounds options, rendered as one bound parameter. Shared cost weights `HeadlineCost` (10) and `BufferCost` (5). + +### Changes +* feat(postgis): GeoJSON precision; feat(contrib): jsonb full-text search and headlines (#69) + +## [0.13.1] - 2026-11-23 + +### Security + +- **Polymorphic resolution and hidden types.** `@anyelement` / `@anycompatible` tags could resolve to the row type of a contract-hidden or fully omitted table, keeping such functions inside a contract. Hidden relations are now recorded on the catalog (`Catalog.HideRelation` / `RelationHidden`, kept by `Clone`) and resolution refuses them; it also only resolves to built-in types or types the introspected catalog knows (non-introspected schemas are refused). No consumer changes needed. + +### Changes +* fix(contract): polymorphic resolution never resolves to a hidden table type (#68) + +## [0.13.0] - 2026-11-23 + +### Highlights + +- **hstore**: `value` expression (`col -> key`, key bound) and `hasDefinedKey`. +- **ltree**: `parent`, `lca` (with a path; also on `ltree[]`) and `subpath` (`{offset, length?}`) accessors alongside `nlevel`. +- **fuzzystrmatch**: Levenshtein distance score, ordering and `levenshteinDistanceLessThan` threshold (computed with `levenshtein_less_equal`); `soundexEqualTo`, `metaphoneEqualTo`, `doubleMetaphoneEqualTo`. +- **intarray**: `matchesQueryInt` (`@@ query_int`, GIN/GiST index hints) and `icount`. +- New `Expr.Derived` flag, operand kinds `ArgTextDistance` / `ArgSubpath`, and an `Integer` coercion helper. + +### Changes +* feat(contrib): hstore and ltree accessors, fuzzystrmatch, intarray (#66) + +## [0.12.0] - 2026-11-23 + +### Changes +* feat(contrib): score expressions, pgvector threshold filters and bit distances (#65) + +## [0.11.0] - 2026-11-23 + +### Highlights + +- **pgvector** (`contrib.Vector`): `vector`, `halfvec`, `sparsevec`; distance expressions (`l2Distance`, `negativeInnerProduct`, `cosineDistance`, `l1Distance` on pgvector 0.7+), HNSW/IVFFlat index hints, `dims` / `norm` accessors, JSON-array codec. +- **unaccent** (`contrib.Unaccent`): `unaccentEqualTo`, `unaccentLike`, `unaccentIncludes`, `unaccentStartsWith` (two-argument `unaccent(regdictionary, …)`, safe when the extension schema is off the search_path). +- **PostGIS**: `bboxIntersects2D` (`&&` against a geometry); on geography columns `Perimeter` is now in metres and `Centroid` is spheroidal. + +### Changes +* feat: pgvector and unaccent vocabularies, bboxIntersects2D, geography measures (#62) + +## [0.10.0] - 2026-11-23 + +### Highlights + +- **Polymorphic signatures**: `introspect` helpers parse SQL type spellings and rewrite polymorphic functions to concrete types; the smart-comments catalog hook applies `@anyelement ` / `@anycompatible `. Fixture gains row-argument, row-array and polymorphic functions. +- **Watcher**: after installing its event trigger, `Run` waits (bounded by `Watcher.InstallWait`, default 30s) for transactions open at install time to end before the startup re-check, so DDL committed by them is no longer missed; `Ready` closes after that re-check. + +### Changes +* fix(watch): wait for transactions open at trigger install before the startup re-check (#64) +* feat(functions): resolve polymorphic signatures; fixture functions with row and polymorphic args (#61) + +## [0.9.0] - 2026-11-23 + +### Highlights + +- **`pgexec.Savepoint`**: run a function inside a SAVEPOINT in a `RunTx` callback; a failure rolls back to the savepoint and returns `*RolledBackError` so the transaction continues. Serialization failures, deadlocks, `ErrRollback` and cancelled contexts still abort the transaction (and retry). + +### Changes +* feat(pgexec): Savepoint helper for partial transaction recovery (#46) + +## [0.8.1] - 2026-11-23 + +### Changes +* fix(pgexec): don't count a requested rollback as a database error (#44) + +## [0.8.0] - 2026-11-23 + +### Highlights + +- **Schema contracts**: named views of one catalog (e.g. `public`, `partner`, `internal`) that pdbq and pdbr each serve as a separate API. Membership comes from smart comments: `@contract a, b` and `@behavior +contract:x` / `-contract:x`, with a per-contract default policy (`include` / `exclude`). A contract only removes surface: hidden tables (with their partitions, foreign keys and row-typed functions), functions and foreign keys are dropped; hidden columns get a bare `@omit` so each product hides them everywhere. +- `introspect.Catalog.Clone()` (deep copy), `confx.Contract` config with validation, and per-contract metrics on a shared registry (`metrics.NewRegistry`, `RegisterPoolOn`). + +### Changes +* feat(contracts): schema contract tags and catalog views (#42) + +## [0.7.1] - 2026-11-23 + +### Changes +* fix(watch): catch DDL committed during startup; add Ready signal (#41) + +## [0.7.0] - 2026-11-23 + +### Security + +- **Claim spoofing in headers auth mode (fixed).** Claim headers such as `X-…-Claim-User-Id` and `X-…-Claim-User_id` (or case/separator variants) used to map to the same claim, and which value won was random per request, so a client behind a gateway could override a claim the gateway set. Each claim now has exactly one header spelling (`X--Claim-`); malformed, repeated or colliding claim headers are rejected with 401. New optional allowlist `rls.auth.header_claims`. Gateways must strip every client-supplied header with the claim prefix, in any letter case. +- **JWKS hardening.** Key fetches no longer serialize requests behind a global lock (forged tokens could stall every authenticated request for 10 s at a time); fetches are shared, run in the background with backoff on failure, stale keys keep verifying for one extra TTL during an IdP outage, and client errors no longer reveal the JWKS URL (it is logged server-side via `auth.Config.Logger`). + +### Breaking changes + +- Headers-mode requests with underscore, malformed, repeated or conflicting claim headers now get 401. +- `rls.auth.header_prefix`, `role_claim` and `header_claims` are validated as header-safe names in headers mode. + +### Changes +* ci: run PG 14 and 19 on PRs, full matrix and docker on main (#34) +* ci: install postgresql-client only when psql is missing (#35) +* fix(auth): reject colliding claim headers and harden JWKS fetching (#39) + +## [0.6.0] - 2026-11-23 + +### Changes +* feat(metrics): add Prometheus instrumentation, pgexec observer and confx metrics section (#32) +* feat(introspect): record domains as named types (#33) + +## [0.5.0] - 2026-11-23 + +### Changes +* introspect: index catalog lookups, skip type-owned functions (#27) +* Add json output variants for postgis, hstore and range SQL (#29) + +## [0.4.0] - 2026-11-23 + +### Security + +**RLS bypass through role "none" (fixed).** Earlier versions accepted the role name `none` from a role claim (JWT or headers mode) when `rls.allowed_roles` was empty or listed it. PostgreSQL treats `SET ROLE none` as `RESET ROLE`, so such a request ran as the database connection's login role — often the table owner or a superuser — and row-level security did not apply. Role names `none`, `public` and `pg_*` are now rejected at config load (`rls.anonymous_role`, `rls.default_role`, `rls.allowed_roles`) and per request. Deployments should set `rls.allowed_roles` explicitly and should not connect as a superuser or table owner. The claims prefix is validated too (real GUC namespaces such as `plpgsql` or `pg_*` are refused). + +### Highlights + +- `pgexec.QueryTx`: RLS identity, claims and statements in one round trip (anonymous ~3x, 7 claims ~5x ops/s vs `RunTx` in benchmarks); `RunTx` claims now applied in one statement. +- watch: event triggers filter by watched schema (temp/other-schema DDL ignored), `OnChange` skipped when the catalog hash is unchanged, `Watcher.InitialHash`, sql_drop coverage, pinned `search_path`. +- PostGIS operand SQL is one value-independent expression per column type (stable prepared statements). +- `Column.BaseTypeSchema`; extension types matched by schema; custom range types (`Catalog.Ranges`) get contrib range vocabularies. +- `CatalogFormatVersion` 7 — regenerate schema caches. + +### Changes +* Value-independent PostGIS operand SQL; base type schemas and range subtypes in the catalog (#25) +* pgexec: one-round-trip QueryTx for RLS; watch: filter DDL and skip unchanged catalogs (#26) + +## [0.3.0] - 2026-11-22 + +### Changes +* Fix Singularize for words ending in sys/us/is and uncountables (#15) +* postgis: ParseFor column SRID, classify PostGIS input errors (#16) +* introspect: PostgreSQL 17-19 catalog support (temporal keys, NOT ENFORCED, virtual columns) (#17) +* Introspect function defaults/VARIADIC/OUT columns; skip partition clones (#21) +* contrib: operator vocabularies for full-text, trgm, hstore, ltree, citext, ranges, inet (#18) + +## [0.2.0] - 2026-11-22 + +### Changes +* ci: test e2e against PostgreSQL 14-19 (#8) +* Introspect extensions and PostGIS column typmods (#9) +* postgis: connection-filter-postgis operator parity and more accessors (#10) + +### New Contributors +* @archlemon made their first contribution in https://github.com/suprbdev/pdbcore/pull/8 + +## [0.1.0] - 2026-09-23 + +Initial release. + +[Unreleased]: https://github.com/suprbdev/pdbcore/compare/v0.18.0...HEAD +[0.18.0]: https://github.com/suprbdev/pdbcore/compare/v0.17.0...v0.18.0 +[0.17.0]: https://github.com/suprbdev/pdbcore/compare/v0.16.0...v0.17.0 +[0.16.0]: https://github.com/suprbdev/pdbcore/compare/v0.15.0...v0.16.0 +[0.15.0]: https://github.com/suprbdev/pdbcore/compare/v0.14.0...v0.15.0 +[0.14.0]: https://github.com/suprbdev/pdbcore/compare/v0.13.1...v0.14.0 +[0.13.1]: https://github.com/suprbdev/pdbcore/compare/v0.13.0...v0.13.1 +[0.13.0]: https://github.com/suprbdev/pdbcore/compare/v0.12.0...v0.13.0 +[0.12.0]: https://github.com/suprbdev/pdbcore/compare/v0.11.0...v0.12.0 +[0.11.0]: https://github.com/suprbdev/pdbcore/compare/v0.10.0...v0.11.0 +[0.10.0]: https://github.com/suprbdev/pdbcore/compare/v0.9.0...v0.10.0 +[0.9.0]: https://github.com/suprbdev/pdbcore/compare/v0.8.1...v0.9.0 +[0.8.1]: https://github.com/suprbdev/pdbcore/compare/v0.8.0...v0.8.1 +[0.8.0]: https://github.com/suprbdev/pdbcore/compare/v0.7.1...v0.8.0 +[0.7.1]: https://github.com/suprbdev/pdbcore/compare/v0.7.0...v0.7.1 +[0.7.0]: https://github.com/suprbdev/pdbcore/compare/v0.6.0...v0.7.0 +[0.6.0]: https://github.com/suprbdev/pdbcore/compare/v0.5.0...v0.6.0 +[0.5.0]: https://github.com/suprbdev/pdbcore/compare/v0.4.0...v0.5.0 +[0.4.0]: https://github.com/suprbdev/pdbcore/compare/v0.3.0...v0.4.0 +[0.3.0]: https://github.com/suprbdev/pdbcore/compare/v0.2.0...v0.3.0 +[0.2.0]: https://github.com/suprbdev/pdbcore/compare/v0.1.0...v0.2.0 +[0.1.0]: https://github.com/suprbdev/pdbcore/releases/tag/v0.1.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..5f9d43b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,99 @@ +# Contributing to pdbcore + +pdbcore is the shared engine of [pdbq](https://github.com/suprbdev/pdbq) and +[pdbr](https://github.com/suprbdev/pdbr). Most changes start here and are then +consumed by the products, so read the "Changes that touch both products" +section before opening a pull request. + +Security issues go through [SECURITY.md](SECURITY.md), not public issues. + +## Development setup + +You need Go (the version in `go.mod`), Docker with the Compose plugin for the +database-backed tests, and optionally `golangci-lint` and +[`act`](https://github.com/nektos/act). + +```console +$ git clone https://github.com/suprbdev/pdbcore && cd pdbcore +$ make test # hermetic unit tests, go test -race ./... +$ make lint # golangci-lint (falls back to go vet) +$ make test-e2e # DB-backed tests on a disposable PostGIS +$ make help # every target +``` + +## Tests + +- `make test` needs no database. Packages that need one skip their DB tests + when `PDBCORE_TEST_DATABASE_URL` is unset. +- `make test-e2e` starts `compose.test.yaml` (project `pdbcore-test`, host + port 5434, `postgis/postgis:18-3.7`), installs pgvector into the container + on a best-effort basis, runs the DB-backed packages (`testutil`, `pgexec`, + `watch`, `introspect`, `postgis`, `contrib`, `metrics`) and tears the + database down. To run against another PostgreSQL major, change the image tag + in `compose.test.yaml` locally or point `PDBCORE_TEST_DATABASE_URL` at your + own database loaded with `make fixture | psql`. +- The shared fixture is `testutil/fixture.sql` with its Go twin + `testutil.FixtureCatalog()`. `testutil/drift_test.go` loads the SQL, introspects + it and asserts the result equals the Go value, so the two must change together. +- `introspect/testdata/catalog_format.golden` pins the catalog JSON shape. If it + fails, either you changed the shape by accident or you must bump + `introspect.CatalogFormatVersion` and regenerate the golden file in the same + change. + +## Changes that touch both products + +The fixture, the catalog model and anything the products compile against are +tested in pdbq and pdbr as well. A fixture change is a pdbcore pull request +first and a golden-file update in both products second. CI's `downstream` job +builds and tests the `main` of pdbq and pdbr against your branch (using a +`replace` directive in a throwaway checkout, never committed); if it fails, the +change breaks a product and needs a coordinated product pull request. Release +order is pdbcore, then pdbq, then pdbr. + +## Running CI locally + +Run the workflow with `act` before pushing, one job at a time (matrix entries +collide on host port 5434), without pulling images: + +```console +$ act pull_request -W .github/workflows/ci.yaml -j lint-test --pull=false +$ act pull_request -W .github/workflows/ci.yaml -j e2e --matrix pg:19 --pull=false +``` + +Pull requests run PostgreSQL 14 and 19. Pushes to `main` run 14 to 19. Wait +for another `act` run's containers to finish rather than removing them. + +## Load and fuzz tests + +Anything that starts a server for load, DoS or fuzz probing must run under a +hard memory cap, because an uncapped probe once exhausted a developer machine: + +```console +$ systemd-run --user --scope -p MemoryMax=2G -p MemorySwapMax=0 +``` + +Keep request sizes bounded. + +## Commits and pull requests + +Use [Conventional Commits](https://www.conventionalcommits.org/) for commit +messages and pull request titles: `type(scope): subject`, with types such as +`feat`, `fix`, `perf`, `refactor`, `test`, `docs`, `ci` and `chore`, and `!` or +a `BREAKING CHANGE:` footer for breaking changes. Merges are squashed and the +squash subject becomes the changelog entry, so make it read as one. Do not put +issue references in commit messages. In Markdown, put code-like `@` words in +backticks so GitHub does not mention an account. + +Add a line under "Unreleased" in [CHANGELOG.md](CHANGELOG.md) for anything a +user of the module would notice. + +## Releasing + +Maintainers run `make release` on an up-to-date `main`: it checks the tree, +asks for `vX.Y.Z`, runs `make test lint`, tags and pushes. The `Release` +workflow tests the tag, generates a CycloneDX SBOM, attests it and publishes the +GitHub release. Then bump pdbq and pdbr (`go get +github.com/suprbdev/pdbcore@vX.Y.Z`), release pdbq, then pdbr. Move the +"Unreleased" notes in `CHANGELOG.md` under the new version before tagging. + +Compatibility rules are in [docs/compatibility.md](docs/compatibility.md). diff --git a/README.md b/README.md index 4102f49..6ec2e01 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,14 @@ Shared engine for [pdbq](https://github.com/suprbdev/pdbq) (GraphQL) and [pdbr](https://github.com/suprbdev/pdbr) (REST): everything about turning a live PostgreSQL database into an API that is not specific to one transport. + +> **pdbcore is the engine for pdbq and pdbr. It is v0.x and makes no external +> compatibility promise**: minor releases may change any exported API, and +> the products pin an exact version. The 1.0 promise is made by pdbq and pdbr +> for their own surfaces. See [docs/compatibility.md](docs/compatibility.md), +> [SECURITY.md](SECURITY.md), [CONTRIBUTING.md](CONTRIBUTING.md) and +> [CHANGELOG.md](CHANGELOG.md). + Library only — no binary, no GraphQL or REST grammar, no `gqlparser` (CI asserts `go list -deps ./...` contains no GraphQL dependency). @@ -89,13 +97,6 @@ sees are product-neutral so policies port, while names on the wire between a gateway and the server are namespaced like every other product header; `watch.TriggerName` differs (`pdbq_watch` / `pdbr_watch`) so both can watch one database. -Until the first tag lands the products point at a sibling checkout: - -``` -// go.mod (pdbq, pdbr) -replace github.com/suprbdev/pdbcore => ../pdbcore -``` - ## Metrics `metrics.New(metrics.Options{Namespace: "pdbq"})` builds one instance's @@ -258,8 +259,9 @@ pdbcore change first and a golden update in both products second. ## Versioning -Semver `v0.x.y` while pre-1.0: minor bumps may break API, patch bumps may -not; products pin an exact version. `introspect.CatalogFormatVersion` is +Semver `v0.x.y`, and it stays there (see +[docs/compatibility.md](docs/compatibility.md)): minor bumps may break API, +patch bumps may not; products pin an exact version. `introspect.CatalogFormatVersion` is owned here — bumping it is a minor release and both products upgrade in lockstep so a cache written by one (`pdbq schema dump` / `pdbr schema dump`) loads in the other. Fixture changes are patch/minor releases; products @@ -288,12 +290,10 @@ same way. pdbcore is a library, so a release is a tag: `make release` verifies the tree is clean, prompts for `vX.Y.Z`, runs `make test lint`, tags and pushes; the `Release` workflow (`.github/workflows/release.yaml`) re-runs the race tests -and creates the GitHub release with generated notes (no binaries; publishing -is skipped under `act`). - -Consumers then bump with `go get github.com/suprbdev/pdbcore@vX.Y.Z` (and, -for the very first tag, delete their `replace ../pdbcore` line and any -"check out pdbcore next to the repo" / `go mod vendor` steps in their -Makefile, Dockerfile and workflows). Order for the first release: pdbcore -`v0.1.0` → pdbq `v0.11.0` → pdbr `v0.1.0`; the exact steps are in pdbr's -`docs/deployment.md` § Releasing. +and creates the GitHub release with generated notes (no binaries; an SBOM is attached; +publishing is skipped under `act`). + +Consumers then bump with `go get github.com/suprbdev/pdbcore@vX.Y.Z`. Release +order is pdbcore, then pdbq, then pdbr. The workflow also publishes a +CycloneDX SBOM with a build provenance attestation. See +[CONTRIBUTING.md](CONTRIBUTING.md#releasing). diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..7a183b0 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,68 @@ +# Security policy + +pdbcore is the engine behind [pdbq](https://github.com/suprbdev/pdbq) and +[pdbr](https://github.com/suprbdev/pdbr): authentication, request identity +(role and claims) and transaction execution live here. A vulnerability in +those packages affects both products, so report it here or in either product +repository; it is triaged once and fixed in all of them. + +## Reporting a vulnerability + +Report vulnerabilities privately through GitHub security advisories: +[Report a vulnerability](https://github.com/suprbdev/pdbcore/security/advisories/new) +(the repository's Security tab, "Report a vulnerability"). Do not open a +public issue or pull request for a suspected vulnerability. + +Include the pdbcore version (and the pdbq or pdbr version that pins it), the +PostgreSQL version, the relevant configuration (redact secrets) and a +reproduction. A failing test in the affected package is ideal. + +pdbcore is maintained by a small team. Response targets, measured from the +report: + +| Step | Target | +|---|---| +| Acknowledge the report | 3 working days | +| Triage and confirm or decline, with severity | 7 days | +| Fix or mitigation for a confirmed high or critical issue | 30 days | +| Coordinated disclosure | with the fixed releases, credited if you wish | + +These are targets, not guarantees. The reporter is kept informed if one +slips. + +## Supported versions + +pdbcore is a v0.x module without an external compatibility promise (see +[docs/compatibility.md](docs/compatibility.md)). Only the latest release is +supported: a fix ships as the next patch release and the products bump to it. +Supported PostgreSQL versions are listed in +[docs/compatibility.md](docs/compatibility.md#supported-versions). + +## Scope + +In scope: + +- `auth`: accepting a forged, expired or wrongly signed JWT, JWKS handling, + trusting claim headers from an untrusted peer. +- `pgexec`: one request's role or claims reaching another request or + connection, or an identity statement that does not apply. +- `introspect`, `smarttags`, `smartcomments`: exposing objects that smart + comments or privileges hide. +- `confx`, `httpx`: configuration handling that weakens a security setting + silently, and HTTP scaffolding such as CORS. +- SQL injection through the `postgis` and `contrib` SQL builders and + `pgexec` helpers. + +Out of scope: findings that need superuser, `BYPASSRLS` or table-owner access +to the database or write access to the configuration, and vulnerabilities in +PostgreSQL, PostGIS, extensions, Go or third-party modules (report those +upstream). + +## Verifying releases + +Each release publishes a CycloneDX SBOM (`pdbcore__sbom.cdx.json`) +with a GitHub build provenance attestation: + +```console +$ gh attestation verify pdbcore__sbom.cdx.json --repo suprbdev/pdbcore +``` diff --git a/docs/compatibility.md b/docs/compatibility.md new file mode 100644 index 0000000..46e9642 --- /dev/null +++ b/docs/compatibility.md @@ -0,0 +1,50 @@ +# Compatibility and versioning + +pdbcore is the engine module for [pdbq](https://github.com/suprbdev/pdbq) and +[pdbr](https://github.com/suprbdev/pdbr). It is not a product and has **no +external compatibility promise**. + +## Policy + +- pdbcore stays at `v0.x`. A minor bump may change or remove any exported + identifier, configuration type, catalog field or cache format; a patch bump + does not add or break API. +- The products pin an exact pdbcore version. Their major versions are not tied + to pdbcore's: pdbq 1.x and pdbr 1.x may sit on any pdbcore `v0.x`. +- Nothing outside the products is expected to import pdbcore. If you do, pin + an exact version and read the [changelog](../CHANGELOG.md) before each bump. + Issues about using pdbcore on its own are welcome but are not covered by a + stability promise. +- The compatibility promise that does exist is made by the products, for their + own surfaces (configuration keys, CLI, HTTP, GraphQL and REST grammar, error + codes, metrics). See pdbq's and pdbr's `docs/compatibility.md`. pdbcore's + job is not to make those change without the products noticing: CI builds and + tests pdbq and pdbr at their `main` against every pull request. + +## Schema cache format + +`introspect.CatalogFormatVersion` identifies the schema cache wire format. +Bumping it is a pdbcore minor release, and both products upgrade in lockstep. +`introspect/testdata/catalog_format.golden` fails the build when the JSON shape +changes without a bump. Within one format version a cache written by pdbq +loads in pdbr and the other way round. After a bump, the products ask you to +re-run `schema dump`. + +## Deprecation + +Removed or renamed API is called out in the changelog. Go identifiers that are +about to go carry a `// Deprecated:` doc comment for at least one minor +release where that is practical; since the module is v0.x this is a courtesy, +not a promise. + +## Supported versions + +| Component | Supported | +|---|---| +| PostgreSQL | 14 to 19. Older servers are refused at introspection and on every pooled connection. | +| PostGIS | 3.7 is what CI runs against. Earlier 3.x releases are not tested. | +| pgvector | Best effort. CI installs it when the image's package source has it and skips its tests otherwise; operators added in 0.7 (`l1`, bit distances) need 0.7 or later. | +| Go | The version in `go.mod` (1.26) or newer, for building from source. | + +CI runs every PostgreSQL major from 14 to 19 on pushes to `main` and 14 and 19 +on pull requests, on Linux amd64. See [../CONTRIBUTING.md](../CONTRIBUTING.md).