osm2pgsql-dev / osm2pgsql

OpenStreetMap data to PostgreSQL converter
https://osm2pgsql.org
GNU General Public License v2.0
1.5k stars 474 forks source link

Document security practices for multi-user systems #831

Closed pnorman closed 4 years ago

pnorman commented 6 years ago

The normal osm2pgsql instructions (createdb && psql -c 'create extension postgis; && osm2pgsql) are designed for a single-user accessing a database and everyone who has access to that user is trusted. In multi-user environments and production, it's a good idea to restrict access to the minimum necessary.

The doc should cover

pnorman commented 6 years ago

I've been evaluating osm2pgsql for CVE-2018-1058-like search_path privilege escalation attacks. It's doing the following function call without a schema qualification

For an attack to work you need

The only scenarios I can see are

In practice, in every scenario I've seen, osm2pgsql imports run with the highest non-superuser level of access, because they have to DROP and CREATE tables.

mmd-osm commented 6 years ago

The official Postgresql wiki page describes a number of safeguarding measures to protect a PostgreSQL installation from CVE-2018-1058.

Did you also evaluate if those recommendations are safe to apply in the context of osm2pgsql, or whether they would cause some issues? Would you recommend applying those recommendations?

pnorman commented 6 years ago

Did you also evaluate if those recommendations are safe to apply in the context of osm2pgsql, or whether they would cause some issues?

It's often assumed that osm2pgsql will be run on the public schema, and that that's where PostGIS will be. Any of the techniques will work, but REVOKE CREATE ON SCHEMA public FROM PUBLIC; would be my preference, but then you also need to adjust the search_path to put the osm2pgsql tables somewhere else. PostGIS could remain in public.

From a practical consideration, people running osm2pgsql and their renderer as superusers is a far bigger security hole than the search_path privilege escalation attacks. I see the former done all the time, and once you have superuser access, there's no more escalation to be done with database permissions.

joto commented 4 years ago

I have written up a chapter security considerations in the new manual. I believe this is enough for us here and I can't really give much more information there without writing a "postgresql security handbook" or confusing users more than helping.