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

ci: fix CI skip script hole #21741

Merged
merged 1 commit into from
Sep 16, 2024
Merged

ci: fix CI skip script hole #21741

merged 1 commit into from
Sep 16, 2024

Conversation

zalimeni
Copy link
Member

@zalimeni zalimeni commented Sep 16, 2024

In some environments, the script will not fail despite SKIP_CHECK_BRANCH being unset, leading to the script explicitly skipping CI when it should fail fast.

Meta-comment: we should consider transitioning to paths-ignore. Even though it'd be a bit more copypasta, the upside is we can't silently skip and pass tests + security scans by accident if a future bug or misconfiguration occurs.

Meta-meta-comment: looks like the above is currently infeasible, more on why and alternatives to maintaining our script here.

Description

Example script failure -> skipped CI: https://github.com/hashicorp/consul/actions/runs/10851790913/job/30116333377#step:3:5 (this workflow no longer uses the script, and relies on paths-ignore instead).

Testing

❯ .github/scripts/check_skip_ci.sh; echo $?
.github/scripts/check_skip_ci.sh: line 16: SKIP_CHECK_BRANCH: SKIP_CHECK_BRANCH is required
1

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

@zalimeni zalimeni added pr/no-changelog PR does not need a corresponding .changelog entry backport/all Apply backports for all active releases per .release/versions.hcl labels Sep 16, 2024
@github-actions github-actions bot added the theme/contributing Additions and enhancements to community contributing materials label Sep 16, 2024
@zalimeni zalimeni force-pushed the zalimeni/fix-scan-ci-skip-config branch from e548773 to 6be0c16 Compare September 16, 2024 17:23
In some environments, the script will not fail despite SKIP_CHECK_BRANCH
being unset, leading to the script explicitly skipping CI when it should
fail fast.

Prevent this by explicitly checking for the env var.
@zalimeni zalimeni force-pushed the zalimeni/fix-scan-ci-skip-config branch from 6be0c16 to 4ffa6cb Compare September 16, 2024 17:23
@@ -13,7 +13,8 @@ set -euo pipefail
#
# ... `git merge-base origin/$SKIP_CHECK_BRANCH HEAD` would return commit `D`
# `...HEAD` specifies from the common ancestor to the latest commit on the current branch (HEAD)..
files_to_check=$(git diff --name-only "$(git merge-base origin/$SKIP_CHECK_BRANCH HEAD~)"...HEAD)
skip_check_branch=${SKIP_CHECK_BRANCH:?SKIP_CHECK_BRANCH is required}
files_to_check=$(git diff --name-only "$(git merge-base origin/$skip_check_branch HEAD~)"...HEAD)
Copy link
Member Author

@zalimeni zalimeni Sep 16, 2024

Choose a reason for hiding this comment

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

This subshell ignores the set -e at the top of the script, so this ended up setting files_to_check to an empty string (it seems). Some envs won't tolerate the later array expansion of that value, but some CI shells seem to allow it, so the failure never causes issues and the script does the "unsafe default" of skipping CI.

@zalimeni zalimeni marked this pull request as ready for review September 16, 2024 17:31
Copy link
Contributor

@dduzgun-security dduzgun-security left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@zalimeni zalimeni merged commit 5e20e13 into main Sep 16, 2024
63 checks passed
@zalimeni zalimeni deleted the zalimeni/fix-scan-ci-skip-config branch September 16, 2024 20:35
@hc-github-team-consul-core hc-github-team-consul-core added backport/1.19 Changes are backported to 1.19 backport/ent/1.17 Changes are backported to 1.17 ent backport/ent/1.15 Changes are backported to 1.15 ent backport/ent/1.18 Changes are backported to 1.18 ent labels Sep 16, 2024
@zalimeni
Copy link
Member Author

zalimeni commented Sep 16, 2024

Just calling out here for posterity (cc @dduzgun-security): I think the reason we aren't able to use paths-ignore generally is that there is no way to make required checks passed if their workflow is skipped by a path filter. Because these particular security scan runs are proactive and not required (unlike others done internally), we can use path filtering in them, but not in integration tests, unit tests, etc.

That said, there are some battle-tested options out there like https://github.com/dorny/paths-filter written in response to this open FR that seem promising, and might relieve us of the burden of maintaining a correct implementation, which is tricky since it's ultimately about always failing the script or always setting skip explicitly to false in the case of a non-skippable file - i.e., the default when the script runs and exits 0 is inherently unsafe.

zalimeni added a commit to hashicorp/consul-k8s that referenced this pull request Sep 16, 2024
In some environments, the script will not fail despite SKIP_CHECK_BRANCH
being unset, leading to the script explicitly skipping CI when it should
fail fast.

Prevent this by explicitly checking for the env var.

Also fix a small bug where we're incorrectly requiring ',' in the
.changelog directory name, which means we'll never skip changelog
entries.

This change is a port of hashicorp/consul#21741.
zalimeni added a commit to hashicorp/consul-k8s that referenced this pull request Sep 16, 2024
In some environments, the script will not fail despite SKIP_CHECK_BRANCH
being unset, leading to the script explicitly skipping CI when it should
fail fast.

Prevent this by explicitly checking for the env var.

Also fix a small bug where we're incorrectly requiring ',' in the
.changelog directory name, which means we'll never skip changelog
entries.

This change is a port of hashicorp/consul#21741.
zalimeni added a commit to hashicorp/consul-dataplane that referenced this pull request Sep 16, 2024
In some environments, the script will not fail despite SKIP_CHECK_BRANCH
being unset, leading to the script explicitly skipping CI when it should
fail fast.

Prevent this by explicitly checking for the env var.

This change is a port of hashicorp/consul#21741.
zalimeni added a commit to hashicorp/consul-k8s that referenced this pull request Sep 17, 2024
In some environments, the script will not fail despite SKIP_CHECK_BRANCH
being unset, leading to the script explicitly skipping CI when it should
fail fast.

Prevent this by explicitly checking for the env var.

Also fix a small bug where we're incorrectly requiring ',' in the
.changelog directory name, which means we'll never skip changelog
entries.

This change is a port of hashicorp/consul#21741.
zalimeni added a commit to hashicorp/consul-dataplane that referenced this pull request Sep 17, 2024
In some environments, the script will not fail despite SKIP_CHECK_BRANCH
being unset, leading to the script explicitly skipping CI when it should
fail fast.

Prevent this by explicitly checking for the env var.

This change is a port of hashicorp/consul#21741.
zalimeni added a commit to hashicorp/consul-dataplane that referenced this pull request Sep 17, 2024
In some environments, the script will not fail despite SKIP_CHECK_BRANCH
being unset, leading to the script explicitly skipping CI when it should
fail fast.

Prevent this by explicitly checking for the env var.

This change is a port of hashicorp/consul#21741.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/all Apply backports for all active releases per .release/versions.hcl backport/ent/1.15 Changes are backported to 1.15 ent backport/ent/1.17 Changes are backported to 1.17 ent backport/ent/1.18 Changes are backported to 1.18 ent backport/1.19 Changes are backported to 1.19 pr/no-changelog PR does not need a corresponding .changelog entry theme/contributing Additions and enhancements to community contributing materials
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants