Designing the most performant row-level security schema in Postgres (2018)
medium.com
medium.com
I keep seeing systems too tied to partocular backend web frameworks, which makes it difficult to have a heterogenous backend. Further, unclear how to deal with say app caches in modern frontend and service systems, or avoiding getting too tied to an authentication system / API gateway / some VC company (eg, auth0, replicated) / non-OSS. Keeping a clean layer here has gotten quite confusing, afaict!
I don't think the current multi-user functionality of databases is terribly useful as most applications only use one database user to connect to the database, but then have to emulate record ownership on an application level (i.e. lots of website accounts) which tends to get pushed down into the SQL itself for performance reasons.
Now we move into big data, data ownership and user permission grants on that data, it would make sense to have a better concept of records having an owner (in the GDPR sense of the word) and it would be convenient if this could be abstracted somewhat into SQL itself instead of complicating all queries.
So my q is modern arch for the app code services -- like, authenticate via JWT and pass that around, maybe even through internal requests, but where does the authorization logic go? A middle tier REST microservice that does all SQL queries, like a graphql layer? (And then DIY RBAC wrappers over the graphql?)
Many datastores support RBAC natively, so each of your stores could define access controls exactly internally which seems like a great separation of concerns to me. Personally, I've been digging into row-level security in Neo4j and Elasticsearch, both of which may be on their way to stealing my heart from Postgres but haven't quite yet.
``` const { accountId } = decodeJwt(req.headers.authorization) SELECT * FROM items WHERE account_id = :accountId ```
I get that it's about the exact opposite of what the article is trying to do but it looks a whole lot easier to maintain.
At some level of complexity SQL gets hard to migrate, upgrade, switch vendors and even cloud providers
Use "efficient" or simply "fast" if that's what you mean.