Skip to content

fix(ci): fix publish-containers workflow matrix reference error#1239

Merged
imran-siddique merged 1 commit intomicrosoft:mainfrom
imran-siddique:fix/container-workflow
Apr 20, 2026
Merged

fix(ci): fix publish-containers workflow matrix reference error#1239
imran-siddique merged 1 commit intomicrosoft:mainfrom
imran-siddique:fix/container-workflow

Conversation

@imran-siddique
Copy link
Copy Markdown
Member

Fixes: matrix context not available in job-level if. Moves filter to step-level check.

…b-level if

Move component filter from job-level 'if' (where matrix context is
unavailable) to a step-level check. All subsequent steps are gated
on steps.check.outputs.skip.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the ci/cd CI/CD and workflows label Apr 20, 2026
@imran-siddique imran-siddique merged commit fc9d4b9 into microsoft:main Apr 20, 2026
16 of 18 checks passed
@github-actions github-actions Bot added the size/S Small PR (< 50 lines) label Apr 20, 2026
@imran-siddique imran-siddique deleted the fix/container-workflow branch April 20, 2026 19:39
@github-actions
Copy link
Copy Markdown

🤖 AI Agent: security-scanner — Security Analysis of the Pull Request

Security Analysis of the Pull Request

This pull request modifies the GitHub Actions workflow for publishing container images. The changes address an issue where the matrix context was not available in a job-level if condition, by moving the filtering logic to a step-level check. Below is a security-focused review of the changes:


1. Prompt Injection Defense Bypass

No prompt injection vulnerabilities are introduced or mitigated in this PR. The changes are limited to a CI/CD workflow and do not involve user-provided prompts or interactions with AI models.

Rating: 🔵 LOW


2. Policy Engine Circumvention

The changes introduce a new step (Check if this component should build) that determines whether subsequent steps in the workflow should execute. This logic is implemented using a shell script that evaluates the event type and component selection.

Attack Vector: If an attacker can manipulate the github.event.inputs.component or github.event_name values, they could potentially bypass the intended filtering logic and trigger the build process for unintended components.

Assessment:

  • The github.event.inputs.component and github.event_name values are controlled by GitHub Actions and are not directly user-provided. However, if the repository is configured to allow untrusted users to trigger workflows (e.g., via workflow_dispatch), there is a risk of malicious input.
  • The shell script does not sanitize or validate these inputs, which could lead to unexpected behavior if the inputs are malformed or manipulated.

Suggested Fix:

  • Add explicit validation for the github.event.inputs.component value to ensure it matches an expected set of components.
  • Use a case-insensitive comparison for the SELECTED and CURRENT variables to avoid bypasses due to casing differences.
  • Example:
    VALID_COMPONENTS=("component1" "component2" "component3")
    if [[ ! " ${VALID_COMPONENTS[@]} " =~ " ${SELECTED,,} " && "$SELECTED" != "all" ]]; then
        echo "Invalid component selected: $SELECTED"
        exit 1
    fi

Rating: 🟠 HIGH


3. Trust Chain Weaknesses

The workflow interacts with Docker and GitHub Container Registry (GHCR). The secrets used for authentication (secrets.GITHUB_TOKEN) are securely managed by GitHub Actions, and there are no changes in this PR that affect the trust chain.

Rating: 🔵 LOW


4. Credential Exposure

The workflow logs the selected component (SELECTED) and the current component (CURRENT) during the Check if this component should build step. If github.event.inputs.component contains sensitive information (e.g., a secret accidentally passed as input), it could be exposed in the logs.

Attack Vector: An attacker could exploit this to extract sensitive information from the logs.

Suggested Fix:

  • Avoid logging the value of SELECTED directly. Instead, log a sanitized or redacted version of the input.
  • Example:
    echo "Skipping component (selected input provided)"

Rating: 🟡 MEDIUM


5. Sandbox Escape

The changes do not introduce any new code execution environments or modify existing ones. The workflow uses GitHub-hosted runners, which are isolated by default.

Rating: 🔵 LOW


6. Deserialization Attacks

No deserialization is performed in this workflow. The changes do not introduce any new deserialization risks.

Rating: 🔵 LOW


7. Race Conditions

The workflow evaluates the github.event.inputs.component and matrix.component values to decide whether to skip steps. There is no evidence of concurrent operations or time-of-check-to-time-of-use (TOCTOU) vulnerabilities in this PR.

Rating: 🔵 LOW


8. Supply Chain

The workflow uses pinned versions of third-party GitHub Actions (e.g., actions/checkout, docker/setup-buildx-action, etc.). This is a good practice to prevent supply chain attacks. No new dependencies are introduced in this PR.

