Skip to content

feat(ci): migrate sync-rule-templates to ephemeral GitHub token - #8350

Merged
gurevichdmitry merged 11 commits into
mainfrom
feat/sync-rule-templates-ephemeral-token
Sep 9, 2026
Merged

feat(ci): migrate sync-rule-templates to ephemeral GitHub token#8350
gurevichdmitry merged 11 commits into
mainfrom
feat/sync-rule-templates-ephemeral-token

Conversation

@gurevichdmitry

@gurevichdmitry gurevichdmitry commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Revives .github/workflows/sync-rule-templates.yml so CIS data.yaml changes on main open/update a PR in elastic/integrations. Authenticates with an ephemeral GitHub token (OIDC + TokenPolicy) instead of CLOUDSEC_MACHINE_TOKEN.

Changes

  • Replace secrets.CLOUDSEC_MACHINE_TOKEN with an OIDC-minted ephemeral token via elastic/ci-gh-actions/fetch-github-token (same pattern as sync-internal-cloudbeat-version.yml)
  • Add id-token: write permission at job level; restrict top-level permissions to contents: read
  • Replace hermit with direct setup-python + pipx install poetry steps — hermit's composite action uses paths relative to $GITHUB_WORKSPACE but cloudbeat is checked out to a subdirectory (cloudbeat/)
  • Fix bump_integration_version in scripts/common.sh for Linux: read version map comment before yq strips it, patch-bump within the current minor series instead of always minor-bumping, strip yq-preserved comments before restoring the header block, replace macOS-only sed -i '' with portable approach
  • Fix generate_rule_templates.py to write a trailing newline on generated JSON files, avoiding noisy diffs in elastic/integrations PRs
  • Fix early exit in sync_rule_templates.sh when no template changes are detected

Pre-requisites

TokenPolicy token-policy-cloudbeat-sync-rule-templatesalready merged and realized:

Test results ✅

Workflow ran end-to-end successfully from this branch:

Verified:

  • Token minted successfully via OIDC + Vault
  • Templates generated for k8s / eks / aws / gcp / azure rules
  • PR created in elastic/integrations with correct labels and version bump (3.5.2-preview01, ^9.6.0)
  • No CLOUDSEC_MACHINE_TOKEN references remain

Tracked in: https://github.com/elastic/security-team/issues/19162

🤖 Generated with Claude Code

Replace CLOUDSEC_MACHINE_TOKEN with an OIDC-minted ephemeral token via
elastic/ci-gh-actions/fetch-github-token. Also fix the hermit action path
(./.github/actions/hermit → ./cloudbeat/.github/actions/hermit), which was
the root cause of both previous workflow failures.

Closes elastic/security-team#19162

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gurevichdmitry
gurevichdmitry requested a review from a team as a code owner September 7, 2026 09:34
@mergify

mergify Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

This pull request does not have a backport label. Could you fix it @gurevichdmitry? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

gurevichdmitry and others added 9 commits September 7, 2026 13:09
Avoids a hard failure on `git commit` (set -euo pipefail) when the
generated templates are identical to what is already in origin/main.
Also prevents a spurious integration version bump when there is nothing
to ship.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…T ME]

Adds the feature branch to the push trigger and makes a trivial data.yaml
change so the workflow runs end-to-end from this branch. Revert this commit
before merging.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The hermit action assumes cloudbeat is checked out at the workspace root
($GITHUB_WORKSPACE), but this workflow checks out both cloudbeat and
integrations as side-by-side subdirectories (required by the generator's
hardcoded ../../../integrations path). Hermit's internal steps (find ./bin,
./.ci/scripts/retry.sh, etc.) resolve relative to $GITHUB_WORKSPACE and
all fail in this layout.

Replace hermit with direct installation of only the tools this workflow
actually needs: Poetry (for generate_rule_templates.py) and yq (for
bump_integration_version in common.sh).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
pipx is pre-installed on ubuntu-22.04 runners; yq 4.53.6 is also
pre-installed so no snap install needed. setup-python activates
Python 3.11 from the runner tool cache.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Read changelog comment header before yq (which strips comments)
- Find version map entry by grep pattern instead of hardcoded line number
- Restore comment block after yq via awk+temp file (cross-platform)
- Replace macOS-only `sed -i ''` with portable temp-file approach

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ling

- Add bump_patch_version helper
- Patch-bump within current minor series (e.g. 3.5.1 → 3.5.2-preview01)
  when version map already has an entry for that minor; minor-bump only
  when starting a new series
- Strip comments yq preserves mid-file before restoring header block
- Fix shfmt: remove space before output redirection in compound command

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ling newline

- Remove test branch trigger (feat/sync-rule-templates-ephemeral-token)
- Revert data.yaml test change (default_value)
- Add trailing newline to generated JSON templates to match existing
  files in elastic/integrations and avoid noisy diffs in sync PRs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mergify

mergify Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@gurevichdmitry
gurevichdmitry added this pull request to the merge queue Sep 9, 2026
Merged via the queue into main with commit f49f9a4 Sep 9, 2026
12 checks passed
@gurevichdmitry
gurevichdmitry deleted the feat/sync-rule-templates-ephemeral-token branch September 9, 2026 10:21
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.

2 participants