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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out Bash read-only env vars in export_env() (such as UID) #1751

Open
edmorley opened this issue Feb 18, 2025 · 2 comments
Open

Filter out Bash read-only env vars in export_env() (such as UID) #1751

edmorley opened this issue Feb 18, 2025 · 2 comments
Labels

Comments

@edmorley
Copy link
Member

While looking at build failure metrics, I noticed this internal error:

-----> Installing dependencies using 'pip install -r requirements.txt'
/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/vendor/buildpack-stdlib_v8.sh: line 56: UID: readonly variable
 !     Push rejected, failed to compile Python app.

This appears to be due to an app having the env var UID set in it's config vars, and UID being a read-only Bash env var.

We should filter this env var out (along with any others labelled as readonly on https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html), here:

# Usage: $ export-env ENV_DIR WHITELIST BLACKLIST
# Exports the environment variables defined in the given directory.
export_env() {
local env_dir=${1:-$ENV_DIR}
local whitelist=${2:-''}
local blacklist
blacklist="$(_env_blacklist "$3")"
if [[ -d "$env_dir" ]]; then
# Environment variable names won't contain characters affected by:
# shellcheck disable=SC2045
for e in $(ls "$env_dir"); do
echo "$e" | grep -E "$whitelist" | grep -qvE "$blacklist" \
&& export "$e=$(cat "$env_dir/$e")"
:
done
fi
}

We should probably do this before implementing #1451 / #1700.

@edmorley edmorley added the bug label Feb 18, 2025
@edmorley
Copy link
Member Author

edmorley commented Mar 5, 2025

We also need to filter out the env var RANDOM, since it's a special Bash env var too, otherwise RANDOM=Foo results in eg:

/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/vendor/buildpack-stdlib_v8.sh: line 56: Foo: unbound variable

@edmorley
Copy link
Member Author

edmorley commented Mar 5, 2025

Also non-ASCII env var names apparently (plus it seems API should prevent setting these in the first place?):

/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/vendor/buildpack-stdlib_v8.sh: line 56: export: `<some-non-ascii-env-var>': not a valid identifier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant