Skip to content
This repository has been archived by the owner on Mar 4, 2019. It is now read-only.

Wrapping connections, e.g. for Row Level Security? #291

Open
benjie opened this issue Jul 24, 2016 · 0 comments
Open

Wrapping connections, e.g. for Row Level Security? #291

benjie opened this issue Jul 24, 2016 · 0 comments

Comments

@benjie
Copy link
Contributor

benjie commented Jul 24, 2016

Hey, great project! One of the recent awesome features Postgres has added in 9.5 is Row Level Security (RLS); I really want to use that in combination with the simple update/insert/etc features in massive (as well as the file query features). However, for this to be really useful you really need to be able to insert some per-query authentication into the database after massive has booted up (we don't want to do all those table and file scans again!); e.g. we want to wrap every "pg.connect" with something like:

begin;
set local role users;
set local claims.user_id to 7;

-- Do the intended query here

commit;

I was hoping to come up with a proof of concept to demostrate RLS working with massive; but alas due to how Entities work (keeping a reference via this.db = args.db) I couldn't do it the way I was planning. Nonetheless I've shared my work in progress to help you see what I'm getting at here:

benjie@336977b

I've tried to implement it in a generic way such that the wrapping function isn't tied specifically to RLS, but could be used for other features too - anything that needs to change on a per-user/per-request/per-query basis but doesn't want to incur massive's startup cost. Intention is to do something like:

const superuserDb = massive.connectSync(URL);

const app = express();

app.use((req, res, next) => {
  req.db = superuserDb.withConnectionWrapper(connectionWrapperForUserId(req.session.user_id));
  next();
});

app.use((req, res, next) => {
  req.db.posts.find(7, ...);
});

What are your thoughts on implementing something like this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant