Skip to content

Conversation

@dcolina
Copy link
Member

@dcolina dcolina commented Dec 15, 2025

Problem

The BASE_REPO variable was only defined inside the repository allowlist validation block (step 3), but it was being used later in the image existence check (step 5). This caused the variable to be empty when verify_image_existence was enabled, leading to validation failures.

Root Cause

In the image validation loop:

  • BASE_REPO extraction logic was inside the if [ -n "$ALLOWED_REPOS" ] block (lines 433-440)
  • The image existence check at line 524 used CANONICAL_IMAGE="${BASE_REPO}:${TAG}"
  • When ALLOWED_REPOS was set, BASE_REPO was defined and everything worked
  • However, the variable was being used outside its scope, which is a logic error

Solution

  • Move BASE_REPO extraction logic outside the conditional block (before step 4)
  • Now BASE_REPO is always available for both repository validation and image existence check
  • Update step numbering in comments: steps 4-7 instead of 3-5
  • Add explicit logging of BASE_REPO value for debugging

Changes

# 2. Extract repository and tag
REPO="${image%:*}"
TAG="${image##*:}"

+# 3. Extract base repository name (always, needed for multiple validations)
+BASE_REPO="$REPO"
+if [[ "$REPO" =~ / ]]; then
+  if [[ "$REPO" =~ ^[a-z0-9.-]+\.[a-z]{2,}/ ]] || [[ "$REPO" =~ ^gcr\.io/ ]] || [[ "$REPO" =~ ^.*\.gcr\.io/ ]]; then
+    BASE_REPO="${REPO#*/}"
+  fi
+fi
+echo "   Base repository: $BASE_REPO"
+
-# 3. Check repository is in allowlist (if configured)
+# 4. Check repository is in allowlist (if configured)
if [ -n "$ALLOWED_REPOS" ]; then
-  BASE_REPO="$REPO"  # ← Was only defined here
-  if [[ "$REPO" =~ / ]]; then
-    ...
-  fi
  ...
fi

Testing

This fixes the validation failure in PR #362 where the image existence check was failing due to empty BASE_REPO variable.

After this fix is merged and v1.1.1 tag is recreated, PR #362 should pass all validations.

Related

The BASE_REPO variable was only defined inside the repository allowlist
validation block, but it was being used later in the image existence check.
This caused the variable to be empty when verify_image_existence was enabled.

Changes:
- Move BASE_REPO extraction logic outside the conditional block (before step 4)
- Now BASE_REPO is always available for both repository validation and image existence check
- Update step numbering in comments (steps 4-7 instead of 3-5)
- Add explicit logging of BASE_REPO value for debugging

This fixes the validation failure in PR #362 where image existence check
was failing due to empty BASE_REPO variable.
@dcolina dcolina requested review from a team as code owners December 15, 2025 15:11
@dcolina dcolina merged commit 1c277e3 into main Dec 15, 2025
3 checks passed
@dcolina dcolina deleted the fix/base-repo-scope-issue branch December 15, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant