I took a look at the dbaccess directory in https://github.com/lsst-dm/gen3_shared_repo_admin and attempted to get my head wrapped around how this would actually look in the database. On the surface, it seems like this should work logically. I'm not familiar with the requirements but none of the policies look very complicated and the expressions used to determine whether a row is visible or not look pretty straightforward depending on what some of the snippets stuff returns.
My biggest concern as is usually the case for me on this project, is performance. You have some policies using regular expressions which will likely render any indexing useless. That assumes the optimizer chooses to evaluate the expression at the proper time in the execution plan. Beyond that, a quick google for "postgresql row based security performance" shows policy evaluation in during SQL execution to be a significant problem in general. It looks like things continue to get better with each version but comments like "To summarize, RLS policies in combination with subqueries are unfortunately not each other friends performance-wise" don't bode well.
Each column is going to have any number of policies that will all have to be accounted for. That's on top of some fairly complicated, nested, dynamically generated SQL which has already presented some significant performance problems.
Performance will likely be fine when data volumes on tables with policies are low but I'm very skeptical about this scaling well. Unfortunately, I don't really have any concrete suggestions. You mentioned that this is to prevent accidental misuse and not intentional misuse. If that's the case, would it make more sense to move a lot of this into the python code since it's the only approved way to access any repo? I think that would help the optimizer and it would definitely help with troubleshooting when performance tanks.
Sorry to be so pessimistic but this is asking the database to get a lot right.
Christopher Stephens [X], a question for you before I dive too deeply into this: I know we grant users permission to create tables in our shared repos (and we have to). But what does the ownership of those user-created tables look like afterwards? Is there a way we could set things up so users can still create those tables, but their ownership reverts to the same admin role that presumably owns the static tables after the dynamic tables are created?