Skip to content

Commit

Permalink
feat(env): add Long Range key overrides from env (#3766)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Lando <[email protected]>
  • Loading branch information
bobcob7 and robertsLando authored Jun 12, 2024
1 parent 9478c29 commit c12448c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions api/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,28 @@ export function parseSecurityKeys(
'S2_AccessControl',
'S0_Legacy',
]
const availableLongRangeKeys = ['S2_Authenticated', 'S2_AccessControl']

const envKeys = Object.keys(process.env)
.filter((k) => k?.startsWith('KEY_'))
.map((k) => k.substring(4))

const longRangeEnvKeys = Object.keys(process.env)
.filter((k) => k?.startsWith('KEY_LR_'))
.map((k) => k.substring(7))

// load security keys from env
for (const k of envKeys) {
if (availableKeys.includes(k)) {
config.securityKeys[k] = process.env[`KEY_${k}`]
}
}
// load long range security keys from env
for (const k of longRangeEnvKeys) {
if (availableLongRangeKeys.includes(k)) {
config.securityKeysLongRange[k] = process.env[`KEY_LR_${k}`]
}
}

options.securityKeys = {}
options.securityKeysLongRange = {}
Expand All @@ -359,10 +370,10 @@ export function parseSecurityKeys(

config.securityKeysLongRange = config.securityKeysLongRange || {}

// convert security keys to buffer
// convert long range security keys to buffer
for (const key in config.securityKeysLongRange) {
if (
availableKeys.includes(key) &&
availableLongRangeKeys.includes(key) &&
config.securityKeysLongRange[key].length === 32
) {
options.securityKeysLongRange[key] = Buffer.from(
Expand Down
2 changes: 2 additions & 0 deletions docs/guide/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This is the list of the supported environment variables:
- `KEY_S2_Unauthenticated`
- `KEY_S2_Authenticated`
- `KEY_S2_AccessControl`
- `KEY_LR_S2_Authenticated`
- `KEY_LR_S2_AccessControl`
- HTTPS:
- `HTTPS`: Enable https
- `SSL_CERTIFICATE` (optional): Absolute path to SSL certificate (for Docker, ensure this is the path as it appears within the container)
Expand Down

0 comments on commit c12448c

Please sign in to comment.