mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-09 14:53:00 +03:00
🚀 Feature: Encrypt private key saved to DB #199
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ItalyPaleAle on GitHub.
Originally assigned to: @ItalyPaleAle on GitHub.
Feature description
The private key is currently stored on disk un-encrypted. Anyone with access to the file system can get the "keys to the kingdom".
The private key could optionally be encrypted when stored to disk. The decryption key is provided to Pocket ID via env vars (e.g.
ENCRYPTION_KEY) or with the name of another file containing the key (ENCRYPTION_KEY_FILE).This allows also using a command to retrieve the key encryption key, e.g. to fetch it from a vault of some sort.
Pitch
Data stored on disk is not always safe and can be leaked or stolen by malicious code. Encrypting the private key is a simple and effective way to keep the "keys to the kingdom" safe.
@ItalyPaleAle commented on GitHub:
I’ve given this some thought and here’s a more flushed-out design proposal.
Goals:
Configuration options:
KEYS_PATH: path on disk where the keys are storedKEYS_STORAGE: can befile(filesystem),db(database). In the future it can bememory(ephemeral) or services likehashicorp-vaultKEYS_ENCRYPTION_KEY: encryption key for the keys when stored on diskHow it works. Here are all the possible combinations. The combinations below preserve backwards-compatiblity so users don’t need to take any action.
KEYS_STORAGEKEYS_ENCRYPTION_KEYKEYS_PATHfileor emptydata/keys)databaseor emptyfiledata/keys)databasememory(Future option)Essentially the default behavior is to store on file, unencrypted. If an encryption key is passed, the default is to store in the database, encrypted.
As for how keys are actually encrypted, my recommendation is:
KEYS_ENCRYPTION_KEYand stretch it using something like PBKDF2 to a 256-bit key@ItalyPaleAle commented on GitHub:
@stonith404 I don't see why not actually, that would defintely make sense
@stonith404 commented on GitHub:
Couldn't we store the encrypted key in the database then? If we properly encrypt the key, it should be safe to store in the database, which would make Pocket ID more independent from the filesystem and bring it a step closer to running serverless.