Skip to content

feat(postgres): add signed download URLs mutation for standalone backups - #681

Open
frodesundby wants to merge 4 commits into
mainfrom
feat/postgres-backup-signed-urls
Open

frodesundby wants to merge 4 commits into
mainfrom
feat/postgres-backup-signed-urls

Conversation

@frodesundby

@frodesundby frodesundby commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds GraphQL mutation createPostgresBackupDownload(input: CreatePostgresBackupDownloadInput!): CreatePostgresBackupDownloadPayload! returning backup, expiresAt (1h), and files { key url sizeBytes sha256 } (with nais-backup.json last) so teams and tenants can build off-platform copy workflows without streaming backup bytes through nais-api.
  • Adds postgres:backups:download authorization enforced with requireStrictTeamAuthorization (team members and team-scoped Nais ServiceAccounts only; no global admin or global service account bypass).
  • Reads <prefix>/nais-backup.json from the backup's DR bucket, validates relative object paths and SHA-256 checksums, signs V4 GET URLs using GOOGLE_SERVICE_ACCOUNT_EMAIL (.Values.serviceaccount.email from Fasit), and records POSTGRES_BACKUP_DOWNLOAD_CREATED in the activity log.

Rollout

Requires nais/pgrator#248 (roles/storage.objectViewer on team DR buckets for nais-api) to be rolled out first.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Signing calls ignore cancellation, and the unpaginated backup inventory can trigger thousands of IAM requests and a large mutation response.

2 open issues
2 files not reviewed
  • internal/graph/gengql/postgres_backup.generated.go: Generated file
  • internal/graph/gengql/schema.generated.go: Generated file
What changed in this PR

Adds standalone Postgres backup downloads to Nais API, allowing teams to copy backups directly from object storage without streaming data through the API.

Changes:

  • Adds a mutation returning one-hour signed URLs and file integrity metadata.
  • Enforces strict team authorization and records download creation.
  • Wires signing configuration and adds validation and integration coverage.
File Description
internal/​persistence/​postgres/​dataloader.go Injects the backup archive store.
internal/​persistence/​postgres/​backup_download.go Validates manifests and generates signed URLs.
internal/​persistence/​postgres/​backup_download_test.go Tests archive validation and download metadata.
internal/​persistence/​postgres/​backup_activitylog.go Registers download activity logging.
internal/​integration/​manager.go Updates integration configuration.
internal/​graph/​schema/​postgres_backup.graphqls Defines the download mutation and response.
internal/​graph/​postgres_backup.resolvers.go Connects the mutation to domain logic.
internal/​graph/​gengql/​schema.generated.go Adds generated mutation handling.
internal/​graph/​gengql/​root_.generated.go Updates generated schema and complexity definitions.
internal/​graph/​gengql/​postgres_backup.generated.go Adds generated input and response handling.
internal/​database/​migrations/​0087_add_postgres_backup_download_authorization.sql Grants download permission to team roles.
internal/​cmd/​api/​http.go Configures and injects the archive store.
internal/​cmd/​api/​config.go Adds signing identity configuration.
internal/​cmd/​api/​api.go Passes the signing identity into setup.
internal/​auth/​authz/​queries.go Adds strict team download authorization.
integration_tests/​postgres_backups.lua Covers authorization, downloads, and auditing.
go.sum Updates dependency checksums.
go.mod Adds the storage client dependency.
charts/​nais-api/​templates/​deployment.yaml Supplies the signing service-account email.

Review effort: Balanced

…ning

- Reject manifests whose backupName, sourceUID, serverName or backupID do not
  match the PostgresBackup, and archive prefixes other than the backup name
- Accept only manifest schemaVersion 1 and at most 10,000 objects
- Stop scheduling IAM signing calls after a failure or canceled request
- Record file count and URL expiry in the download activity log entry
- Drop down migration from 0087 and clarify the file key documentation
@frodesundby
frodesundby marked this pull request as ready for review December 4, 2026 13:26
@frodesundby
frodesundby requested a review from a team as a code owner December 4, 2026 13:26
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.

4 participants