Rating: 🔵 LOW


Summary of Findings

  1. Policy Engine Circumvention: 🟠 HIGH

    • Issue: Potential for bypassing the filtering logic if github.event.inputs.component is manipulated.
    • Fix: Add validation for github.event.inputs.component to ensure it matches an expected set of components.
  2. Credential Exposure: 🟡 MEDIUM

    • Issue: Potential exposure of sensitive information in logs if github.event.inputs.component contains secrets.
    • Fix: Avoid logging sensitive or user-provided inputs directly.
  3. Other Categories: 🔵 LOW

    • No issues identified in prompt injection, trust chain, sandbox escape, deserialization, race conditions, or supply chain.

Recommendations

  • Implement the suggested fixes for the identified issues.
  • Test the workflow thoroughly to ensure the filtering logic works as intended and cannot be bypassed.
  • Consider adding automated tests or validations for the github.event.inputs.component value to prevent misuse.

Let me know if you need further assistance!

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Agent: code-reviewer

Review of Pull Request: fix(ci): fix publish-containers workflow matrix reference error

This PR addresses an issue in the publish-containers.yml GitHub Actions workflow, where the matrix context was incorrectly used in a job-level if condition. The fix moves the filtering logic to a step-level check, ensuring proper evaluation of the conditions.


🔍 Review Summary:

The changes in this PR are well-structured and address the issue of the matrix context not being available at the job level. By introducing a step to determine whether the current component should be built and using the GITHUB_OUTPUT mechanism to pass the result to subsequent steps, the workflow is now more robust and adheres to GitHub Actions' best practices.

However, there are a few areas that could benefit from further improvements or clarifications. Below are the detailed findings:


🔴 CRITICAL

No critical issues were found in this PR.


🟡 WARNING

  1. Potential Breaking Change in Workflow Behavior:
    • The change introduces a new step (Check if this component should build) and modifies the if conditions for all subsequent steps. While this is a necessary fix, it changes the behavior of the workflow. If any downstream systems or processes depend on the previous behavior (e.g., logs, metrics, or notifications), this could be a breaking change.
    • Action: Ensure that all stakeholders are aware of this change and that it has been tested thoroughly in a staging or test environment before merging.

💡 SUGGESTIONS

  1. Improve Logging for Skipped Components:

    • The Check if this component should build step logs a message when a component is skipped, but this message is not visible in the workflow summary. Adding a summary entry for skipped components would improve visibility.
    • Suggestion: Add a step to append a message to $GITHUB_STEP_SUMMARY for skipped components. For example:
      - name: Log skipped component
        if: steps.check.outputs.skip == 'true'
        run: |
          echo "### ⚠️ Skipped \`${{ matrix.component }}\` (selected: ${{ github.event.inputs.component }})" >> "$GITHUB_STEP_SUMMARY"
  2. Refactor Repeated if Conditions:

    • The if: steps.check.outputs.skip != 'true' condition is repeated across multiple steps. This repetition can make the workflow harder to maintain and more error-prone.
    • Suggestion: Use a reusable workflow or a composite action to encapsulate the repeated logic, or group the steps under a single conditional block if possible.
  3. Add Unit Tests for Workflow Logic:

    • While this is a CI/CD workflow, testing the logic for the Check if this component should build step would help ensure correctness. This could be done using a GitHub Actions testing framework like act or by creating a mock workflow to validate the behavior.
    • Suggestion: Add a test plan or documentation for how this workflow logic was validated.
  4. Document the Workflow Behavior:

    • The new behavior of the workflow (e.g., how components are filtered) should be documented for contributors who may need to modify or debug it in the future.
    • Suggestion: Update the repository's documentation or add comments in the workflow file to explain the purpose and behavior of the Check if this component should build step.

✅ Positive Aspects

  1. Correct Use of GITHUB_OUTPUT:

    • The use of GITHUB_OUTPUT to pass data between steps is a best practice and ensures compatibility with GitHub Actions' design.
  2. Improved Workflow Robustness:

    • By moving the filtering logic to a step-level check, the workflow avoids potential runtime errors caused by the misuse of the matrix context at the job level.
  3. Selective Execution:

    • The new logic ensures that only the necessary components are built, reducing unnecessary workload and improving efficiency.

Final Recommendation:

This PR effectively resolves the issue and improves the workflow's robustness. However, it introduces a potential breaking change in behavior and could benefit from additional logging, refactoring, and documentation. Addressing the suggestions above will further enhance the maintainability and clarity of the workflow.

Action: Proceed with merging after addressing the suggestions or confirming that they are not required for this iteration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/cd CI/CD and workflows size/S Small PR (< 50 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant