Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(env): add Long Range key overrides from env #3766

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading