Skip to content

fix(automation): fill the bump PR body in a single pass - #77

Merged
rhuss merged 4 commits into
mainfrom
fix/bump-pr-body-render
Nov 27, 2026
Merged

rhuss merged 4 commits into
mainfrom
fix/bump-pr-body-render

Conversation

@rhuss

@rhuss rhuss commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

open-bump-pr.sh fills bump-pr-body.md with awk. After each substitution the loop scanned the whole line again, including the text it had just inserted, and resolved any {{UPPER_CASE}} key through ENVIRON. Upstream text in the proto diff that looks like a placeholder was therefore expanded from the core-watch step's environment, which holds GH_TOKEN. SDAChess pointed this out in the review of #60.

The renderer now lives in fill in hack/automation/template.jq, called through hack/automation/fill-template.sh, which takes KEY=value arguments and passes them to jq as --arg values. Nothing goes through the environment, so the bot token is never within reach, and values are inserted as is: no escape processing, and no second scan for placeholders. Each caller names each key once. An unknown placeholder in the template stops the run with an error, so a typo can't silently render as empty. rpc-issues.jq had the same function inline and now shares the module.

hack/migration/port-pr.sh had the same rescanning loop and inserts commit subjects and author names from the core PR, so it uses the shared renderer too.

Rendering safely is not enough for port-pr.sh: after git am, the working tree holds the upstream PR's files, so a PR could replace the renderer or port-pr.sh itself, and that code would run on the operator's machine. Before it applies anything, the script now copies itself, port-pr-body.md, fill-template.sh and template.jq to port-src/<n>/trusted in the git directory, renders the body with that copy, and runs --fix-paths and --continue only from it; every stop prints the trusted command. hack/migration/port-pr-test.sh, also in workflows:check, ports a synthetic PR that replaces the renderer and checks that none of its code runs and that the working-tree entry points are refused. SDAChess found this in review.

hack/automation/fill-template-test.sh runs in workflows:check. It checks that placeholder text inside a value stays literal (no environment variable leaks, and a value naming its own placeholder does not loop; the test runs under a timeout), that several placeholders on one line are filled, that unknown placeholders and malformed arguments fail, and that each caller passes exactly the keys its template uses. With the old rescanning loop swapped back in, the test fails.

Tested with jq 1.7 (the Ubuntu runner's) and jq 1.8, and with bash 3.2; the rendered bump and port bodies are byte-identical to the previous renderer. shellcheck, actionlint, rpc-issues-test.sh and go test ./... pass.

@SDAChess SDAChess left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The single-pass jq renderer closes the reported token disclosure in open-bump-pr.sh. I verified offline that the body passed to gh preserves {{GH_TOKEN}} literally. The RPC planner also preserved placeholder text from upstream comments through --plan-input. Both test scripts ran and passed in the workflows job. The migration caller adds an execution path that crosses the upstream PR trust boundary.

Comment thread hack/migration/port-pr.sh Resolved
Comment thread hack/automation/fill-template-test.sh Resolved
SDAChess
SDAChess previously approved these changes Nov 27, 2026
The renderer scanned each line again after a substitution and looked
up any {{UPPER_CASE}} key in ENVIRON. Text inside an inserted value,
such as the upstream proto diff, could therefore pull in any variable
of the core-watch step, including GH_TOKEN, and publish it in the PR
body.

Substitute left to right and never rescan inserted text, and accept
only the keys the template uses. An unknown placeholder in the
template now fails the run.

Signed-off-by: Roland Huß <rhuss@redhat.com>
Move the single-pass renderer into fill-template.awk behind
fill-template.sh, which takes KEY=value arguments, so every placeholder
key is named once. hack/migration/port-pr.sh had the same rescanning
loop and inserts commit subjects and author names from the core PR; it
now uses the shared renderer too.

fill-template-test.sh, part of workflows:check, checks that placeholder
text in values stays literal (under a timeout, so a rescanning loop
fails), that unknown placeholders fail, and that both real templates
render completely.

Signed-off-by: Roland Huß <rhuss@redhat.com>
awk can only take the values through the environment, where they sit
next to the bot token, or through -v, which processes escape sequences.
Pass them to jq as --arg arguments instead and fill the template with
fill from the new template.jq module, a single gsub pass that never
rescans inserted text. rpc-issues.jq had the same function inline and
now includes the module.

fill now fails on a placeholder without a value instead of leaving it
in place; the only rpc-issues template call passes every key its
template uses.

Tests cover backslashes in values and a byte-exact render of a template
without placeholders.

Signed-off-by: Roland Huß <rhuss@redhat.com>
Once git am has applied the upstream patches, the working tree holds
the PR's files, and a PR could replace fill-template.sh, template.jq
or port-pr.sh itself, which then ran on the operator's machine during
the port or the --fix-paths and --continue steps.

Copy port-pr.sh, port-pr-body.md, fill-template.sh and template.jq to
port-src/<n>/trusted in the git directory before anything is applied,
render the PR body with that copy, and run --fix-paths and --continue
only from it; the script prints the trusted command at every stop.

port-pr-test.sh, part of workflows:check, ports a synthetic upstream PR
that replaces the renderer and checks that none of its code runs, that
the body stays literal, and that the working-tree entry points are
refused.

Signed-off-by: Roland Huß <rhuss@redhat.com>

@SDAChess SDAChess left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed the rebase at c51986a. The conflict resolution keeps the core auto-merge checks from main alongside the RPC, template, and migration tests. All commands in workflows:check passed locally. The renderer and trusted migration copy still address the original security findings.

@rhuss
rhuss merged commit d4be8b5 into main Nov 27, 2026
10 checks passed
@rhuss
rhuss deleted the fix/bump-pr-body-render branch November 27, 2026 17:07
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