How do I store details securely with django?

71 views
Skip to first unread message

Lance Haig

unread,
Nov 11, 2018, 8:47:56 AM11/11/18
to django...@googlegroups.com
Hi,

I have a project I am working on https://github.com/lhaig/usery/ and
part of the roadmap of the project is to add more cloud types to the list.

I wanted to allow admins for these services to login and create records
for their different clouds in the DB and then use these when people
request access to these services.

I need to find a secure way to store these credentials so that even if
the DB is compromised that the credentials are safe.

Does anyone have suggestions on how I can accomplish this?

I would really appreciate some advice.

Regards

Lance



Mike Dewhirst

unread,
Nov 11, 2018, 5:07:57 PM11/11/18
to django...@googlegroups.com
On 12/11/2018 12:47 AM, Lance Haig wrote:
> Hi,
>
> I have a project I am working on https://github.com/lhaig/usery/ and
> part of the roadmap of the project is to add more cloud types to the
> list.
>
> I wanted to allow admins for these services to login and create
> records for their different clouds in the DB and then use these when
> people request access to these services.
>
> I need to find a secure way to store these credentials so that even if
> the DB is compromised that the credentials are safe.

I agree credentials should not be stored in the database but what are
your other assumptions about the threats?

How many sets of credentials will there be?

In future, will you be using simple credentials or tokens, certificates,
multi factor auth?

If this is a prototype and only a few sets are involved you can store
credentials in a file or one file per set and write a method to fetch
them as required. That will keep them out of the database and let you
rejig the method after you have decided how it should really work.

PASCUAL Eric

unread,
Nov 11, 2018, 6:04:25 PM11/11/18
to django...@googlegroups.com

Hi,


It can depend on which deployment option you plan to use for the application.


For instance, a Docker deployment orchestrated by Kubernetes gives the option of using secrets for sensitive information, which a hoster such as GCP manages conveniently. In this kind of deployment, configuration (and secrets) are passed to the app as environment variables, on which Kubernetes configuration maps and secrets are mapped to. Thanks to this, values are stored nowhere in the app code, companion files or database.


Regards


Eric


From: django...@googlegroups.com <django...@googlegroups.com> on behalf of Mike Dewhirst <mi...@dewhirst.com.au>
Sent: Sunday, November 11, 2018 11:07:14 PM
To: django...@googlegroups.com
Subject: Re: How do I store details securely with django?
 
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c8819341-7c60-56ee-6298-3a6a7897e9b1%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

Lance Haig

unread,
Nov 12, 2018, 3:03:29 AM11/12/18
to django...@googlegroups.com
Hi,

Thanks for responding.

My answers inline


On 11/11/18 11:07 PM, Mike Dewhirst wrote:
> On 12/11/2018 12:47 AM, Lance Haig wrote:
>> Hi,
>>
>> I have a project I am working on https://github.com/lhaig/usery/ and
>> part of the roadmap of the project is to add more cloud types to the
>> list.
>>
>> I wanted to allow admins for these services to login and create
>> records for their different clouds in the DB and then use these when
>> people request access to these services.
>>
>> I need to find a secure way to store these credentials so that even
>> if the DB is compromised that the credentials are safe.
>
> I agree credentials should not be stored in the database but what are
> your other assumptions about the threats?
>
> How many sets of credentials will there be?


it could potentially be 5 to 10 per admin account


>
> In future, will you be using simple credentials or tokens,
> certificates, multi factor auth?


These credentials are access details to other clouds.

The application is a user sandbox portal to allow admins to grant X
number of days access to a cloud for testing and discovery.

It currently is focused on openstack but he roadmap plan is to add
docker Kubernetes etc..

So I need to have the ability for the cloud admins to add or remove
authentication details as they are needed.


>
> If this is a prototype and only a few sets are involved you can store
> credentials in a file or one file per set and write a method to fetch
> them as required. That will keep them out of the database and let you
> rejig the method after you have decided how it should really work.
>
I currently use the .env file to hold these credentials but that does
not scale very well when you need to add more and more.

Lance Haig

unread,
Nov 12, 2018, 3:08:05 AM11/12/18
to django...@googlegroups.com

Hi Eric,


Thanks for the response.


This idea has an end goal of being deployed in a resilient way so most probably docker with some form of orchestration, Docker swarm or Kubernetes.


The credentials are mainly stored in a .env file at the moment and could be added to the secrets but I need for people who are admins for a particular cloud to add their cloud details to the app and then store their credentials securely.


Unfortunately this will need a dynamic storage mechanism which i don't know how to do yet


Regards


Lance

Mike Dewhirst

unread,
Nov 12, 2018, 3:31:37 AM11/12/18
to django...@googlegroups.com
I haven't thought deeply about this because it is not my project but on
the surface, if they are temporary credentials I cannot see much need
for heavy duty security.

If the perceived risk is database compromise it might be better to
configure the database or the database server with an ACL including only
the Django server IP address and perhaps one or two trusted people.

Maybe Kubernetes secrets is the eventual way forward but scalability is
assured if you can keep the creds in the database.

