Prepared schema creation ignores grant errors and does not retry missing privileges

Open
#3,230 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

  • #3235 by @ritojoao — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go, kubernetes, postgresql
Domain
backend, databases

Research direction

Start with execCreateDatabaseSchema() in pkg/cluster/database.go and syncPreparedSchemas() in pkg/cluster/sync.go; trace how default privilege grant errors are handled and how existing schemas are skipped. Check nearby tests for prepared schema synchronization. Done means grant failures are reported and missing privileges are retried on later synchronizations.

Written by the indexing model from the issue text.

Description

duplicate

Description

When initializing a prepared schema, the operator creates the schema first and then sets its default privileges. If schema creation succeeds but the privilege grant step fails, execCreateDatabaseSchema() ignores the error from execAlterSchemaDefaultPrivileges() and returns nil (pkg/cluster/database.go:453-480).

On subsequent runs, syncPreparedSchemas() checks only whether the schema name already exists and skips existing schemas (pkg/cluster/sync.go:1660-1693). As a result, synchronizations report no errors, and the missing schema USAGE and default table SELECT privileges are never retried.

Steps to reproduce

  1. Configure a prepared database schema_db (DefaultUsers=false) with a prepared schema data (DefaultRoles=false).
  2. Create schema_db along with the schema_db_owner and schema_db_reader roles, leaving schema_db_writer absent.
  3. Synchronize prepared schemas. Schema data is created, while setting its default privileges fails because schema_db_writer does not exist (and the error is ignored).
  4. Create the missing schema_db_writer role and synchronize prepared schemas three more times.
  5. Create a new table in data as schema_db_owner: schema_db_reader has neither USAGE on schema data nor SELECT on the new table.

Expected behavior

Return an error when execAlterSchemaDefaultPrivileges() fails, and retry the missing schema privileges on subsequent synchronizations until setup succeeds.

Dominant language
Go
Stars
5.3k
Forks
1.1k
Avg merge
3d 17h
Merged PRs (30d)
11

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from zalando/postgres-operator

All issues in zalando/postgres-operator

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.