Easier Postgres User Management

SergeantBiggs

linuxdatabasesqlsystem administrationsecurity

293 Words

2021-12-31 12:52 +0000


I have a Postgres instance that runs on my main server, and provides database services to all of my apps. Like everything, this has grown over the years. So I thought be time for some cleaning.

When I configured the services, I did it inconsistently because I didn’t really understand the different authentication options. Most of the time I would just create a username and password, contact the server over TCP/IP, and call it a day. This meant tracking users + passwords in external password managers, and writing long passwords in configuration files. I knew about postgresql sockets but never really used them. That is, until I discovered peer authentication. This allows postgres to authenticate users locally. You can then specify which users have access to which databases in pga_hba.conf. This allows you to easily add new users and give them permissions for databases, without having to fuck around with passwords. You can configure it by adding the specific users and databases that you want to activate peer authentication for.

For example: if you configure a gitlab instance, and want to give the gitlab user access to the gitlab database, add the following to pg_hba.conf:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             postgres                                peer

# All other users that can access the socket
local   foo             foo                                     peer
local   bar             bar                                     peer
local   gitlab          gitlab                                  peer

This provides an easy way to ensure only specific users are allowed to access specific databases. It has the added benefit of being faster and more reliable, since it uses a Unix socket. I also removed the network authentication for localhost, and disabled listening on a network socket, since that is no longer needed.

/var/lib/postgres/data/postgresql.conf

listen_addresses = ''

Articles from blogs I read

Anubis works

That meme is not an understatement, Anubis has been deployed by the United Nations. For your amusement, here is how the inner monologue of me finding out about this went: AoiWhat. You can't be serious, can you?CadeyIt's real.…

via Xe Iaso's blog April 12, 2025

A Firefox addon for putting prices into perspective

I had a fun idea for a small project this weekend, and so I quickly put it together over the couple of days. The result is Price Perspective. Humor me: have you ever bought something, considered the price, and wondered how that price would look to someone el…

via Drew DeVault's blog April 4, 2025

I don't really like OIDC

I will look into this single sign-on protocol and figure out why it is so darn complicated.

via Ξ January 7, 2025

Announcing systemd v257

Last week we released systemd v257 into the wild. In the weeks leading up to this release (and the week after) I have posted a series of serieses of posts to Mastodon about key new features in this release, under the #systemd257 hash tag. In case you aren'…

via Pid Eins December 17, 2024

Generated by openring