fix(config): Merge producer role database overrides in split config

What does this MR do?

In split mode, role overrides under overrides.<application_identifier> are dropped silently, so the producer manages the publication as the replication user, which cannot call siphon_alter_publication.

This MR merges primary_database and snapshot_database. A block naming another user without a non-empty password is skipped when database sets one, with one warning.

flowchart LR
  subgraph base["base config"]
    DB["connection.databases.main<br/>user: siphon_replicator"]
    OV["overrides.producer-main<br/>primary_database.user: siphon"]
  end
  DB -->|database_ref| D["producer.database"]
  OV -.->|"dropped today"| X(("x"))
  C{"user differs from<br/>database user?"}
  P["producer.primary_database"]
  OV ==>|"this MR"| C
  D -->|fills host, port, database| C
  C -->|"no password set,<br/>database has one"| E["warning at load, block<br/>not applied, replication<br/>connection kept"]
  C -->|"password set, or same user"| P
  D --> R["replication slot<br/>as siphon_replicator"]
  P --> F["siphon_alter_publication<br/>as siphon"]

Two questions for review:

  1. Would you prefer the stricter option, failing config load with an error naming the producer and block? It catches the mistake at deploy time, and it turns today's working configs that carry a user-only block into a failed start.
  2. Should an empty password instead apply as written?

How do I test it?

go test ./pkg/config/...

Without a grant to the replication role:

  • No override: 0 tables, as released.
  • {user: siphon}: one override warning, 0 tables.
  • With password: 86 tables.

An AI coding assistant wrote this change and ran the checks.

Related: gitlab-org/orbit/knowledge-graph#1145 (closed)

Details: behaviour, limits, tests and results

Behaviour

Override block Result
none merged config unchanged, byte for byte against output captured before this change
{user: siphon, password: ...} applies, with host, port and database from database
{user: siphon} not applied, one warning: producer "siphon_main_1" primary_database: user "siphon" differs from the database user "siphon_replicator" and no password is set; override not applied, set password to apply this override
{user: siphon_replicator, password: ""} or no user, empty or null password applies, with the database password
a CDC entry's own block wins over the override, and is left as written when the override is skipped
consumers, reconcilers, producers without an override no role block

The fill takes host, port, database, user and password. It leaves out ssl_mode, matching the single-file rule (producer_test.go:88-99). A snapshot_database block takes disallow_hot_standby_feedback_on from database when it omits the key, and primary_database does not. The single-file config path does not call the merge.

Why a user without a password is skipped: the password belongs to the shared database user, so inheriting it for another user can only fail, and the login error (password authentication failed for user "siphon") does not point at the cause. Skipping keeps existing deployments loading as they do today, including ones that copied the chart 2.4.2 example and granted the function to the replication role by hand. A companion chart change adds password to both example blocks and the matching secret entries.

Limits:

  • An empty or null password counts as unset, which is what an unset ${VAR} becomes.
  • A password supplied outside the config (.pgpass, a client certificate, trust) looks like no password, so when database sets one, a block naming another user is skipped with the warning.
  • A role block without ssl_mode connects with prefer even when database sets require.
  • A null disallow_hot_standby_feedback_on counts as unset, and a value the snapshot block sets keeps its own.

The gap dates from 80ce1384 (feat(config): Add support for passing in split config (connection and cdc)).

Out of scope

Out of scope: inherited keys are matched by exact name, so a key written with different casing (for example Host) is not seen as set, and the resolved database's value is added beside it. This predates this MR.

Tests

  • TestMergeConfigs_ProducerRoleOverridesLayerOnDatabase: both blocks reach the producer, override keys win and the rest come from database.
  • TestMergeConfigs_CDCRoleBlockWinsOverOverride: a block in the CDC entry beats the override.
  • TestMergeConfigs_RoleOverridesOnlyReachProducers: consumers, reconcilers and producers without an override get no role block.
  • TestMergeConfigs_RoleOverridesDoNotAliasDatabases: a filled block is a copy, not a reference to the shared entry or the override.
  • TestMergeConfigs_NoRoleOverridesLeavesProducerUnchanged: the rendered YAML without role overrides matches output captured before this change.
  • TestMergeConfigs_RoleOverrideUserWithoutPasswordIsSkippedWithWarning: a different user without a password is not applied for either block, and one warning names the producer and the block.
  • TestMergeConfigs_RoleOverrideDoesNotInheritSSLMode: the fill leaves ssl_mode out.
  • TestMergeConfigs_RoleOverrideHotStandbyFeedbackFlag, TestNewMergedConfig_SnapshotDatabaseHotStandbyFeedbackFlag: a snapshot block inherits the flag from database when it omits it, and keeps a value it sets.
  • TestMergeConfigs_SkippedRoleOverrideLeavesCDCEntryBlockUntouched: a skipped override does not edit the CDC entry's own block.
  • TestMergeConfigs_RoleOverrideWithEmptyPasswordIsSkippedWithWarning: an empty or null password on another user is skipped with the warning.
  • TestMergeConfigs_RoleOverrideWithEmptyPasswordTakesTheDatabasePassword: an empty or null password on the same user or no user takes the database password.
  • TestMergeConfigs_RoleOverrideUserWithPasswordMerges, ..IsFineWhenDatabaseHasNone, ..WithoutUserKeepsDatabaseUser: a valid block applies without a warning.
  • TestNewMergedConfig_ProducerRoleOverrides: the primary and snapshot connection strings use siphon and siphon_snapshot, while replication keeps siphon_replicator.
  • TestNewMergedConfig_UserOnlyOverrideKeepsReplicationConnectionAndWarns: a user-only block leaves the primary connection on siphon_replicator and surfaces one warning for the caller to log.

End to end

On 0.0.163-beta with this change applied, on a split-mode deployment with a separate replication user and use_alter_publication_function: true, the publication starting empty:

Producer override Result
none, released image 0 tables in the publication
none, this change 0 tables, no warning, same as released
primary_database: {user: siphon} pods ready, one warning, 0 tables, connections as the replication user
primary_database: {user: siphon, password: ...} 86 tables, no grant added
Edited by Andrew Dunn

Merge request reports

Loading
Loading