Skip to content

msfdb init fails on Kali — hardcoded psql -U postgres but that role never gets created #21590

Description

@4ravind-b

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:

psql -U postgres ...

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions