Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 2 min read

Your Database Users Still Have MD5 Passwords and PostgreSQL 18 Has Started Warning

The database started life in 2018. Then came an upgrade. Then another. Then another. Each one carried every role across, exactly as it was. Including how its password was stored. Then the team moved to PostgreSQL 1

The database
started life in 2018.

Then came
an upgrade.

Then another.

Then another.

Each one carried
every role across,
exactly as it was.

Including
how its password was stored.

Then the team
moved to PostgreSQL 18.

The deploy script
reset the app's password,
as it always did.

And a new warning appeared
in the logs:

MD5 passwords are deprecated.

Here is the mechanism.

PostgreSQL 18
deprecated MD5 passwords.

The release notes say
support will be removed
in a future major version.

Setting one
now raises a warning.

You can switch the warning off
with md5_password_warnings.

You cannot switch off
the version
that will refuse them.

Why go?

An MD5 password
is stored as a hash
of the password and the username.

That hash
is enough to log in.

If someone copies it
from a backup,
they do not need to crack it.

They can use it.

SCRAM-SHA-256
fixes that,
and has been the default
for new passwords
since PostgreSQL 14.

So why are you still on MD5?

Because a default
only applies
to passwords set after it.

pg_upgrade
copies the stored hashes,
not the passwords.

A role created in 2018
still carries an MD5 hash today,
unless somebody set its password again.

And a postgresql.conf
copied forward from 2018
may still say
password_encryption = md5,
so even new passwords
are stored the old way.

Find out now:

SELECT rolname
FROM pg_authid
WHERE rolpassword LIKE 'md5%';

Every row
is a migration waiting.

Check the service accounts first.

Those are the passwords
nobody has typed in years,
set once by a person
who has since left,
and read by an application
that will simply stop connecting
the day support is gone.

The path:

Make sure every client
can speak SCRAM.

Modern drivers can.

Very old ones,
on forgotten servers,
cannot.

Check them first.

Confirm password_encryption
is scram-sha-256.

Set each password again.

Rotate them,
since you are touching them anyway.

Then change pg_hba.conf
from md5
to scram-sha-256,
so nothing can fall back.

None of this
is urgent today.

That is the point.

Do it while
a warning is all you get.

– Serguey Asael Shinder

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.