Connecting to a database with logged in user credentials

59 views
Skip to first unread message

konrad....@uni.lodz.pl

unread,
Feb 23, 2017, 6:59:21 AM2/23/17
to Django users
Is it possible to create database ENGINE that would be able to pass credentials of logged in user to DatabaseWrapper.connect() method?

We want to build rest api with Django that would base on a legacy Postgresql database. We've got permissions to objects ensured on database level, so a user logged in to database cannot see/modify anything he should not to.
We have a very strong need not to destroy this mechanism. This means that every application user is at the same time a database user.
After starting the project, we've realised that db routing is limited to the set of db connections that are statically described in django settings.
Is there a way to create database connection dynamically based on the currently logged in user?
In ideal we would like to pass kerberos credentials from the frontend throug api to the database.

Thanks in advance for any clues,
Konrad Perzyna

Melvyn Sopacua

unread,
Feb 23, 2017, 12:38:14 PM2/23/17
to django...@googlegroups.com
Hi Konrad,

On Thursday 23 February 2017 02:54:22 konrad....@uni.lodz.pl wrote:


> After starting the project, we've realised that db routing is limited
> to the set of db connections that are statically described in django
> settings.

Just a few minutes before your post, a link was posted:
https://github.com/ambitioninc/django-dynamic-db-router

So no, they're not static. This package may not suit your needs, but
it's mechanism with a custom router should help you along.

--
Melvyn Sopacua

konrad....@uni.lodz.pl

unread,
Feb 27, 2017, 10:26:34 AM2/27/17
to Django users
Thank you Melvyn. For now it's the best option we've found.
Reply all
Reply to author
Forward
0 new messages