Ran into this while setting up a Kali dev environment to test a PR.
Repro
cd metasploit-framework
bundle exec ruby msfdb delete
bundle exec ruby msfdb init --debug
Every role creation step fails with:
psql: error: connection to server on socket "..." failed:
FATAL: role "postgres" does not exist
Eventually msfdb init crashes with:
PG::ConnectionBad: connection to server at "127.0.0.1", port 5433 failed:
FATAL: role "msf" does not exist
from lib/msfdb_helpers/pg_ctlcluster.rb:119:in `create_db_users'
After digging into it, it looks like msfdb creates the cluster with:
pg_createcluster ... --user=$(whoami)
which means the bootstrap superuser becomes the current Linux user rather than postgres.
Later, run_psql in lib/msfdb_helpers/db_interface.rb assumes a postgres role exists and hardcodes:
As a result, all of the role creation and alter-role commands in create_db_users fail, but those failures aren't surfaced immediately. The first visible exception is the later PG.connect(... user: msf_db_user ...) call after the expected roles were never created.
This isn't PostgreSQL 18 specific — it's the combination of pg_createcluster --user=$(whoami) and the hardcoded psql -U postgres in run_psql, not a recent PostgreSQL change.
This may be related to #19299. There's also an open proposal around msfdb and postgresql-common that touches similar code paths.
Workaround
Creating a postgres role manually allows msfdb init to complete:
psql -U <your-username> -h /tmp -p <port> -d postgres \
-c "CREATE ROLE postgres SUPERUSER LOGIN;"
Possible fixes:
- Have
run_psql connect as the same user passed to pg_createcluster instead of hardcoding postgres
- Or explicitly create the cluster with a
postgres bootstrap user so the existing assumptions remain valid
Environment: Kali Linux (rolling), PostgreSQL 18, Ruby 3.3.x.
Happy to test a fix if useful.
Ran into this while setting up a Kali dev environment to test a PR.
Repro
Every role creation step fails with:
Eventually
msfdb initcrashes with:After digging into it, it looks like
msfdbcreates the cluster with:pg_createcluster ... --user=$(whoami)which means the bootstrap superuser becomes the current Linux user rather than
postgres.Later,
run_psqlinlib/msfdb_helpers/db_interface.rbassumes apostgresrole exists and hardcodes:As a result, all of the role creation and alter-role commands in
create_db_usersfail, but those failures aren't surfaced immediately. The first visible exception is the laterPG.connect(... user: msf_db_user ...)call after the expected roles were never created.This isn't PostgreSQL 18 specific — it's the combination of
pg_createcluster --user=$(whoami)and the hardcodedpsql -U postgresinrun_psql, not a recent PostgreSQL change.This may be related to #19299. There's also an open proposal around
msfdbandpostgresql-commonthat touches similar code paths.Workaround
Creating a
postgresrole manually allowsmsfdb initto complete:Possible fixes:
run_psqlconnect as the same user passed topg_createclusterinstead of hardcodingpostgrespostgresbootstrap user so the existing assumptions remain validEnvironment: Kali Linux (rolling), PostgreSQL 18, Ruby 3.3.x.
Happy to test a fix if useful.