From 76805601a8ce7d224ef551921f5f52c17749a892 Mon Sep 17 00:00:00 2001 From: nilsver Date: Mon, 9 Nov 2026 12:06:36 +0000 Subject: [PATCH 01/15] Read the redborder DB password for the CVE ingest script from an OpenBao agent file in /run --- resources/metadata.rb | 2 ++ resources/providers/config.rb | 11 +++++++++++ resources/resources/config.rb | 2 ++ resources/scripts/rb_ingest_vuln_cve_pg.rb | 5 ++++- .../templates/default/db_redborder_pass.ctmpl.erb | 1 + 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 resources/templates/default/db_redborder_pass.ctmpl.erb diff --git a/resources/metadata.rb b/resources/metadata.rb index 911425f..5792027 100644 --- a/resources/metadata.rb +++ b/resources/metadata.rb @@ -6,3 +6,5 @@ license 'AGPL-3.0' description 'Installs/Configures cookbook-logstash' version '0.5.4' + +depends 'openbao' diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 275b383..9ed0104 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -70,6 +70,17 @@ action [:start, :enable] end + # rb_ingest_vuln_cve_pg.rb (root) reads the redborder DB password from here, in memory only + openbao_secret_file 'postgresql-db-redborder' do + source 'db_redborder_pass.ctmpl.erb' + cookbook 'postgresql' + destination '/run/rb-secrets/postgresql/db_redborder_pass' + owner 'root' + group 'root' + mode '0600' + action new_resource.openbao ? :add : :remove + end + Chef::Log.info('PostgreSQL cookbook has been processed') rescue => e Chef::Log.error(e.message) diff --git a/resources/resources/config.rb b/resources/resources/config.rb index ad68593..c8bae9c 100644 --- a/resources/resources/config.rb +++ b/resources/resources/config.rb @@ -8,3 +8,5 @@ attribute :postgresql_port, kind_of: Integer, default: 5432 attribute :cdomain, kind_of: String, default: 'redborder.cluster' attribute :ipaddress, kind_of: String, default: '127.0.0.1' +# true: service passwords live in OpenBao (agent files in /run), not in data bags +attribute :openbao, kind_of: [TrueClass, FalseClass], default: false diff --git a/resources/scripts/rb_ingest_vuln_cve_pg.rb b/resources/scripts/rb_ingest_vuln_cve_pg.rb index 49490f4..7766755 100644 --- a/resources/scripts/rb_ingest_vuln_cve_pg.rb +++ b/resources/scripts/rb_ingest_vuln_cve_pg.rb @@ -32,10 +32,13 @@ def self.redborder_pg_conn .reject(&:empty?) .map { |line| line.split(/:\s+/, 2) } .to_h + # OpenBao installs keep the password out of the data bag: the agent renders it into /run + pass_file = '/run/rb-secrets/postgresql/db_redborder_pass' + password = File.exist?(pass_file) ? File.read(pass_file).strip : databag['pass'] { dbname: databag['database'], user: databag['username'], - password: databag['pass'], + password: password, host: databag['hostname'], port: databag['port'], } diff --git a/resources/templates/default/db_redborder_pass.ctmpl.erb b/resources/templates/default/db_redborder_pass.ctmpl.erb new file mode 100644 index 0000000..53f19ad --- /dev/null +++ b/resources/templates/default/db_redborder_pass.ctmpl.erb @@ -0,0 +1 @@ +{{ with secret "secret/data/db_redborder" }}{{ .Data.data.pass }}{{ end }} \ No newline at end of file From b812d85c903b7f9f4c04ef66c0327f17de7cc59e Mon Sep 17 00:00:00 2001 From: nilsver Date: Tue, 17 Nov 2026 09:23:56 +0000 Subject: [PATCH 02/15] Store PostgreSQL passwords as SCRAM-SHA-256 --- resources/templates/default/postgresql.conf.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/templates/default/postgresql.conf.erb b/resources/templates/default/postgresql.conf.erb index 06c275b..dabdb49 100644 --- a/resources/templates/default/postgresql.conf.erb +++ b/resources/templates/default/postgresql.conf.erb @@ -6,6 +6,7 @@ # Memory asigned: 1449 listen_addresses = '*' port = 5432 +password_encryption = scram-sha-256 # LINCE: approved password hashing (not md5) max_connections = 1000 shared_buffers = 362MB work_mem = 8MB # min 64kB From 06639f8f863ddd22d6603111bebdc60d56e541d9 Mon Sep 17 00:00:00 2001 From: nilsver Date: Tue, 17 Nov 2026 10:46:47 +0000 Subject: [PATCH 03/15] Switch existing PostgreSQL to SCRAM-SHA-256 password storage --- resources/providers/config.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 9ed0104..35a8652 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -70,6 +70,15 @@ action [:start, :enable] end + # Existing databases (postgresql.conf is only written at initdb): new passwords as SCRAM-SHA-256, not md5. + # Roles keep their old md5 verifier until their password is set again ('rb_openbao rotate'). + psql = 'psql -h 127.0.0.1 -U postgres -XAt' + execute 'Store new PostgreSQL passwords as SCRAM-SHA-256' do + command "#{psql} -c \"ALTER SYSTEM SET password_encryption = 'scram-sha-256'\" && #{psql} -c 'SELECT pg_reload_conf()'" + only_if "#{psql} -c 'SELECT 1'" + not_if "#{psql} -c 'SHOW password_encryption' | grep -qx scram-sha-256" + end + # rb_ingest_vuln_cve_pg.rb (root) reads the redborder DB password from here, in memory only openbao_secret_file 'postgresql-db-redborder' do source 'db_redborder_pass.ctmpl.erb' From 309702f204397b6aafb0395910ba9a0c43f53ffb Mon Sep 17 00:00:00 2001 From: nilsver Date: Tue, 17 Nov 2026 12:41:23 +0000 Subject: [PATCH 04/15] pg_hba: passwords (SCRAM-SHA-256) from the sync network, rep password from OpenBao via pgpass --- resources/libraries/helper.rb | 24 ++++++++++ resources/providers/config.rb | 49 +++++++++++++++++++- resources/templates/default/pg_hba.conf.erb | 14 +++++- resources/templates/default/pgpass.ctmpl.erb | 1 + test/helper_test.rb | 14 ++++++ 5 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 resources/templates/default/pgpass.ctmpl.erb create mode 100644 test/helper_test.rb diff --git a/resources/libraries/helper.rb b/resources/libraries/helper.rb index bbbe3b9..8260c4b 100644 --- a/resources/libraries/helper.rb +++ b/resources/libraries/helper.rb @@ -1,3 +1,5 @@ +require 'openssl' + module Postgresql module Helper def local_routes @@ -14,6 +16,28 @@ def local_routes routes end + # Roles that log in over the sync network with a password (KV db_*). The chef-server roles connect from + # this node's own addresses (trusted), so their old md5 verifiers do not matter here. + NETWORK_ROLES = %w(redborder druid radius airflow rep).freeze + PSQL = '/bin/psql -h 127.0.0.1 -U postgres -d postgres -XAtq'.freeze + + # scram-sha-256 once no network role has an md5 verifier left ('rb_openbao rotate' re-sets them). + # Until then md5: it still checks the password (and uses SCRAM for roles that already have a SCRAM verifier). + def hba_password_method + out = `#{PSQL} -c "SELECT count(*) FROM pg_authid WHERE rolname IN ('#{NETWORK_ROLES.join("','")}') AND rolpassword LIKE 'md5%'" 2>/dev/null`.strip + $?.success? && out == '0' ? 'scram-sha-256' : 'md5' + end + + # SCRAM-SHA-256 verifier as PostgreSQL stores it (RFC 5802/7677, 4096 iterations): the plain password + # never reaches the server, so it cannot end up in its log. Generated hex passwords: no SASLprep needed. + def scram_verifier(pass, salt = OpenSSL::Random.random_bytes(16)) + salted = OpenSSL::KDF.pbkdf2_hmac(pass, salt: salt, iterations: 4096, length: 32, hash: 'sha256') + client = OpenSSL::HMAC.digest('sha256', salted, 'Client Key') + server = OpenSSL::HMAC.digest('sha256', salted, 'Server Key') + b = ->(s) { [s].pack('m0') } + "SCRAM-SHA-256$4096:#{b.call(salt)}$#{b.call(OpenSSL::Digest::SHA256.digest(client))}:#{b.call(server)}" + end + def find_master_ip cluster_info = node.dig('redborder', 'cluster_info') postgresql_managers = node.dig('redborder', 'managers_per_services', 'postgresql') diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 35a8652..5116a07 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -7,6 +7,8 @@ begin user = new_resource.user routes = local_routes + openbao = new_resource.openbao + pgpass = '/run/rb-secrets/postgresql-rep/pgpass' dnf_package 'postgresql' do action :upgrade @@ -22,6 +24,24 @@ not_if 'getent passwd postgres' end + # Password of the replication user rep: libpq (pg_basebackup, the walreceiver, rb_check_postgresql.sh) + # reads ~postgres/.pgpass, a link to the agent's file in /run. Before initdb: a joining node needs it to sync. + openbao_secret_file 'postgresql-rep' do + source 'pgpass.ctmpl.erb' + cookbook 'postgresql' + destination pgpass + owner user + group user + mode '0600' + action openbao ? :add : :remove + end + + link '/var/lib/pgsql/.pgpass' do + to pgpass + action openbao ? :create : :delete + only_if { openbao || ::File.symlink?('/var/lib/pgsql/.pgpass') } + end + unless ::File.exist? '/var/lib/pgsql/data/postgresql.conf' Chef::Log.info('Initializing postgresql service') execute 'postgresql_initdb' do @@ -45,6 +65,11 @@ if master_ip local_ips = `hostname -I`.split unless local_ips.include?(master_ip) + # The agent restart for pgpass is delayed to the end of the run: the sync needs it now + if openbao && !::File.size?(pgpass) + system('systemctl restart openbao-agent') + 30.times { ::File.size?(pgpass) ? break : sleep(1) } + end system("rb_sync_from_master.sh #{master_ip}") end end @@ -53,14 +78,34 @@ end end + # rep was created without a password (rb_configure_leader.sh): give it the one in OpenBao, on the + # primary only (replicas get it through WAL). Later changes come from 'rb_openbao rotate db_rep'. + ruby_block 'Set the PostgreSQL password of rep' do + block do + pass = ::File.read(pgpass).strip.split(':', 5).last + cmd = Mixlib::ShellOut.new("#{Postgresql::Helper::PSQL} -v ON_ERROR_STOP=1", + input: "ALTER ROLE rep PASSWORD '#{scram_verifier(pass)}';\n").run_command + # no stdout/stderr in the message: psql echoes the failing statement + raise "ALTER ROLE rep failed (exit #{cmd.exitstatus})" if cmd.error? + end + sensitive true + ignore_failure true + only_if do + openbao && ::File.size?(pgpass) && + `#{Postgresql::Helper::PSQL} -c "SELECT pg_is_in_recovery() = false AND rolpassword IS NULL FROM pg_authid WHERE rolname = 'rep'" 2>/dev/null`.strip == 't' + end + end + + vip = (data_bag_item('rBglobal', 'ipvirtual-internal-postgresql')['ip'] rescue nil) template '/var/lib/pgsql/data/pg_hba.conf' do source 'pg_hba.conf.erb' owner user group user mode '0644' cookbook 'postgresql' - variables(routes: routes, user: user) - notifies :restart, 'service[postgresql]' + variables(routes: routes, user: user, openbao: openbao, method: (hba_password_method if openbao), + local_ips: [new_resource.ipaddress, vip].compact.uniq - ['127.0.0.1']) + notifies :reload, 'service[postgresql]' # pg_hba.conf needs no restart end service 'postgresql' do diff --git a/resources/templates/default/pg_hba.conf.erb b/resources/templates/default/pg_hba.conf.erb index 87162b4..935fc49 100644 --- a/resources/templates/default/pg_hba.conf.erb +++ b/resources/templates/default/pg_hba.conf.erb @@ -1,6 +1,17 @@ #TYPE DATABASE USER CIDR-ADDRESS METHOD host all all 127.0.0.1/32 trust host all all ::1/128 trust +<% if @openbao %> +# This node's own addresses: only local processes connect from them (master.postgresql.service, the +# chef-server superuser at install). Every other address must send a password. +<% @local_ips.each do |ip| %> +host all all <%= ip %>/32 trust +<% end %> +<% @routes.each do |r| %> +host all all <%= r.to_s %> <%= @method %> +host replication rep <%= r.to_s %> <%= @method %> +<% end %> +<% else %> <% @routes.each do |r| %> host all all <%= r.to_s %> trust host all <%= @user %> <%= r.to_s %> trust @@ -9,6 +20,7 @@ host redborder redborder <%= r.to_s %> trust host replication rep <%= r.to_s %> trust host radius radius <%= r.to_s %> trust <% end %> +<% end %> <% if !node["redborder"]["manager"].nil? and !node["redborder"]["manager"]["database"].nil? and !node["redborder"]["manager"]["database"]["grant"].nil? %> <% node["redborder"]["manager"]["database"]["grant"].each do |x| %> <% if x["network"] != @netsync and x["network"] != "127.0.0.1/32" %> @@ -17,4 +29,4 @@ host redborder redborder <%= x["network"] %> <%= x["mode"] %> host radius radius <%= x["network"] %> <%= x["mode"] %> <% end %> <% end %> -<% end %> \ No newline at end of file +<% end %> diff --git a/resources/templates/default/pgpass.ctmpl.erb b/resources/templates/default/pgpass.ctmpl.erb new file mode 100644 index 0000000..26611ac --- /dev/null +++ b/resources/templates/default/pgpass.ctmpl.erb @@ -0,0 +1 @@ +*:*:*:rep:{{ with secret "secret/data/db_rep" }}{{ .Data.data.pass }}{{ end }} diff --git a/test/helper_test.rb b/test/helper_test.rb new file mode 100644 index 0000000..706303d --- /dev/null +++ b/test/helper_test.rb @@ -0,0 +1,14 @@ +# ruby test/helper_test.rb +require 'minitest/autorun' +require_relative '../resources/libraries/helper' + +class HelperTest < Minitest::Test + include Postgresql::Helper + + def test_scram_verifier_matches_postgresql_format + # same vector as redborder-openbao internal/bao rotate_test.go (checked against PostgreSQL) + assert_equal 'SCRAM-SHA-256$4096:MDEyMzQ1Njc4OWFiY2RlZg==$1asHMbH2my37rP6NwUFN+2R8TdQH62n1sUt37vYmrdg=:NzWfkwfUXAEhu4qk7VI4+OobFAOX1J1vq5shICwNaKc=', + scram_verifier('secretpass', '0123456789abcdef') + refute_equal scram_verifier('x'), scram_verifier('x') + end +end From a64914d81f07074734036ff6dd8e3099cc14de3c Mon Sep 17 00:00:00 2001 From: nilsver Date: Wed, 18 Nov 2026 08:59:31 +0000 Subject: [PATCH 05/15] Trim comments --- resources/libraries/helper.rb | 9 +++------ resources/providers/config.rb | 16 ++++++---------- resources/resources/config.rb | 1 - resources/scripts/rb_ingest_vuln_cve_pg.rb | 1 - resources/templates/default/pg_hba.conf.erb | 3 +-- resources/templates/default/postgresql.conf.erb | 2 +- test/helper_test.rb | 2 +- 7 files changed, 12 insertions(+), 22 deletions(-) diff --git a/resources/libraries/helper.rb b/resources/libraries/helper.rb index 8260c4b..185d3d7 100644 --- a/resources/libraries/helper.rb +++ b/resources/libraries/helper.rb @@ -16,20 +16,17 @@ def local_routes routes end - # Roles that log in over the sync network with a password (KV db_*). The chef-server roles connect from - # this node's own addresses (trusted), so their old md5 verifiers do not matter here. + # no chef-server roles: they connect from this node's own (trusted) addresses NETWORK_ROLES = %w(redborder druid radius airflow rep).freeze PSQL = '/bin/psql -h 127.0.0.1 -U postgres -d postgres -XAtq'.freeze - # scram-sha-256 once no network role has an md5 verifier left ('rb_openbao rotate' re-sets them). - # Until then md5: it still checks the password (and uses SCRAM for roles that already have a SCRAM verifier). + # md5 until no network role has an md5 verifier: md5 also accepts SCRAM verifiers def hba_password_method out = `#{PSQL} -c "SELECT count(*) FROM pg_authid WHERE rolname IN ('#{NETWORK_ROLES.join("','")}') AND rolpassword LIKE 'md5%'" 2>/dev/null`.strip $?.success? && out == '0' ? 'scram-sha-256' : 'md5' end - # SCRAM-SHA-256 verifier as PostgreSQL stores it (RFC 5802/7677, 4096 iterations): the plain password - # never reaches the server, so it cannot end up in its log. Generated hex passwords: no SASLprep needed. + # built here so the plain password never reaches the server log def scram_verifier(pass, salt = OpenSSL::Random.random_bytes(16)) salted = OpenSSL::KDF.pbkdf2_hmac(pass, salt: salt, iterations: 4096, length: 32, hash: 'sha256') client = OpenSSL::HMAC.digest('sha256', salted, 'Client Key') diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 5116a07..54f5b7a 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -24,8 +24,7 @@ not_if 'getent passwd postgres' end - # Password of the replication user rep: libpq (pg_basebackup, the walreceiver, rb_check_postgresql.sh) - # reads ~postgres/.pgpass, a link to the agent's file in /run. Before initdb: a joining node needs it to sync. + # before initdb: a joining node needs rep's password to sync openbao_secret_file 'postgresql-rep' do source 'pgpass.ctmpl.erb' cookbook 'postgresql' @@ -65,7 +64,7 @@ if master_ip local_ips = `hostname -I`.split unless local_ips.include?(master_ip) - # The agent restart for pgpass is delayed to the end of the run: the sync needs it now + # the delayed agent restart comes too late for the sync if openbao && !::File.size?(pgpass) system('systemctl restart openbao-agent') 30.times { ::File.size?(pgpass) ? break : sleep(1) } @@ -78,14 +77,13 @@ end end - # rep was created without a password (rb_configure_leader.sh): give it the one in OpenBao, on the - # primary only (replicas get it through WAL). Later changes come from 'rb_openbao rotate db_rep'. + # primary only: replicas get it through WAL ruby_block 'Set the PostgreSQL password of rep' do block do pass = ::File.read(pgpass).strip.split(':', 5).last cmd = Mixlib::ShellOut.new("#{Postgresql::Helper::PSQL} -v ON_ERROR_STOP=1", input: "ALTER ROLE rep PASSWORD '#{scram_verifier(pass)}';\n").run_command - # no stdout/stderr in the message: psql echoes the failing statement + # no output in the message: psql echoes the statement raise "ALTER ROLE rep failed (exit #{cmd.exitstatus})" if cmd.error? end sensitive true @@ -105,7 +103,7 @@ cookbook 'postgresql' variables(routes: routes, user: user, openbao: openbao, method: (hba_password_method if openbao), local_ips: [new_resource.ipaddress, vip].compact.uniq - ['127.0.0.1']) - notifies :reload, 'service[postgresql]' # pg_hba.conf needs no restart + notifies :reload, 'service[postgresql]' end service 'postgresql' do @@ -115,8 +113,7 @@ action [:start, :enable] end - # Existing databases (postgresql.conf is only written at initdb): new passwords as SCRAM-SHA-256, not md5. - # Roles keep their old md5 verifier until their password is set again ('rb_openbao rotate'). + # postgresql.conf is only written at initdb psql = 'psql -h 127.0.0.1 -U postgres -XAt' execute 'Store new PostgreSQL passwords as SCRAM-SHA-256' do command "#{psql} -c \"ALTER SYSTEM SET password_encryption = 'scram-sha-256'\" && #{psql} -c 'SELECT pg_reload_conf()'" @@ -124,7 +121,6 @@ not_if "#{psql} -c 'SHOW password_encryption' | grep -qx scram-sha-256" end - # rb_ingest_vuln_cve_pg.rb (root) reads the redborder DB password from here, in memory only openbao_secret_file 'postgresql-db-redborder' do source 'db_redborder_pass.ctmpl.erb' cookbook 'postgresql' diff --git a/resources/resources/config.rb b/resources/resources/config.rb index c8bae9c..55f011c 100644 --- a/resources/resources/config.rb +++ b/resources/resources/config.rb @@ -8,5 +8,4 @@ attribute :postgresql_port, kind_of: Integer, default: 5432 attribute :cdomain, kind_of: String, default: 'redborder.cluster' attribute :ipaddress, kind_of: String, default: '127.0.0.1' -# true: service passwords live in OpenBao (agent files in /run), not in data bags attribute :openbao, kind_of: [TrueClass, FalseClass], default: false diff --git a/resources/scripts/rb_ingest_vuln_cve_pg.rb b/resources/scripts/rb_ingest_vuln_cve_pg.rb index 7766755..b9d26b5 100644 --- a/resources/scripts/rb_ingest_vuln_cve_pg.rb +++ b/resources/scripts/rb_ingest_vuln_cve_pg.rb @@ -32,7 +32,6 @@ def self.redborder_pg_conn .reject(&:empty?) .map { |line| line.split(/:\s+/, 2) } .to_h - # OpenBao installs keep the password out of the data bag: the agent renders it into /run pass_file = '/run/rb-secrets/postgresql/db_redborder_pass' password = File.exist?(pass_file) ? File.read(pass_file).strip : databag['pass'] { diff --git a/resources/templates/default/pg_hba.conf.erb b/resources/templates/default/pg_hba.conf.erb index 935fc49..77d42f1 100644 --- a/resources/templates/default/pg_hba.conf.erb +++ b/resources/templates/default/pg_hba.conf.erb @@ -2,8 +2,7 @@ host all all 127.0.0.1/32 trust host all all ::1/128 trust <% if @openbao %> -# This node's own addresses: only local processes connect from them (master.postgresql.service, the -# chef-server superuser at install). Every other address must send a password. +# This node's own addresses: local processes only <% @local_ips.each do |ip| %> host all all <%= ip %>/32 trust <% end %> diff --git a/resources/templates/default/postgresql.conf.erb b/resources/templates/default/postgresql.conf.erb index dabdb49..fbe0d58 100644 --- a/resources/templates/default/postgresql.conf.erb +++ b/resources/templates/default/postgresql.conf.erb @@ -6,7 +6,7 @@ # Memory asigned: 1449 listen_addresses = '*' port = 5432 -password_encryption = scram-sha-256 # LINCE: approved password hashing (not md5) +password_encryption = scram-sha-256 max_connections = 1000 shared_buffers = 362MB work_mem = 8MB # min 64kB diff --git a/test/helper_test.rb b/test/helper_test.rb index 706303d..1b7d8ef 100644 --- a/test/helper_test.rb +++ b/test/helper_test.rb @@ -6,7 +6,7 @@ class HelperTest < Minitest::Test include Postgresql::Helper def test_scram_verifier_matches_postgresql_format - # same vector as redborder-openbao internal/bao rotate_test.go (checked against PostgreSQL) + # same vector as redborder-openbao rotate_test.go assert_equal 'SCRAM-SHA-256$4096:MDEyMzQ1Njc4OWFiY2RlZg==$1asHMbH2my37rP6NwUFN+2R8TdQH62n1sUt37vYmrdg=:NzWfkwfUXAEhu4qk7VI4+OobFAOX1J1vq5shICwNaKc=', scram_verifier('secretpass', '0123456789abcdef') refute_equal scram_verifier('x'), scram_verifier('x') From a29189b31b92267dad851d9410ec8db7eb1fb60a Mon Sep 17 00:00:00 2001 From: nilsver Date: Wed, 18 Nov 2026 10:07:00 +0000 Subject: [PATCH 06/15] pgpass for rep: SELinux type postgresql_var_run_t --- resources/providers/config.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 54f5b7a..107f82e 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -29,6 +29,7 @@ source 'pgpass.ctmpl.erb' cookbook 'postgresql' destination pgpass + selinux_type 'postgresql_var_run_t' # postgres (postgresql_t) cannot read var_run_t: replica sends no password owner user group user mode '0600' From fb6d5ed6e1b031b4ea7a04fc6e0d436052e6ea9e Mon Sep 17 00:00:00 2001 From: nilsver Date: Wed, 18 Nov 2026 12:09:00 +0000 Subject: [PATCH 07/15] rep password: ignore an empty or placeholder pgpass value --- resources/providers/config.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 107f82e..f336129 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -9,6 +9,7 @@ routes = local_routes openbao = new_resource.openbao pgpass = '/run/rb-secrets/postgresql-rep/pgpass' + rep_pass = -> { (::File.read(pgpass).strip.split(':', 5).last.to_s rescue '').then { |p| p.empty? || p == '' ? nil : p } } dnf_package 'postgresql' do action :upgrade @@ -66,9 +67,9 @@ local_ips = `hostname -I`.split unless local_ips.include?(master_ip) # the delayed agent restart comes too late for the sync - if openbao && !::File.size?(pgpass) + if openbao && !rep_pass.call system('systemctl restart openbao-agent') - 30.times { ::File.size?(pgpass) ? break : sleep(1) } + 30.times { rep_pass.call ? break : sleep(1) } end system("rb_sync_from_master.sh #{master_ip}") end @@ -81,16 +82,15 @@ # primary only: replicas get it through WAL ruby_block 'Set the PostgreSQL password of rep' do block do - pass = ::File.read(pgpass).strip.split(':', 5).last cmd = Mixlib::ShellOut.new("#{Postgresql::Helper::PSQL} -v ON_ERROR_STOP=1", - input: "ALTER ROLE rep PASSWORD '#{scram_verifier(pass)}';\n").run_command + input: "ALTER ROLE rep PASSWORD '#{scram_verifier(rep_pass.call)}';\n").run_command # no output in the message: psql echoes the statement raise "ALTER ROLE rep failed (exit #{cmd.exitstatus})" if cmd.error? end sensitive true ignore_failure true only_if do - openbao && ::File.size?(pgpass) && + openbao && rep_pass.call && `#{Postgresql::Helper::PSQL} -c "SELECT pg_is_in_recovery() = false AND rolpassword IS NULL FROM pg_authid WHERE rolname = 'rep'" 2>/dev/null`.strip == 't' end end From b2debd010d89f6007e167b3b120104b0845258d0 Mon Sep 17 00:00:00 2001 From: nilsver Date: Wed, 18 Nov 2026 12:09:00 +0000 Subject: [PATCH 08/15] rb_ingest_vuln_cve_pg: fall back to the data bag when the password file is empty --- resources/scripts/rb_ingest_vuln_cve_pg.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/scripts/rb_ingest_vuln_cve_pg.rb b/resources/scripts/rb_ingest_vuln_cve_pg.rb index b9d26b5..6c2df09 100644 --- a/resources/scripts/rb_ingest_vuln_cve_pg.rb +++ b/resources/scripts/rb_ingest_vuln_cve_pg.rb @@ -33,7 +33,7 @@ def self.redborder_pg_conn .map { |line| line.split(/:\s+/, 2) } .to_h pass_file = '/run/rb-secrets/postgresql/db_redborder_pass' - password = File.exist?(pass_file) ? File.read(pass_file).strip : databag['pass'] + password = File.size?(pass_file) ? File.read(pass_file).strip : databag['pass'] { dbname: databag['database'], user: databag['username'], From 640e3556f7ed33481865468988c7fde82edd0a59 Mon Sep 17 00:00:00 2001 From: nilsver Date: Wed, 18 Nov 2026 13:13:00 +0000 Subject: [PATCH 09/15] hba_password_method: md5 while any role has an md5 verifier (chef-server roles connect over the sync network from non-primary nodes) --- resources/libraries/helper.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/resources/libraries/helper.rb b/resources/libraries/helper.rb index 185d3d7..05fb715 100644 --- a/resources/libraries/helper.rb +++ b/resources/libraries/helper.rb @@ -16,13 +16,11 @@ def local_routes routes end - # no chef-server roles: they connect from this node's own (trusted) addresses - NETWORK_ROLES = %w(redborder druid radius airflow rep).freeze PSQL = '/bin/psql -h 127.0.0.1 -U postgres -d postgres -XAtq'.freeze - # md5 until no network role has an md5 verifier: md5 also accepts SCRAM verifiers + # md5 until no role has an md5 verifier: md5 also accepts SCRAM verifiers def hba_password_method - out = `#{PSQL} -c "SELECT count(*) FROM pg_authid WHERE rolname IN ('#{NETWORK_ROLES.join("','")}') AND rolpassword LIKE 'md5%'" 2>/dev/null`.strip + out = `#{PSQL} -c "SELECT count(*) FROM pg_authid WHERE rolpassword LIKE 'md5%'" 2>/dev/null`.strip $?.success? && out == '0' ? 'scram-sha-256' : 'md5' end From 4bc421dcab291861ae4f3a84c9c533517ce6cb5b Mon Sep 17 00:00:00 2001 From: nilsver Date: Wed, 18 Nov 2026 13:13:00 +0000 Subject: [PATCH 10/15] pg_hba: trust only addresses this node holds (postgres VIP only on its holder) --- resources/providers/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/providers/config.rb b/resources/providers/config.rb index f336129..71f229c 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -103,7 +103,7 @@ mode '0644' cookbook 'postgresql' variables(routes: routes, user: user, openbao: openbao, method: (hba_password_method if openbao), - local_ips: [new_resource.ipaddress, vip].compact.uniq - ['127.0.0.1']) + local_ips: ([new_resource.ipaddress, vip].compact.uniq - ['127.0.0.1']) & `hostname -I`.split) notifies :reload, 'service[postgresql]' end From 7f0dcd37dc42815f9d8b00973818cdd14ded8600 Mon Sep 17 00:00:00 2001 From: nilsver Date: Wed, 18 Nov 2026 13:13:00 +0000 Subject: [PATCH 11/15] Joining replica: retry rb_sync_from_master.sh until it succeeds (marker file in the data directory), not without a rep password in pgpass --- resources/providers/config.rb | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 71f229c..63aade0 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -9,6 +9,7 @@ routes = local_routes openbao = new_resource.openbao pgpass = '/run/rb-secrets/postgresql-rep/pgpass' + sync_pending = '/var/lib/pgsql/data/rb_sync_pending' rep_pass = -> { (::File.read(pgpass).strip.split(':', 5).last.to_s rescue '').then { |p| p.empty? || p == '' ? nil : p } } dnf_package 'postgresql' do @@ -60,23 +61,26 @@ notifies :restart, 'service[postgresql]' end - ruby_block 'sync_if_not_master' do - block do - master_ip = find_master_ip - if master_ip - local_ips = `hostname -I`.split - unless local_ips.include?(master_ip) - # the delayed agent restart comes too late for the sync - if openbao && !rep_pass.call - system('systemctl restart openbao-agent') - 30.times { rep_pass.call ? break : sleep(1) } - end - system("rb_sync_from_master.sh #{master_ip}") - end - end + file sync_pending do + only_if { (m = find_master_ip) && !`hostname -I`.split.include?(m) } + end + end + + # rb_sync_from_master.sh replaces the data directory, marker included + ruby_block 'sync_if_not_master' do + block do + # the delayed agent restart comes too late for the sync + if openbao && !rep_pass.call + system('systemctl restart openbao-agent') + 30.times { rep_pass.call ? break : sleep(1) } + end + if openbao && !rep_pass.call + Chef::Log.warn('PostgreSQL sync postponed: no rep password in pgpass yet') + elsif !system("rb_sync_from_master.sh #{find_master_ip}") + Chef::Log.error('rb_sync_from_master.sh failed, retrying on the next run') end - action :run end + only_if { ::File.exist?(sync_pending) && find_master_ip } end # primary only: replicas get it through WAL From 8b48865f270d4d970a20f31dbc89677fbaaf8a03 Mon Sep 17 00:00:00 2001 From: nilsver Date: Wed, 18 Nov 2026 13:13:00 +0000 Subject: [PATCH 12/15] rep password: set after PostgreSQL starts and whenever the stored SCRAM verifier does not match pgpass --- resources/libraries/helper.rb | 11 ++++++++--- resources/providers/config.rb | 33 +++++++++++++++++---------------- test/helper_test.rb | 9 +++++++++ 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/resources/libraries/helper.rb b/resources/libraries/helper.rb index 05fb715..2bad8ce 100644 --- a/resources/libraries/helper.rb +++ b/resources/libraries/helper.rb @@ -25,12 +25,17 @@ def hba_password_method end # built here so the plain password never reaches the server log - def scram_verifier(pass, salt = OpenSSL::Random.random_bytes(16)) - salted = OpenSSL::KDF.pbkdf2_hmac(pass, salt: salt, iterations: 4096, length: 32, hash: 'sha256') + def scram_verifier(pass, salt = OpenSSL::Random.random_bytes(16), iterations = 4096) + salted = OpenSSL::KDF.pbkdf2_hmac(pass, salt: salt, iterations: iterations, length: 32, hash: 'sha256') client = OpenSSL::HMAC.digest('sha256', salted, 'Client Key') server = OpenSSL::HMAC.digest('sha256', salted, 'Server Key') b = ->(s) { [s].pack('m0') } - "SCRAM-SHA-256$4096:#{b.call(salt)}$#{b.call(OpenSSL::Digest::SHA256.digest(client))}:#{b.call(server)}" + "SCRAM-SHA-256$#{iterations}:#{b.call(salt)}$#{b.call(OpenSSL::Digest::SHA256.digest(client))}:#{b.call(server)}" + end + + def scram_matches?(verifier, pass) + m = /\ASCRAM-SHA-256\$(\d+):([^$]+)\$/.match(verifier) or return false + scram_verifier(pass, m[2].unpack1('m'), m[1].to_i) == verifier end def find_master_ip diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 63aade0..bf0f78c 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -83,22 +83,6 @@ only_if { ::File.exist?(sync_pending) && find_master_ip } end - # primary only: replicas get it through WAL - ruby_block 'Set the PostgreSQL password of rep' do - block do - cmd = Mixlib::ShellOut.new("#{Postgresql::Helper::PSQL} -v ON_ERROR_STOP=1", - input: "ALTER ROLE rep PASSWORD '#{scram_verifier(rep_pass.call)}';\n").run_command - # no output in the message: psql echoes the statement - raise "ALTER ROLE rep failed (exit #{cmd.exitstatus})" if cmd.error? - end - sensitive true - ignore_failure true - only_if do - openbao && rep_pass.call && - `#{Postgresql::Helper::PSQL} -c "SELECT pg_is_in_recovery() = false AND rolpassword IS NULL FROM pg_authid WHERE rolname = 'rep'" 2>/dev/null`.strip == 't' - end - end - vip = (data_bag_item('rBglobal', 'ipvirtual-internal-postgresql')['ip'] rescue nil) template '/var/lib/pgsql/data/pg_hba.conf' do source 'pg_hba.conf.erb' @@ -118,6 +102,23 @@ action [:start, :enable] end + # primary only: replicas get it through WAL + ruby_block 'Set the PostgreSQL password of rep' do + block do + cmd = Mixlib::ShellOut.new("#{Postgresql::Helper::PSQL} -v ON_ERROR_STOP=1", + input: "ALTER ROLE rep PASSWORD '#{scram_verifier(rep_pass.call)}';\n").run_command + # no output in the message: psql echoes the statement + raise "ALTER ROLE rep failed (exit #{cmd.exitstatus})" if cmd.error? + end + sensitive true + ignore_failure true + only_if do + next false unless openbao && rep_pass.call + out = `#{Postgresql::Helper::PSQL} -c "SELECT 'x' || coalesce(rolpassword, '') FROM pg_authid WHERE rolname = 'rep' AND NOT pg_is_in_recovery()" 2>/dev/null` + $?.success? && out.start_with?('x') && !scram_matches?(out.strip[1..], rep_pass.call) + end + end + # postgresql.conf is only written at initdb psql = 'psql -h 127.0.0.1 -U postgres -XAt' execute 'Store new PostgreSQL passwords as SCRAM-SHA-256' do diff --git a/test/helper_test.rb b/test/helper_test.rb index 1b7d8ef..209f040 100644 --- a/test/helper_test.rb +++ b/test/helper_test.rb @@ -11,4 +11,13 @@ def test_scram_verifier_matches_postgresql_format scram_verifier('secretpass', '0123456789abcdef') refute_equal scram_verifier('x'), scram_verifier('x') end + + def test_scram_matches + v = scram_verifier('secretpass') + assert scram_matches?(v, 'secretpass') + refute scram_matches?(v, 'other') + refute scram_matches?('', 'secretpass') + refute scram_matches?('md5abc', 'secretpass') + assert scram_matches?(scram_verifier('p', 'saltsaltsaltsalt', 10), 'p') + end end From bb9d90750893f49915466a5ff0bc88e07bb90d95 Mon Sep 17 00:00:00 2001 From: nilsver Date: Mon, 23 Nov 2026 11:59:22 +0000 Subject: [PATCH 13/15] OpenBao only: drop the pre-OpenBao code path and the openbao switch --- resources/providers/config.rb | 13 ++++--------- resources/resources/config.rb | 1 - resources/templates/default/pg_hba.conf.erb | 11 ----------- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/resources/providers/config.rb b/resources/providers/config.rb index bf0f78c..b320b6b 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -7,7 +7,6 @@ begin user = new_resource.user routes = local_routes - openbao = new_resource.openbao pgpass = '/run/rb-secrets/postgresql-rep/pgpass' sync_pending = '/var/lib/pgsql/data/rb_sync_pending' rep_pass = -> { (::File.read(pgpass).strip.split(':', 5).last.to_s rescue '').then { |p| p.empty? || p == '' ? nil : p } } @@ -35,13 +34,10 @@ owner user group user mode '0600' - action openbao ? :add : :remove end link '/var/lib/pgsql/.pgpass' do to pgpass - action openbao ? :create : :delete - only_if { openbao || ::File.symlink?('/var/lib/pgsql/.pgpass') } end unless ::File.exist? '/var/lib/pgsql/data/postgresql.conf' @@ -70,11 +66,11 @@ ruby_block 'sync_if_not_master' do block do # the delayed agent restart comes too late for the sync - if openbao && !rep_pass.call + unless rep_pass.call system('systemctl restart openbao-agent') 30.times { rep_pass.call ? break : sleep(1) } end - if openbao && !rep_pass.call + if !rep_pass.call Chef::Log.warn('PostgreSQL sync postponed: no rep password in pgpass yet') elsif !system("rb_sync_from_master.sh #{find_master_ip}") Chef::Log.error('rb_sync_from_master.sh failed, retrying on the next run') @@ -90,7 +86,7 @@ group user mode '0644' cookbook 'postgresql' - variables(routes: routes, user: user, openbao: openbao, method: (hba_password_method if openbao), + variables(routes: routes, method: hba_password_method, local_ips: ([new_resource.ipaddress, vip].compact.uniq - ['127.0.0.1']) & `hostname -I`.split) notifies :reload, 'service[postgresql]' end @@ -113,7 +109,7 @@ sensitive true ignore_failure true only_if do - next false unless openbao && rep_pass.call + next false unless rep_pass.call out = `#{Postgresql::Helper::PSQL} -c "SELECT 'x' || coalesce(rolpassword, '') FROM pg_authid WHERE rolname = 'rep' AND NOT pg_is_in_recovery()" 2>/dev/null` $?.success? && out.start_with?('x') && !scram_matches?(out.strip[1..], rep_pass.call) end @@ -134,7 +130,6 @@ owner 'root' group 'root' mode '0600' - action new_resource.openbao ? :add : :remove end Chef::Log.info('PostgreSQL cookbook has been processed') diff --git a/resources/resources/config.rb b/resources/resources/config.rb index 55f011c..ad68593 100644 --- a/resources/resources/config.rb +++ b/resources/resources/config.rb @@ -8,4 +8,3 @@ attribute :postgresql_port, kind_of: Integer, default: 5432 attribute :cdomain, kind_of: String, default: 'redborder.cluster' attribute :ipaddress, kind_of: String, default: '127.0.0.1' -attribute :openbao, kind_of: [TrueClass, FalseClass], default: false diff --git a/resources/templates/default/pg_hba.conf.erb b/resources/templates/default/pg_hba.conf.erb index 77d42f1..6f1face 100644 --- a/resources/templates/default/pg_hba.conf.erb +++ b/resources/templates/default/pg_hba.conf.erb @@ -1,7 +1,6 @@ #TYPE DATABASE USER CIDR-ADDRESS METHOD host all all 127.0.0.1/32 trust host all all ::1/128 trust -<% if @openbao %> # This node's own addresses: local processes only <% @local_ips.each do |ip| %> host all all <%= ip %>/32 trust @@ -10,16 +9,6 @@ host all all <%= ip %>/32 trust host all all <%= r.to_s %> <%= @method %> host replication rep <%= r.to_s %> <%= @method %> <% end %> -<% else %> -<% @routes.each do |r| %> -host all all <%= r.to_s %> trust -host all <%= @user %> <%= r.to_s %> trust -host druid druid <%= r.to_s %> trust -host redborder redborder <%= r.to_s %> trust -host replication rep <%= r.to_s %> trust -host radius radius <%= r.to_s %> trust -<% end %> -<% end %> <% if !node["redborder"]["manager"].nil? and !node["redborder"]["manager"]["database"].nil? and !node["redborder"]["manager"]["database"]["grant"].nil? %> <% node["redborder"]["manager"]["database"]["grant"].each do |x| %> <% if x["network"] != @netsync and x["network"] != "127.0.0.1/32" %> From 0f7860b3ea5c8e054e50c118b0d886bebf9c6a8f Mon Sep 17 00:00:00 2001 From: nilsver Date: Mon, 23 Nov 2026 14:58:18 +0000 Subject: [PATCH 14/15] PostgreSQL: replication password and replica sync in named helpers --- resources/libraries/helper.rb | 35 ++++++++++++++++++++++++++++++++++ resources/providers/config.rb | 36 +++++++---------------------------- 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/resources/libraries/helper.rb b/resources/libraries/helper.rb index 2bad8ce..d37acc3 100644 --- a/resources/libraries/helper.rb +++ b/resources/libraries/helper.rb @@ -38,6 +38,41 @@ def scram_matches?(verifier, pass) scram_verifier(pass, m[2].unpack1('m'), m[1].to_i) == verifier end + REP_PGPASS = '/run/rb-secrets/postgresql-rep/pgpass'.freeze + + # rep's password from the agent-rendered pgpass; nil until the agent has written it + def rep_password + pass = ::File.read(REP_PGPASS).strip.split(':', 5).last.to_s + pass.empty? || pass == '' ? nil : pass + rescue Errno::ENOENT + nil + end + + # a joining replica: wait for the agent (its delayed restart comes too late), then copy the primary + def sync_from_master(master_ip) + unless rep_password + system('systemctl restart openbao-agent') + 30.times { rep_password ? break : sleep(1) } + end + if !rep_password + Chef::Log.warn('PostgreSQL sync postponed: no rep password in pgpass yet') + elsif !system("rb_sync_from_master.sh #{master_ip}") + Chef::Log.error('rb_sync_from_master.sh failed, retrying on the next run') + end + end + + # SCRAM verifier stored on the primary for rep: nil on a replica or without a server + def rep_verifier_on_primary + out = `#{PSQL} -c "SELECT 'x' || coalesce(rolpassword, '') FROM pg_authid WHERE rolname = 'rep' AND NOT pg_is_in_recovery()" 2>/dev/null` + $?.success? && out.start_with?('x') ? out.strip[1..] : nil + end + + def set_rep_password(pass) + cmd = Mixlib::ShellOut.new("#{PSQL} -v ON_ERROR_STOP=1", input: "ALTER ROLE rep PASSWORD '#{scram_verifier(pass)}';\n").run_command + # no output in the message: psql echoes the statement + raise "ALTER ROLE rep failed (exit #{cmd.exitstatus})" if cmd.error? + end + def find_master_ip cluster_info = node.dig('redborder', 'cluster_info') postgresql_managers = node.dig('redborder', 'managers_per_services', 'postgresql') diff --git a/resources/providers/config.rb b/resources/providers/config.rb index b320b6b..c90b1b4 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -7,9 +7,7 @@ begin user = new_resource.user routes = local_routes - pgpass = '/run/rb-secrets/postgresql-rep/pgpass' sync_pending = '/var/lib/pgsql/data/rb_sync_pending' - rep_pass = -> { (::File.read(pgpass).strip.split(':', 5).last.to_s rescue '').then { |p| p.empty? || p == '' ? nil : p } } dnf_package 'postgresql' do action :upgrade @@ -29,7 +27,7 @@ openbao_secret_file 'postgresql-rep' do source 'pgpass.ctmpl.erb' cookbook 'postgresql' - destination pgpass + destination Postgresql::Helper::REP_PGPASS selinux_type 'postgresql_var_run_t' # postgres (postgresql_t) cannot read var_run_t: replica sends no password owner user group user @@ -37,7 +35,7 @@ end link '/var/lib/pgsql/.pgpass' do - to pgpass + to Postgresql::Helper::REP_PGPASS end unless ::File.exist? '/var/lib/pgsql/data/postgresql.conf' @@ -64,18 +62,7 @@ # rb_sync_from_master.sh replaces the data directory, marker included ruby_block 'sync_if_not_master' do - block do - # the delayed agent restart comes too late for the sync - unless rep_pass.call - system('systemctl restart openbao-agent') - 30.times { rep_pass.call ? break : sleep(1) } - end - if !rep_pass.call - Chef::Log.warn('PostgreSQL sync postponed: no rep password in pgpass yet') - elsif !system("rb_sync_from_master.sh #{find_master_ip}") - Chef::Log.error('rb_sync_from_master.sh failed, retrying on the next run') - end - end + block { sync_from_master(find_master_ip) } only_if { ::File.exist?(sync_pending) && find_master_ip } end @@ -100,25 +87,16 @@ # primary only: replicas get it through WAL ruby_block 'Set the PostgreSQL password of rep' do - block do - cmd = Mixlib::ShellOut.new("#{Postgresql::Helper::PSQL} -v ON_ERROR_STOP=1", - input: "ALTER ROLE rep PASSWORD '#{scram_verifier(rep_pass.call)}';\n").run_command - # no output in the message: psql echoes the statement - raise "ALTER ROLE rep failed (exit #{cmd.exitstatus})" if cmd.error? - end + block { set_rep_password(rep_password) } sensitive true ignore_failure true - only_if do - next false unless rep_pass.call - out = `#{Postgresql::Helper::PSQL} -c "SELECT 'x' || coalesce(rolpassword, '') FROM pg_authid WHERE rolname = 'rep' AND NOT pg_is_in_recovery()" 2>/dev/null` - $?.success? && out.start_with?('x') && !scram_matches?(out.strip[1..], rep_pass.call) - end + only_if { rep_password && (v = rep_verifier_on_primary) && !scram_matches?(v, rep_password) } end # postgresql.conf is only written at initdb - psql = 'psql -h 127.0.0.1 -U postgres -XAt' + psql = Postgresql::Helper::PSQL execute 'Store new PostgreSQL passwords as SCRAM-SHA-256' do - command "#{psql} -c \"ALTER SYSTEM SET password_encryption = 'scram-sha-256'\" && #{psql} -c 'SELECT pg_reload_conf()'" + command "#{psql} -c \"ALTER SYSTEM SET password_encryption = 'scram-sha-256'\" -c 'SELECT pg_reload_conf()'" only_if "#{psql} -c 'SELECT 1'" not_if "#{psql} -c 'SHOW password_encryption' | grep -qx scram-sha-256" end From 59e2d612e1fef6bc9731e07e5a2e4ed7027c0ad9 Mon Sep 17 00:00:00 2001 From: nilsver Date: Tue, 24 Nov 2026 21:11:19 +0000 Subject: [PATCH 15/15] pg_hba: trust this node's own IPv4 addresses from hostname -I (the bootstrap solo run passes no ipaddress) --- resources/providers/config.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/resources/providers/config.rb b/resources/providers/config.rb index c90b1b4..1e5f6db 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -66,7 +66,6 @@ only_if { ::File.exist?(sync_pending) && find_master_ip } end - vip = (data_bag_item('rBglobal', 'ipvirtual-internal-postgresql')['ip'] rescue nil) template '/var/lib/pgsql/data/pg_hba.conf' do source 'pg_hba.conf.erb' owner user @@ -74,7 +73,7 @@ mode '0644' cookbook 'postgresql' variables(routes: routes, method: hba_password_method, - local_ips: ([new_resource.ipaddress, vip].compact.uniq - ['127.0.0.1']) & `hostname -I`.split) + local_ips: `hostname -I`.split.select { |ip| ip.include?('.') } - ['127.0.0.1']) notifies :reload, 'service[postgresql]' end