What about a separate non-public schema (assuming Postgres) for creds?
I'm sure you could lock that down to particular permission groups which
ought keep things secure enough.

The bottom line question: What is lost if temporary creds are compromised?

Risk is hazard multiplied by likelihood/opportunity

If you can reduce either side of that equation you reduce risk.

What plan do you have to execute to recover from the feared event
when/if it happens?

When all things are considered the answer to that last question
determines how much effort is warranted.

PASCUAL Eric

unread,
Nov 12, 2018, 4:05:14 AM11/12/18
to django...@googlegroups.com

Hi Lance,


 but I need for people who are admins for a particular cloud to add their cloud details to the app and then store their credentials securely.


I'm not sure to understand the need for adding cloud details to the app for the admins.


The suggestion I made assumed that sensitive information is managed as K8S secrets. As long as the admins have GCloud (for instance) credentials set (which are stored and managed at GCloud level), they can administrate the secrets resources by "applying" the corresponding YAML descriptors remotely from their workstation. The sensitive values are thus stored nowhere inside the application itself, but passed to the containers at runtime as environment variables.


Maybe I've misunderstood your need and sorry in this case if my answer is off topic.


Best


Eric


From: django...@googlegroups.com <django...@googlegroups.com> on behalf of Lance Haig <lnh...@gmail.com>
Sent: Monday, November 12, 2018 9:07:30 AM

Pradeep Singh

unread,
Nov 12, 2018, 6:29:38 AM11/12/18
to django...@googlegroups.com
can i develop real estate web application using python+ django

Lance Haig

unread,
Nov 12, 2018, 10:46:32 AM11/12/18
to django...@googlegroups.com

Hi Eric,


I am sure I have not explained myself properly.

The app does the following.

It presents a user the ability to sign up to a cloud platform for a sandbox / playground account.
The number of cloud services that are available will change over time.

Each cloud platform has a set of credentials (username, password, domain etc...) These credentials will have elevated permissions within their own environments and so should be kept as safe as possible.

Currently I use secrets and .env files to provide these credentials.
This requires physical access to the platform to add new secrets etc...

I want to enable editing (e.g. CRUD on the platform credentials) without having to redeploy the application or update the secrets.
The idea was to enable an admin interface to the DB so that each cloud platform admin could add more or delete their platform from the solution.
This requires a place to store secrets that can be updated deleted and created.
I was hoping that there might be a standard way to store these that is secure other than adding secrets or updating the .env file.

Thanks for trying to understand my vague question.

Lance

Lance Haig

unread,
Nov 12, 2018, 10:53:22 AM11/12/18
to django...@googlegroups.com

Hi Mike,

Thank you for taking the time to read this.

I have highlighted these sentences in your response

The bottom line question: What is lost if temporary creds are compromised?

The credentials have high level access to the backed system think e.g  kubernetes admin so compromise would mean full access to kubernetes to add remove delete anything.


What plan do you have to execute to recover from the feared event when/if it happens?

This is a valid question, The recovery for these would be rebuild of a cluster or service. depending on the damage caused.


It seems my idea of making these options configurable via a web UI will not easily be done.

I will have to stay with the current deployment plan.

Thanks


Lance

PASCUAL Eric

unread,
Nov 12, 2018, 5:36:57 PM11/12/18
to django...@googlegroups.com

Hi Lance,


Well, I was off topic. Sorry for this :/ I understand your need better now.


There are chances you've already thought to this option, but what about storing the sensitive data encrypted with a key based on a passphrase the user must provide when logging, in addition to the usual credentials ? This passphrase would not be stored anywhere, so even if the DB is compromised, the sensitive data would not be usable.


Eric


Sent: Monday, November 12, 2018 4:45:50 PM

Devender Kumar

unread,
Nov 12, 2018, 10:56:19 PM11/12/18
to django...@googlegroups.com
Hi
Study about LDAP protocol 
Regards 
Dev

Mike Dewhirst

unread,
Nov 13, 2018, 12:29:02 AM11/13/18
to Django users
Another thought

Django admin has a built-in mechanism for password management. It includes forms with password widgets.Perhaps you could hack your own encryption of the cloud credentials based on the Django approach to passwords.

It is possible to add forms to the Admin and include your own logic. I have done that - without the extra credentials part - to create additional data based on converting a @domain added to a username into a company name and company profile.

Mike

Lance Haig

unread,
Nov 14, 2018, 9:59:53 AM11/14/18
to django...@googlegroups.com

Thanks I will take a look at that


Lance

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Lance Haig

unread,
Nov 14, 2018, 10:00:46 AM11/14/18
to django...@googlegroups.com

Thanks Eric,


I did not explain myself properly so the mistake was mine.


Thanks for the help.


Lance

Lance Haig

unread,
Nov 14, 2018, 10:02:17 AM11/14/18
to django...@googlegroups.com

Hi Dev,

I believe that it would not provide much more security around the details.

Thank you for responding.


Regards

Lance

Reply all
Reply to author
Forward
0 new messages