mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-09 14:42:59 +03:00
[PR #682] [MERGED] feat: Encrypt private keys saved on disk and in DB #678
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?
📋 Pull Request Information
Original PR: https://github.com/pocket-id/pocket-id/pull/682
Author: @ItalyPaleAle
Created: 6/26/2025
Status: ✅ Merged
Merged: 7/3/2025
Merged by: @kmendell
Base:
main← Head:encrypt-keys📝 Commits (10+)
742673dfeat: Encrypt private keys saved on disk and in DB35145f6Store envConfig instead of appUrl in the object2a2e8d9Fix tests47bde74Merge branch 'main' into encrypt-keysd497e1cMerge branch 'main' of https://github.com/pocket-id/pocket-id into encrypt-keysc4fe94cMerge branch 'main' into encrypt-keysafa8d10Merge branch 'main' of https://github.com/pocket-id/pocket-id into encrypt-keysf68e848Merge branch 'main' into encrypt-keys5b28eb5Re-order migrations after merging latest changesc7d6405Rename env vars to ENCRYPTION_KEYS📊 Changes
25 files changed (+2310 additions, -327 deletions)
View changed files
📝
backend/internal/bootstrap/services_bootstrap.go(+1 -1)📝
backend/internal/common/env_config.go(+68 -31)➕
backend/internal/common/env_config_test.go(+188 -0)➕
backend/internal/model/kv.go(+11 -0)📝
backend/internal/service/app_config_service_test.go(+17 -15)📝
backend/internal/service/e2etest_service.go(+3 -1)📝
backend/internal/service/jwt_service.go(+52 -94)📝
backend/internal/service/jwt_service_test.go(+166 -77)📝
backend/internal/service/oidc_service_test.go(+8 -7)➕
backend/internal/utils/crypto/crypto.go(+69 -0)➕
backend/internal/utils/crypto/crypto_test.go(+208 -0)➕
backend/internal/utils/jwk/key_provider.go(+50 -0)➕
backend/internal/utils/jwk/key_provider_database.go(+109 -0)➕
backend/internal/utils/jwk/key_provider_database_test.go(+275 -0)➕
backend/internal/utils/jwk/key_provider_file.go(+202 -0)➕
backend/internal/utils/jwk/key_provider_file_test.go(+320 -0)➕
backend/internal/utils/jwk/utils.go(+180 -0)➕
backend/internal/utils/jwk/utils_test.go(+324 -0)➖
backend/internal/utils/jwk_util.go(+0 -69)📝
backend/internal/utils/testing/database.go(+7 -32)...and 5 more files
📄 Description
Fixes #580
Implements the design described here: https://github.com/pocket-id/pocket-id/issues/580#issuecomment-2918342289
Adds these new config options:
KEYS_STORAGE, which can befileordatabase. The default isfile.ENCRYPTION_KEYallows passing a key to use to encrypt keys stored on disk or DBENCRYPTION_KEY_FILEis akin toENCRYPTION_KEYbut contains the path to a file with the key to loadWhen keys are encrypted, they are tied to a specific instance of Pocket ID (identified by the InstanceID internal config setting).
Also note that keys are encrypted with AES-GCM.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.