-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix: add root encryption key in the examples env #4919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,7 +17,6 @@ import { RootKeyEncryptionStrategy } from "@app/services/kms/kms-types"; | |||||
| import { TSuperAdminDALFactory } from "@app/services/super-admin/super-admin-dal"; | ||||||
| import { ADMIN_CONFIG_DB_UUID } from "@app/services/super-admin/super-admin-service"; | ||||||
|
|
||||||
| import { isBase64 } from "../../base64"; | ||||||
| import { getConfig, TEnvConfig } from "../../config/env"; | ||||||
| import { CryptographyError } from "../../errors"; | ||||||
| import { logger } from "../../logger"; | ||||||
|
|
@@ -114,7 +113,7 @@ const cryptographyFactory = () => { | |||||
| enabled: boolean, | ||||||
| hsmService: THsmServiceFactory, | ||||||
| kmsRootConfigDAL: TKmsRootConfigDALFactory, | ||||||
| envCfg?: Pick<TEnvConfig, "ENCRYPTION_KEY"> | ||||||
| envCfg?: Pick<TEnvConfig, "ENCRYPTION_KEY" | "ROOT_ENCRYPTION_KEY"> | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||||||
| ) => { | ||||||
| // If FIPS is enabled, we need to validate that the ENCRYPTION_KEY is in a base64 format, and is a 256-bit key. | ||||||
| if (enabled) { | ||||||
|
|
@@ -135,18 +134,20 @@ const cryptographyFactory = () => { | |||||
|
|
||||||
| // only perform encryption key validation if it's actually required. | ||||||
| if (needsEncryptionKey) { | ||||||
| if (appCfg.ENCRYPTION_KEY) { | ||||||
| const encryptionKey = appCfg.ROOT_ENCRYPTION_KEY || appCfg.ENCRYPTION_KEY; | ||||||
|
|
||||||
| if (encryptionKey) { | ||||||
| // we need to validate that the ENCRYPTION_KEY is a base64 encoded 256-bit key | ||||||
|
|
||||||
| // note(daniel): for some reason this resolves as true for some hex-encoded strings. | ||||||
| if (!isBase64(appCfg.ENCRYPTION_KEY)) { | ||||||
| if (!encryptionKey) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: this check will always evaluate to false since
Suggested change
|
||||||
| throw new CryptographyError({ | ||||||
| message: | ||||||
| "FIPS mode is enabled, but the ENCRYPTION_KEY environment variable is not a base64 encoded 256-bit key.\nYou can generate a 256-bit key using the following command: `openssl rand -base64 32`" | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| if (bytesToBits(Buffer.from(appCfg.ENCRYPTION_KEY, "base64").length) !== 256) { | ||||||
| if (bytesToBits(Buffer.from(encryptionKey, "base64").length) !== 256) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above applies for all other changes except the .env.example file |
||||||
| throw new CryptographyError({ | ||||||
| message: | ||||||
| "FIPS mode is enabled, but the ENCRYPTION_KEY environment variable is not a 256-bit key.\nYou can generate a 256-bit key using the following command: `openssl rand -base64 32`" | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -828,9 +828,9 @@ export const kmsServiceFactory = ({ | |
| }; | ||
|
|
||
| const $getBasicEncryptionKey = () => { | ||
| const encryptionKey = envConfig.ENCRYPTION_KEY || envConfig.ROOT_ENCRYPTION_KEY; | ||
| const encryptionKey = envConfig.ROOT_ENCRYPTION_KEY || envConfig.ENCRYPTION_KEY; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be removed, since we are using ENCRYPTION_KEY |
||
|
|
||
| const isBase64 = !envConfig.ENCRYPTION_KEY; | ||
| const isBase64 = envConfig.ROOT_ENCRYPTION_KEY; | ||
| if (!encryptionKey) | ||
| throw new Error( | ||
| "Root encryption key not found for KMS service. Did you set the ENCRYPTION_KEY or ROOT_ENCRYPTION_KEY environment variables?" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIPS doesn't use the ROOT_ENCRYPTION_KEY variable. It still uses the ENCRYPTION_KEY variable, internally transforms it to ROOT_ENCRYPTION_KEY.