k8s: handle $ symbols in environment variable names and values (#74)

* Add test cases

* Handle $ symbols in environment variable names and values
This commit is contained in:
Arthur Baars
2023-04-18 15:14:10 +02:00
committed by GitHub
parent 04b58be49a
commit c37c5ca584
3 changed files with 108 additions and 3 deletions

View File

@@ -111,13 +111,21 @@ export function writeEntryPointScript(
if (environmentVariables && Object.entries(environmentVariables).length) {
const envBuffer: string[] = []
for (const [key, value] of Object.entries(environmentVariables)) {
if (key.includes(`=`) || key.includes(`'`) || key.includes(`"`)) {
if (
key.includes(`=`) ||
key.includes(`'`) ||
key.includes(`"`) ||
key.includes(`$`)
) {
throw new Error(
`environment key ${key} is invalid - the key must not contain =, ' or "`
`environment key ${key} is invalid - the key must not contain =, $, ', or "`
)
}
envBuffer.push(
`"${key}=${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`
`"${key}=${value
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\$/g, '\\$')}"`
)
}
environmentPrefix = `env ${envBuffer.join(' ')} `