165 points · by proboscis · 7y ago · 77 comments
Then I looked at the PostgreSQL statement, which said that the report claimed that users with a read-access role could do the su things, and they said that the claim was not true.
And then I looked at the actual report, which stated that you have to have the read-access role, and the execute-access role (or su).
So, what it seems like is that both parties didn't represent the actual situation well, but the root (ha) issue was that it was reported as "IF YOU HAVE READ ACCESS (and execute access) THEN YOU CAN EXECUTE ARBITRARY CODE!!11!!!"
Raymond Chen on "security vulnerabilities" that depend on already having superuser status.
https://devblogs.microsoft.com/oldnewthing/20121207-00/?p=58...
Looks like Microsoft messed up the line breaks on switching to a new blog platform.
One could argue Microsoft has been messing up line breaks since 1981.
Which is also currently a banner at postgresql.org titled “4th April 2019: CVE-2019-9193: Not a Security Vulnerability”
It was a bad report. To be fair, it's also a bad feature. But bad features working as intended shouldn't be "vulnerabilities".
COPY TO/FROM PROGRAM has been valuable for our data warehousing operations.
The community consensus was the MS should make this thing disabled by default, and they did. Postgres should too.
The security researchers did not seem too concerned with the feedback they got from the community prior to releasing this CVE.
Seriously though, security research is starting to drift into bizarro land, security contacts at companies are inundated with port-scans asking for bug bounties because there's an open port and now people are registering CVEs on expected and documented behavior.
Remember that these people are essentially trying to earn a living by finding vulnerabilities, so it's no surprise that they'll try to spin anything as one, regardless of any other considerations.
I've used the term "security vultures" before in reference to such things. It's unfortunate that a lot of companies misunderstand or obey their requests, and in the process useful features are destroyed and software becomes more user-hostile.
[0] https://devblogs.microsoft.com/oldnewthing/author/oldnewthin...
Yeah that's just not done. Dutch: kinderen die vragen worden overgeslagen (it rhymes nicely) - kids that ask will be skipped/passed. I.e., if you ask for a reward (or sweets, in a kids' case), you certainly won't get any.
If you reward people that report silly stuff and then ask for money, that would be bizarro land indeed.
That's possibly an improvement Postgress can do to avoid easy pivoting. Its what a less defensive security reply would include, because if hackers use it to pivot it might not look good down the road.
But from a pure argument standpoint Postgres is correct, it's more of a defense in depth strategy.
If you take that to its logical conclusion you end up with completely unusable, user-hostile software that becomes nearly useless.
The fact that everything can be abused, should not be a reason to ban everything either.
Someone above mentions that the feature/config is actually off by default!
""" Btw, the xp_cmdshell thing the author references several times? It can be enabled via tsql if you have a privileged account.
https://docs.microsoft.com/en-us/sql/database-engine/configu...
and it allows to execute shell code (as a specified user) even when not a sysadmin: https://docs.microsoft.com/en-us/sql/relational-databases/sy... """
so no MS didn't really "lock down" the feature.
Please stop repeating this FUD.
Postgres is just a process that happens to do a lot of I/O. It's no different than any other Unix process: it can spawn children, it can dynamically load libraries on request. It protects these powerful tools with permissions, which is the sane and correct approach taken by many, many other languages and frameworks, all just unix processes, all just trying to get shit done.
Please explain what's FUD about that?
The postgres equivalent this post is about a feature that's only granted to superusers (or in recent version user that have explicitly been granted rights that are equivalent to superuser and documented as such - namely the right to directly write into any database file...).
For comparison, in CockroachDB (disclosure: I'm a co-founder of Cockroach Labs), we don't have any features that let you execute server programs, but we do have something analogous to `pg_{read,write}_server_files` via the BACKUP, RESTORE, and IMPORT commands. In order to use these commands with a target on the server's filesystem, though, the database `admin` role isn't enough. The server also needs to be started with the `--external-io-dir` flag (and file operations will be limited to that directory). This gives an extra layer of opt-in before filesystem operations are allowed.
If you’re talking about a more broad “COPY TO/FROM” is evil, then I think this is a far broader discussion, and I encourage you to get a better understanding of some of the use cases.
It's a command, and it's closer to other commands that do similar things, like loading a plugin (i.e. a ".so" file).
Also those schmucks who like data to be loaded way way faster.
I prefer using COPY ... STDIN/STDOUT. AFAICT, you get the same bulk table access performance. But, the external file access is via the client, separating DB rights and filesystem rights. When appropriate, you can also SSH to the server and invoke psql as a regular user there, manipulating files under that user's control on the server filesystem.
The psql command also provides built-in \COPY command to make it easy to combine several such commands into one transaction in a SQL script. It looks a little like the SQL COPY command, but accesses files on the client side and executes equivalent COPY ... STDIN/STDOUT statements on the server.
In Python, you can use the copy_expert() method with psycopg2 connections to access the COPY ... STDIN/STDOUT feature for similar bulk ETL. However, Python will become the performance bottleneck if you try to do any real row-level processing rather than just relaying byte buffers to/from the filesystem.
COPY TO/FROM PROGRAM is useful e.g. when you already have the data locally on the server (same filesystem, ...).
COPY FROM STDIN/STDOUT are useful when the data are on some other system (say, on a different server, etc).
Of course, you might write a script that reads the local data and loads it through a regular client, i.e. something like COPY t FROM PROGRAM 'gunzip -c /path/to/compressed/data.gz';
might be rewritten like gunzip -c /path/to/compressed/data.gz | psql db -c 'copy t from stdin';
but well, that requires some access to the server and ability to execute commands on it (although not as a postgres superuser).Ultimately it's a tradeoff - don't trust your users? Don't give them superuser access, don't grant them the role. It's possible to restrict that in other ways (e.g. security-definer functions + extra validations).
Anyone with privileges to run docker image is basically root on your host.