Repository navigation
fix(automation): fill the bump PR body in a single pass - #77
Conversation
6f7b142 to
5b611a1
Compare
SDAChess
left a comment
There was a problem hiding this comment.
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.
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>
c511681 to
c51986a
Compare
SDAChess
left a comment
There was a problem hiding this comment.
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.
open-bump-pr.shfillsbump-pr-body.mdwith awk. After each substitution the loop scanned the whole line again, including the text it had just inserted, and resolved any{{UPPER_CASE}}key throughENVIRON. Upstream text in the proto diff that looks like a placeholder was therefore expanded from the core-watch step's environment, which holdsGH_TOKEN. SDAChess pointed this out in the review of #60.The renderer now lives in
fillinhack/automation/template.jq, called throughhack/automation/fill-template.sh, which takesKEY=valuearguments and passes them to jq as--argvalues. 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.jqhad the same function inline and now shares the module.hack/migration/port-pr.shhad 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: aftergit am, the working tree holds the upstream PR's files, so a PR could replace the renderer orport-pr.shitself, 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.shandtemplate.jqtoport-src/<n>/trustedin the git directory, renders the body with that copy, and runs--fix-pathsand--continueonly from it; every stop prints the trusted command.hack/migration/port-pr-test.sh, also inworkflows: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.shruns inworkflows: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.shandgo test ./...pass.