theskumar / theskumar/python-dotenv

Support encryption of .env file

Aperta
#524 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
8.9k
Fork
581
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Working in a high security environment it is sometimes concerning to have a .env file sitting on your machine with plaintext credentials needed for development. It is also cumbersome to regularly recreate the .env file per working session if the credentials are particularly sensitive. One possible solution would be to support pgp encryption of the .env file, so a call to load dotenv would look like:

from dotenv import load_dotenv

load_dotenv(encrypted=True)

Right now I'm using some boilerplate code like this:

from os import getenv
from io import StringIO
from gnupg import GPG
from dotenv import load_dotenv

# encrypted with `gpg -o .env.gpg -e --default-recipient-self .env`
with open("test.env.gpg", "rb") as f:
    env_vars = GPG().decrypt_file(f)

if not env_vars.ok:
    raise Exception(f"Decryption failed: {env_vars.status}")

load_dotenv(stream=StringIO(env_vars.data.decode()))

foo = getenv("FOO")
print(f"FOO: {foo}")

This way the decrypted credentials will only ever exist in memory and since I use a yubikey to store my private keys, there is no way to access that key and retrieve those credentials without the physical key.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Start at the load_dotenv entry point and review how the existing stream-based loading path could relate to an encrypted .env input. The issue's example uses PGP decryption and gnupg, so clarify the supported decryption interface and dependency expectations before implementation. Done should allow encrypted credentials to be loaded without requiring a plaintext .env file on disk.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
security
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.