Skip to content

Commit a01d56e

Browse files
committed
fix: preserve $ in Harbor robot username through registry-info + docker login
When a serverless k8s (Harbor-backed) org runs through the legacy `serverless_prod_deploy` / `serverless_branch_deploy` flow, the docker login step fails with `401 unauthorized`. Two layers of bash variable expansion eat the `$<project>` substring of the Harbor robot username `robot$<project>+push`: 1. `src/registry_info.sh` ran `echo $REGISTRY_INFO > registry_info.env` (unquoted) followed by `source registry_info.env`. Both re-expand `$<project>` (an unset shell variable) to empty before the value reached `$GITHUB_ENV`. Parse KEY=VALUE pairs via `read -r` instead so the literal `$` survives. 2. The `Login to ECR` step in both deploy action YAMLs interpolated the username via `${{ env.AWS_ECR_USERNAME }}` template substitution, which pastes the value into the bash script *before* bash runs. Switch to bash env-var access (`"$AWS_ECR_USERNAME"`) so the value is read verbatim at run time, no recursive expansion. ECR ("AWS" username, no `$`) is unaffected. Tested on a real prod serverless v2 org by pinning a downstream workflow to this fix branch and running both branch and prod deploys end to end.
1 parent 4b80945 commit a01d56e

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

actions/serverless_branch_deploy/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ runs:
5757
DAGSTER_CLOUD_API_TOKEN: ${{ inputs.dagster_cloud_api_token }}
5858

5959
- name: Login to ECR
60-
run: echo "${{ env.AWS_ECR_PASSWORD }}" | docker login --username ${{ env.AWS_ECR_USERNAME }} --password-stdin ${{ env.REGISTRY_URL }}
60+
# Read credentials from bash env, not from `${{ env.VAR }}` template
61+
# substitution. The latter pastes the literal value into the bash
62+
# script before bash runs, which causes a `$` in the username (e.g.
63+
# Harbor robot accounts: robot$<project>+push) to be eaten as a
64+
# variable expansion.
65+
run: echo "$AWS_ECR_PASSWORD" | docker login --username "$AWS_ECR_USERNAME" --password-stdin "$REGISTRY_URL"
6166
shell: bash
6267

6368
- name: Notify build start

actions/serverless_prod_deploy/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ runs:
5757
DAGSTER_CLOUD_API_TOKEN: ${{ inputs.dagster_cloud_api_token }}
5858

5959
- name: Login to ECR
60-
run: echo "${{ env.AWS_ECR_PASSWORD }}" | docker login --username ${{ env.AWS_ECR_USERNAME }} --password-stdin ${{ env.REGISTRY_URL }}
60+
# Read credentials from bash env, not from `${{ env.VAR }}` template
61+
# substitution. The latter pastes the literal value into the bash
62+
# script before bash runs, which causes a `$` in the username (e.g.
63+
# Harbor robot accounts: robot$<project>+push) to be eaten as a
64+
# variable expansion.
65+
run: echo "$AWS_ECR_PASSWORD" | docker login --username "$AWS_ECR_USERNAME" --password-stdin "$REGISTRY_URL"
6166
shell: bash
6267

6368
- name: Set up Docker Buildx

src/registry_info.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,23 @@ while (( !AWS_ECR_PASSWORD && count < 6 )); do
1515
REGISTRY_INFO=$(dagster-cloud serverless registry-info \
1616
--url "${DAGSTER_CLOUD_URL}/${INPUT_DEPLOYMENT}" \
1717
--api-token "$DAGSTER_CLOUD_API_TOKEN")
18-
echo $REGISTRY_INFO > registry_info.env
19-
source registry_info.env
18+
# Parse KEY=VALUE pairs without `source` or unquoted `echo`, because
19+
# either would re-expand any `$` in the value (e.g. Harbor robot
20+
# usernames are `robot$<project>+push`) and mangle the credential.
21+
AWS_ECR_USERNAME=""
22+
AWS_ECR_PASSWORD=""
23+
REGISTRY_URL=""
24+
AWS_DEFAULT_REGION=""
25+
CUSTOM_BASE_IMAGE_ALLOWED=""
26+
while IFS='=' read -r _key _value; do
27+
case "$_key" in
28+
AWS_ECR_USERNAME) AWS_ECR_USERNAME="$_value" ;;
29+
AWS_ECR_PASSWORD) AWS_ECR_PASSWORD="$_value" ;;
30+
REGISTRY_URL) REGISTRY_URL="$_value" ;;
31+
AWS_DEFAULT_REGION) AWS_DEFAULT_REGION="$_value" ;;
32+
CUSTOM_BASE_IMAGE_ALLOWED) CUSTOM_BASE_IMAGE_ALLOWED="$_value" ;;
33+
esac
34+
done <<<"$REGISTRY_INFO"
2035
count=$(($count + 1))
2136
if [ ! -z "$AWS_ECR_PASSWORD" ]; then
2237
echo "Loaded registry information."

0 commit comments

Comments
 (0)