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

fix s3 unauthenticated logic #169

Merged
merged 1 commit into from
Oct 30, 2023
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
2 changes: 1 addition & 1 deletion features/src/utils/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "devcontainer-utils",
"id": "utils",
"version": "23.12.0",
"version": "23.12.1",
"description": "A feature to install RAPIDS devcontainer utility scripts",
"containerEnv": {
"BASH_ENV": "/etc/bash.bash_env"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ generate_s3_creds() {

if test -z "${VAULT_HOST:-}" \
|| test -z "${SCCACHE_BUCKET:-}"; then
return;
exit 1;
fi

SCCACHE_REGION="${SCCACHE_REGION:-${AWS_DEFAULT_REGION:-}}";
Expand All @@ -25,7 +25,7 @@ generate_s3_creds() {
source devcontainer-utils-init-github-cli;

if test -z "${GITHUB_USER:-}"; then
return;
exit 1;
fi

# Check whether the user is in one of the allowed GitHub orgs
Expand All @@ -41,7 +41,7 @@ generate_s3_creds() {
)";

if test -z "${user_orgs:-}"; then
return;
exit 1;
fi

echo ""
Expand All @@ -56,7 +56,7 @@ generate_s3_creds() {

if [ "${vault_token:-null}" = "null" ]; then
echo "Your GitHub user was not recognized by vault. Skipping." >&2;
return;
exit 1;
fi

echo "Successfully authenticated with vault!";
Expand Down Expand Up @@ -84,12 +84,12 @@ generate_s3_creds() {

if grep -qE "^null$" <<< "${aws_access_key_id:-null}"; then
echo "Failed to retrieve AWS S3 credentials. Skipping." >&2;
return;
exit 1;
fi

if grep -qE "^null$" <<< "${aws_secret_access_key:-null}"; then
echo "Failed to retrieve AWS S3 credentials. Skipping." >&2;
return;
exit 1;
fi

echo "Successfully generated temporary AWS S3 credentials!";
Expand All @@ -115,6 +115,6 @@ if test -n "${devcontainer_utils_debug:-}"; then
PS4="+ ${BASH_SOURCE[0]}:\${LINENO} "; set -x;
fi

(generate_s3_creds "$@");
generate_s3_creds "$@";

. /etc/profile.d/*-devcontainer-utils.sh;
20 changes: 11 additions & 9 deletions features/src/utils/opt/devcontainer/bin/vault/s3/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ init_vault_s3_creds() {
&& grep -qE "^$" <<< "${AWS_SECRET_ACCESS_KEY:-}" ; then
if test -n "${VAULT_HOST:-}" ; then
# Generate S3 creds if they don't exist (or are expired)
if ! devcontainer-utils-vault-s3-creds-test 2>&1 >/dev/null; then
devcontainer-utils-vault-s3-creds-generate;
if devcontainer-utils-vault-s3-creds-test 2>&1 >/dev/null\
|| devcontainer-utils-vault-s3-creds-generate; then
# Persist creds in ~/.aws dir
devcontainer-utils-vault-s3-creds-persist <<< "
$(s3_bucket_args)
$(s3_bucket_auth)
";
# Install a crontab to refresh the credentials
devcontainer-utils-vault-s3-creds-schedule;
else
devcontainer-utils-vault-s3-creds-persist <<< "--no_bucket --no_region";
fi
# Persist creds in ~/.aws dir
devcontainer-utils-vault-s3-creds-persist <<< "
$(s3_bucket_args)
$(s3_bucket_auth)
";
# Install a crontab to refresh the credentials
devcontainer-utils-vault-s3-creds-schedule;
else
# If credentials have been mounted in, ensure they're used
case $(devcontainer-utils-vault-s3-creds-test; echo $?) in
Expand Down