From: | KaiGai Kohei <kaigai(at)ak(dot)jp(dot)nec(dot)com> |
---|---|
To: | Robert Haas <robertmhaas(at)gmail(dot)com> |
Cc: | KaiGai Kohei <kaigai(at)kaigai(dot)gr(dot)jp>, PgSQL-Hackers <pgsql-hackers(at)postgresql(dot)org>, Joshua Brindle <method(at)manicmethod(dot)com>, "David P(dot) Quigley" <dpquigl(at)tycho(dot)nsa(dot)gov> |
Subject: | Re: security hook on table creation |
Date: | 2010-10-05 09:01:35 |
Message-ID: | 4CAAE96F.4010108@ak.jp.nec.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
(2010/10/01 11:23), Robert Haas wrote:
> On Sep 30, 2010, at 9:01 PM, KaiGai Kohei<kaigai(at)ak(dot)jp(dot)nec(dot)com> wrote:
>> (2010/10/01 3:09), Robert Haas wrote:
>>> 2010/9/29 KaiGai Kohei<kaigai(at)ak(dot)jp(dot)nec(dot)com>:
>>>> In addition, I want to give these entrypoints its name which
>>>> represents an appropriate purpose of the hook, rather than
>>>> a uniformed one.
>>>
>>> It sounds like you're proposing to create a vast number of hooks
>>> rather than just one. If we have ~20 object types in the system,
>>> that's 40 hooks just for create and drop, and then many more to handle
>>> comment, alter (perhaps in various flavors), etc. I'm pretty
>>> unexcited about that. The main hook function can always dispatch
>>> internally if it so desires, but I don't see any benefit to forcing
>>> people to write the code that way.
>>>
>> What I proposed is to create just one hook and wrapper functions
>> with appropriate name; that calls the hook with appropriate parameters,
>> such as SearchSysCache1, 2, 3 and 4.
>
> Seems like you'd end up creating a lot of macros that were only used once.
>
I began to revise the security hooks, but I could find a few cases that does
not work with the approach of post-creation security hooks.
If we try to fix up the core PG routine to become suitable for the post-creation
security hooks, it shall need to put more CommandCounterIncrement() on various
places, so it made me doubtful whether this approach gives really minimum impact
to the core PG routine, or not.
See the following analysis:
Now we support to assign security label on the seven object classes enumerated
at ExecSecLabelStmt().
Some of object classes have CommandCounterIncrement() just after the routine
to create a new object. For example, DefineRelation() calls it just after the
heap_create_with_catalog(), so the new relation entry is visible for plugin
modules using SearchSysCache(), as long as we put the post-creation security
hook aftere the CommandCounterIncrement().
However, we also have a few headache cases.
DefineType() creates a new type object and its array type, but it does not
call CommandCounterIncrement() by the end of this function, so the new type
entries are not visible from the plugin modules, even if we put a security
hook at tail of the DefineType().
DefineFunction() also has same matter. It create a new procedure object,
but it also does not call CommandCounterIncrement() by the end of this
function, except for the case when ProcedureCreate() invokes language
validator function.
During the discussion, we talked about which is more preferable design
(A) having both of prep/post creation hooks, or (B) having only post
creation hook. My original proposition is similar to the idea (A), but
we could not find out a good reason to justify (A) rather than simple
(B) a week ago.
However, again, it seems to me the idea (A) becomes better, because it
enables to avoid random injection of CommandCounterIncrement() in the
future.
So, I'd like to reconsider the idea with two hooks on creation time.
The issue of prep creation hook was that it needs per object class
definitions because we cannot pull-out information from SysCache
before the new database object being visible.
But it does not mean we eventually need (# of object classes) x (# of
access types) hooks.
E.g, it may be possible to design creation of relation as follows:
DefineRelation(...)
{
/* DAC permission checks here */
:
/* MAC permission checks; it returns its private data */
opaque = check_relation_create(...<relation parameters>...);
:
/* insertion into pg_class catalog */
relationId = heap_create_with_catalog(...);
:
/* assign security labels on the new object */
InvokeObjectAccessHook(OBJECT_TABLE, OAT_POST_CREATE,
relationId, 0, opaque);
}
In this design, we can share the post-creation hook with any other object
classes, so all we need to provide for each object classes are just prep
creation hooks. It does not seem to me explosion of security hooks.
Could you give me your opinion to handle these problematic code paths?
Thanks,
--
KaiGai Kohei <kaigai(at)ak(dot)jp(dot)nec(dot)com>
From | Date | Subject | |
---|---|---|---|
Next Message | Itagaki Takahiro | 2010-10-05 09:01:45 | Re: leaky views, yet again |
Previous Message | Marko Tiikkaja | 2010-10-05 08:55:37 | Re: top-level DML under CTEs |