Re: Proposal: template-ify (binary) extensions

Поиск
Список
Период
Сортировка
От Markus Wanner
Тема Re: Proposal: template-ify (binary) extensions
Дата
Msg-id 51EC4503.4070702@bluegap.ch
обсуждение исходный текст
Ответ на Re: Proposal: template-ify (binary) extensions  (Dimitri Fontaine <dimitri@2ndQuadrant.fr>)
Ответы Re: Proposal: template-ify (binary) extensions  (Hannu Krosing <hannu@2ndQuadrant.com>)
Re: Proposal: template-ify (binary) extensions  (Dimitri Fontaine <dimitri@2ndQuadrant.fr>)
Список pgsql-hackers
Salut Dimitri,

On 07/20/2013 01:23 AM, Dimitri Fontaine wrote:
> Markus Wanner <markus@bluegap.ch> writes:
>>>   - per-installation (not even per-cluster) DSO availability
>>>
>>>     If you install PostGIS 1.5 on a system, then it's just impossible to
>>>     bring another cluster (of the same PostgreSQL major version), let
>> On Debian, that should be well possible. Certainly installing Postgres
>> 9.1 w/ postgis-1.5 in parallel to Postgres 9.2 w/ postgis-2.0 is. I
>> designed it to be.
>>
>> I think I'm misunderstanding the problem statement, here.
> 
> (of the same PostgreSQL major version)

Not sure what the issue is, here, but I agree that should be possible.

>> Can CREATE EXTENSION check if the standbys have the extension installed?
>> And refuse creation, if they don't?
> 
> No, because we don't register standbies so we don't know who they are,
> and also because some things that we see connected and using the
> replication protocol could well be pg_basebackup or pg_receivexlog.

Can the standby check? In any case, these seem to be problems we can
solve without affecting security.

> Also, it's possible that the standby is only there for High Availability
> purposes and runs no user query.

Requiring the sysadmin to install the extensions there, too, seems
justified to me. Sounds like good advice, anyways.

>> I'm sure you are aware that even without this clear separation of roles,
>> the guarantee means we provide an additional level of security against
>> attackers.
> 
> Given lo_import() to upload a file from the client to the server then
> LOAD with the absolute path where the file ended up imported (or any
> untrusted PL really), this argument carries no sensible weight in my
> opinion.

lo_import() won't write a file for LOAD to load. An untrusted PL (or any
other extension allowing the superuser to do that) is currently required
to do that.

Or to put it another way: Trusted PLs exist for a good reason. And some
people just value security a lot and want that separation of roles.

>> None the less, the "safe by default" has served us well, I think.
> 
> That's true. We need to consider carefully the proposal at hand though.
> 
> It's all about allowing the backend to automatically load a file that it
> finds within its own $PGDATA so that we can have per-cluster and
> per-database modules (DSO files).

As someone mentioned previously, $PGDATA may well be mounted noexec, so
that seems to be a bad choice.

> The only difference with before is the location where the file is read
> from, and the main security danger comes from the fact that we used to
> only consider root-writable places and now propose to consider postgres
> bootstrap user writable places.

FWIW, I only proposed to let postgres check write permissions on
libraries it loads. IIUC we don't currently do that, yet. And Postgres
happily loads a world-writable library, ATM.

> Having the modules in different places in the system when it's a
> template and when it's instanciated allows us to solve a problem I
> forgot to list:
> 
>   - upgrading an extension at the OS level
> 
>     Once you've done that, any new backend will load the newer module
>     (DSO file), so you have to be real quick if installing an hot fix in
>     production and the SQL definition must be changed to match the new
>     module version…

I agree, that's a problem.

Alternatively, we could solve that problem the other way around: Rather
than template-ify the DSO, we could instead turn the objects created by
the SQL scripts into something that's more linked to the script.
Something that would reload as soon as the file on disk changes.

(Note how this would make out-of-line extensions a lot closer to the
in-line variant your recent patch adds? With the dependency between
"template" and "instantiation"?)

> With the ability to "instanciate" the module in a per-cluster
> per-database directory within $PGDATA the new version of the DSO module
> would only put in place and loaded at ALTER EXTENSION UPDATE time.
> 
> I'm still ok with allowing to fix those problems only when a security
> option that defaults to 'false' has been switched to 'true', by the way,
> so that it's an opt-in,

Okay, good.

For the issues you raised, I'd clearly prefer fixes that maintain
current security standards, though.

> but I will admit having a hard time swallowing
> the threat model we're talking about…

An attacker having access to a libpq connection with superuser rights
cannot currently run arbitrary native code. He can try a DOS by
exhausting system resources, but that's pretty far from being
invisible. Or he can delete valuable data. Maybe other nasty things. But
he should not be able to gain root access and remove its traces.

Dropping this barrier by installing an untrusted PL (or equally insecure
extensions), an attacker with superuser rights can trivially gain
root.

Of course, an attacker shouldn't gain superuser rights in the first
place. But if he did, you better stop him right there with yet another
fence.

>> It's extensions that undermine the guarantee, at the moment. But yeah,
>> it depends a lot on what kind of "relaxed behavior" you have in mind.
> 
> The ability to load a module from another place than the current
> Dynamic_library_path is what we're talking about here, and IIUC Robert
> mentioned that maybe it could be down to an extension to allow for
> changing the behavior. I didn't look at that in details but I would be
> surprised to be able to tweak that without having to patch the backend.

Well, an extension can certainly perform something akin to pg_dlopen().
And thus load pretty much any code it wants. However, I don't think an
extension can hook into CREATE EXTENSION, yet.

>> If the sysadmin wants to disallow arbitrary execution of native code to
>> postgres (the process), any kind of embedded compiler likely is equally
>> unwelcome.
> 
> You already mentioned untrusted PL languages, and I don't see any
> difference in between offering PL/pythonu and PL/C on security grounds,
> really.

I agree. However, this also means that any kind of solution it offers is
not a good one for the security conscious sysadmin.

Regards

Markus Wanner



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Josh Berkus
Дата:
Сообщение: Re: REINDEX checking of index constraints
Следующее
От: Josh Berkus
Дата:
Сообщение: Re: REINDEX checking of index constraints