From d9dcdfe3b7be2091a2fefe793a0ffa1117fcd591 Mon Sep 17 00:00:00 2001 From: jtanner Date: Fri, 6 Nov 2026 09:10:08 -0500 Subject: [PATCH 1/8] feat(#9044)!: pass the gateway endpoint from repository variables Follow-up to #9049, per the design agreed with rh-hemartin: the dispatch workflow reads vars.OPENSHELL_GATEWAY_ENDPOINT and passes it to the agent action via a dedicated FULLSEND_OPENSHELL_GATEWAY_ENDPOINT channel, so an unset repository variable (rendered as an empty string) cannot shadow a value configured in the runner's own process environment. The action's detection prefers a non-empty workflow channel, falls back to the runner process environment, and publishes the resolved endpoint to GITHUB_ENV for the sandbox setup. Workflow env is the infrastructure-plumbing channel (ADR 0081); the runner-env detection remains as a documented fallback for fleet-managed runner images, with the workflow value taking precedence. Addresses #9044 Signed-off-by: jtanner --- .github/workflows/reusable-dispatch.yml | 11 +++++ action.yml | 20 ++++++++- docs/guides/infrastructure/advanced-setup.md | 13 ++++-- internal/scaffold/action_sandbox_host_test.go | 41 ++++++++++++++----- 4 files changed, 68 insertions(+), 17 deletions(-) diff --git a/.github/workflows/reusable-dispatch.yml b/.github/workflows/reusable-dispatch.yml index c63945eaa7..8e8aa82283 100644 --- a/.github/workflows/reusable-dispatch.yml +++ b/.github/workflows/reusable-dispatch.yml @@ -1514,6 +1514,11 @@ jobs: - name: Run triage agent uses: ./.defaults/ env: + # Remote OpenShell gateway endpoint from repository variables + # (#9044): passed via a dedicated channel so an unset variable + # (rendered as an empty string) does not shadow a value configured + # in the runner's own process environment. + FULLSEND_OPENSHELL_GATEWAY_ENDPOINT: ${{ vars.OPENSHELL_GATEWAY_ENDPOINT }} GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} FULLSEND_WORK_ITEM_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} REPO_FULL_NAME: ${{ github.repository }} @@ -1646,6 +1651,7 @@ jobs: - name: Run code agent uses: ./.defaults/ env: + FULLSEND_OPENSHELL_GATEWAY_ENDPOINT: ${{ vars.OPENSHELL_GATEWAY_ENDPOINT }} GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} FULLSEND_WORK_ITEM_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} FULLSEND_WORK_ITEM_KEY: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} @@ -1822,6 +1828,7 @@ jobs: - name: Run review agent uses: ./.defaults/ env: + FULLSEND_OPENSHELL_GATEWAY_ENDPOINT: ${{ vars.OPENSHELL_GATEWAY_ENDPOINT }} GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} FULLSEND_WORK_ITEM_URL: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.html_url || fromJSON(needs.route.outputs.event_payload).issue.html_url }} GITHUB_PR_URL: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.html_url || fromJSON(needs.route.outputs.event_payload).issue.html_url }} @@ -2091,6 +2098,7 @@ jobs: - name: Run fix agent uses: ./.defaults/ env: + FULLSEND_OPENSHELL_GATEWAY_ENDPOINT: ${{ vars.OPENSHELL_GATEWAY_ENDPOINT }} PR_NUMBER: ${{ steps.context.outputs.pr_number }} REPO_FULL_NAME: ${{ github.repository }} TARGET_BRANCH: ${{ steps.context.outputs.base_ref }} @@ -2209,6 +2217,7 @@ jobs: - name: Run retro agent uses: ./.defaults/ env: + FULLSEND_OPENSHELL_GATEWAY_ENDPOINT: ${{ vars.OPENSHELL_GATEWAY_ENDPOINT }} ORIGINATING_URL: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.html_url || fromJSON(needs.route.outputs.event_payload).issue.html_url }} RETRO_COMMENT: ${{ fromJSON(needs.route.outputs.event_payload).comment.body || '' }} REPO_FULL_NAME: ${{ github.repository }} @@ -2310,6 +2319,7 @@ jobs: - name: Run prioritize agent uses: ./.defaults/ env: + FULLSEND_OPENSHELL_GATEWAY_ENDPOINT: ${{ vars.OPENSHELL_GATEWAY_ENDPOINT }} GITHUB_ISSUE_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} FULLSEND_WORK_ITEM_URL: ${{ fromJSON(needs.route.outputs.event_payload).issue.html_url }} REPO_FULL_NAME: ${{ github.repository }} @@ -2691,6 +2701,7 @@ jobs: - name: Run harness agent uses: ./.defaults/ env: + FULLSEND_OPENSHELL_GATEWAY_ENDPOINT: ${{ vars.OPENSHELL_GATEWAY_ENDPOINT }} GITHUB_ISSUE_URL: ${{ steps.dispatch-env.outputs.issue_url }} FULLSEND_WORK_ITEM_URL: ${{ steps.dispatch-env.outputs.issue_url }} FULLSEND_WORK_ITEM_KEY: ${{ steps.dispatch-env.outputs.work_item_key }} diff --git a/action.yml b/action.yml index 83cc1fcaa3..127412f170 100644 --- a/action.yml +++ b/action.yml @@ -442,9 +442,25 @@ runs: shell: bash run: | set -euo pipefail - if [[ -n "${OPENSHELL_GATEWAY_ENDPOINT:-}" ]]; then - echo "OPENSHELL_GATEWAY_ENDPOINT is set: using the existing OpenShell gateway, skipping local Podman and gateway setup" + # The workflow layer (reusable-dispatch.yml) passes the gateway + # endpoint from repository variables as + # FULLSEND_OPENSHELL_GATEWAY_ENDPOINT. That channel wins when it is + # non-empty. An unset repository variable renders as an empty string + # and must not shadow a value configured in the runner's own process + # environment, so the fallback reads OPENSHELL_GATEWAY_ENDPOINT only + # when the workflow channel is empty (#9044). + endpoint="${FULLSEND_OPENSHELL_GATEWAY_ENDPOINT:-}" + if [[ -z "$endpoint" ]]; then + endpoint="${OPENSHELL_GATEWAY_ENDPOINT:-}" + fi + if [[ -n "$endpoint" ]]; then + echo "Using the OpenShell gateway at ${endpoint}; skipping local Podman and gateway setup" echo "local=false" >> "${GITHUB_OUTPUT}" + # The sandbox setup reads OPENSHELL_GATEWAY_ENDPOINT from the + # environment; publish the resolved value for the later steps. + if [[ -n "${GITHUB_ENV:-}" ]]; then + echo "OPENSHELL_GATEWAY_ENDPOINT=${endpoint}" >> "${GITHUB_ENV}" + fi if command -v openshell >/dev/null 2>&1; then echo "Using the preinstalled OpenShell CLI" echo "install-openshell=false" >> "${GITHUB_OUTPUT}" diff --git a/docs/guides/infrastructure/advanced-setup.md b/docs/guides/infrastructure/advanced-setup.md index 19acf4d9aa..23b28fc12c 100644 --- a/docs/guides/infrastructure/advanced-setup.md +++ b/docs/guides/infrastructure/advanced-setup.md @@ -106,10 +106,15 @@ configuration, and installs the OpenShell CLI. That suits GitHub-hosted runners, which start empty. A self-hosted runner can instead use an OpenShell gateway that runs -elsewhere. Set `OPENSHELL_GATEWAY_ENDPOINT` in the runner's environment to -that gateway's `https://` endpoint. When it is set, the action skips the -Podman installation, the rootless Podman configuration, and the local gateway -configuration, and sandboxes are created on the remote gateway. If the +elsewhere. Set the `OPENSHELL_GATEWAY_ENDPOINT` repository variable to that +gateway's `https://` endpoint; the dispatch workflow passes it to the agent +action. When it is set, the action skips the Podman installation, the +rootless Podman configuration, and the local gateway configuration, and +sandboxes are created on the remote gateway. A non-empty repository variable +takes precedence over a value configured in the runner's own process +environment, which remains supported as a fallback for fleet-managed runner +images: set `OPENSHELL_GATEWAY_ENDPOINT` in the runner's environment and it +applies whenever the repository variable is unset. If the `openshell` CLI is already on the runner's `PATH`, the action also skips the OpenShell CLI installer, which needs `sudo` and starts a local gateway service. Install the CLI version pinned in diff --git a/internal/scaffold/action_sandbox_host_test.go b/internal/scaffold/action_sandbox_host_test.go index 210a34e18a..963f12176f 100644 --- a/internal/scaffold/action_sandbox_host_test.go +++ b/internal/scaffold/action_sandbox_host_test.go @@ -40,8 +40,10 @@ func loadRootActionSteps(t *testing.T) map[string]actionStep { // runDetectSandboxHost runs the "Detect sandbox host" step script with only // pathDir on PATH and returns the outputs it wrote to GITHUB_OUTPUT. When -// endpoint is nil, OPENSHELL_GATEWAY_ENDPOINT is left unset. -func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir string) map[string]string { +// endpoint is nil, OPENSHELL_GATEWAY_ENDPOINT is left unset; when +// workflowEndpoint is non-nil, FULLSEND_OPENSHELL_GATEWAY_ENDPOINT is set to +// it (the channel the dispatch workflow passes from repository variables). +func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir string, workflowEndpoint *string) (map[string]string, map[string]string) { t.Helper() bash, err := exec.LookPath("bash") require.NoError(t, err) @@ -51,25 +53,33 @@ func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir require.NoError(t, os.WriteFile(scriptPath, []byte(script), 0o600)) outputPath := filepath.Join(dir, "github_output") require.NoError(t, os.WriteFile(outputPath, nil, 0o600)) + envPath := filepath.Join(dir, "github_env") + require.NoError(t, os.WriteFile(envPath, nil, 0o600)) - env := []string{"PATH=" + pathDir, "GITHUB_OUTPUT=" + outputPath} + env := []string{"PATH=" + pathDir, "GITHUB_OUTPUT=" + outputPath, "GITHUB_ENV=" + envPath} if endpoint != nil { env = append(env, "OPENSHELL_GATEWAY_ENDPOINT="+*endpoint) } + if workflowEndpoint != nil { + env = append(env, "FULLSEND_OPENSHELL_GATEWAY_ENDPOINT="+*workflowEndpoint) + } cmd := exec.Command(bash, scriptPath) cmd.Env = env out, err := cmd.CombinedOutput() require.NoError(t, err, string(out)) - raw, err := os.ReadFile(outputPath) - require.NoError(t, err) - outputs := map[string]string{} - for line := range strings.SplitSeq(strings.TrimSpace(string(raw)), "\n") { - if k, v, ok := strings.Cut(line, "="); ok { - outputs[k] = v + parse := func(path string) map[string]string { + raw, err := os.ReadFile(path) + require.NoError(t, err) + parsed := map[string]string{} + for line := range strings.SplitSeq(strings.TrimSpace(string(raw)), "\n") { + if k, v, ok := strings.Cut(line, "="); ok { + parsed[k] = v + } } + return parsed } - return outputs + return parse(outputPath), parse(envPath) } func TestActionDetectSandboxHostStep(t *testing.T) { @@ -85,24 +95,33 @@ func TestActionDetectSandboxHostStep(t *testing.T) { empty := "" remote := "https://gateway.example:8080" + other := "https://other-gateway.example:8080" cases := []struct { name string endpoint *string + workflowEndpoint *string pathDir string wantLocal string wantInstallShell string + wantEndpoint string }{ {name: "endpoint unset sets up a local sandbox host", pathDir: withCLI, wantLocal: "true", wantInstallShell: "true"}, {name: "empty endpoint sets up a local sandbox host", endpoint: &empty, pathDir: withCLI, wantLocal: "true", wantInstallShell: "true"}, {name: "endpoint set with preinstalled CLI skips all local setup", endpoint: &remote, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false"}, {name: "endpoint set without CLI still installs the CLI", endpoint: &remote, pathDir: emptyPath, wantLocal: "false", wantInstallShell: "true"}, + {name: "workflow channel wins over the runner environment", endpoint: &remote, workflowEndpoint: &other, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false", wantEndpoint: other}, + {name: "empty workflow channel falls back to the runner environment", endpoint: &remote, workflowEndpoint: &empty, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false", wantEndpoint: remote}, + {name: "workflow channel alone skips local setup", workflowEndpoint: &remote, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false", wantEndpoint: remote}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { - outputs := runDetectSandboxHost(t, detect.Run, tc.endpoint, tc.pathDir) + outputs, envWrites := runDetectSandboxHost(t, detect.Run, tc.endpoint, tc.pathDir, tc.workflowEndpoint) assert.Equal(t, tc.wantLocal, outputs["local"]) assert.Equal(t, tc.wantInstallShell, outputs["install-openshell"]) + if tc.wantEndpoint != "" { + assert.Equal(t, tc.wantEndpoint, envWrites["OPENSHELL_GATEWAY_ENDPOINT"]) + } }) } } From 3833fd52140bdae6662b99f130b26a7afa9ca289 Mon Sep 17 00:00:00 2001 From: jtanner Date: Fri, 6 Nov 2026 09:21:16 -0500 Subject: [PATCH 2/8] fix(#9044)!: validate the gateway endpoint and rank the repository variable Review follow-up (Claude Sonnet 5.5 + Codex gpt-6.1 cross-review): - The standalone reusable-prioritize.yml also invokes the agent action; pass the repository-variable channel there too (missed call site). - Reject endpoints that are not a single https:// URL with no whitespace before logging or writing them to GITHUB_ENV: a newline in the value would become a separate assignment for later steps, and whitespace-only configuration would silently suppress the runner-environment fallback. - Log the endpoint's source channel, not its value (repository variables are not masked in public logs). - Tests: propagation is now asserted unconditionally (remote cases must publish the resolved endpoint, local cases must write nothing), the runner-only cases assert the published value, and rejection cases cover whitespace-only, newline-injected, and non-https endpoints. - Docs: organization variables apply too; the precedence is stated as deliberate (repository administrators choose the gateway for their runs); the single-URL requirement is documented. BREAKING CHANGE: the sandbox-host detection now rejects an endpoint that is not a single https:// URL with no whitespace, where any non-empty value was previously accepted. Runner environments configured with a plaintext http:// endpoint, a value with no scheme, or an uppercase scheme must switch to an https:// URL; gateways that serve only plaintext are no longer supported through this path. The no-whitespace rule keeps GITHUB_ENV injection out either way. Separately, a non-empty repository or organization variable OPENSHELL_GATEWAY_ENDPOINT now takes precedence over a value configured in the runner's own process environment; consumers who already hold a variable with this name will see their routing change. Signed-off-by: jtanner --- .github/workflows/reusable-prioritize.yml | 5 +++ action.yml | 25 ++++++++++---- docs/guides/infrastructure/advanced-setup.md | 21 +++++++----- internal/scaffold/action_sandbox_host_test.go | 34 +++++++++++++++---- 4 files changed, 64 insertions(+), 21 deletions(-) diff --git a/.github/workflows/reusable-prioritize.yml b/.github/workflows/reusable-prioritize.yml index 28e4dccbad..846fe0a7cc 100644 --- a/.github/workflows/reusable-prioritize.yml +++ b/.github/workflows/reusable-prioritize.yml @@ -173,6 +173,11 @@ jobs: - name: Run prioritize agent uses: ./.defaults/ env: + # Remote OpenShell gateway endpoint from repository variables + # (#9044): passed via a dedicated channel so an unset variable + # (rendered as an empty string) does not shadow a value configured + # in the runner's own process environment. + FULLSEND_OPENSHELL_GATEWAY_ENDPOINT: ${{ vars.OPENSHELL_GATEWAY_ENDPOINT }} GITHUB_ISSUE_URL: ${{ fromJSON(inputs.event_payload).issue.html_url }} REPO_FULL_NAME: ${{ inputs.source_repo }} OTEL_EXPORTER_OTLP_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_ENDPOINT }} diff --git a/action.yml b/action.yml index 127412f170..da3d593432 100644 --- a/action.yml +++ b/action.yml @@ -432,11 +432,13 @@ runs: shell: bash run: fullsend --version - # A runner that sets OPENSHELL_GATEWAY_ENDPOINT uses an OpenShell gateway - # that runs elsewhere. Sandboxes are created on that gateway, so the - # runner needs no Podman and no local gateway (#9044). This step reads the - # runner process environment: the `env` context in an `if:` holds only - # workflow, job and step variables, not the runner's own environment. + # A remote OpenShell gateway runs elsewhere; sandboxes are created on + # it, so the runner needs no Podman and no local gateway (#9044). The + # endpoint comes from the repository variable the dispatch workflow + # passes as FULLSEND_OPENSHELL_GATEWAY_ENDPOINT, or, when that is unset, + # from the runner's own process environment: the `env` context in an + # `if:` holds only workflow, job and step variables, not the runner's + # own environment. - name: Detect sandbox host id: sandbox-host shell: bash @@ -450,11 +452,22 @@ runs: # environment, so the fallback reads OPENSHELL_GATEWAY_ENDPOINT only # when the workflow channel is empty (#9044). endpoint="${FULLSEND_OPENSHELL_GATEWAY_ENDPOINT:-}" + endpoint_source="repository variable" if [[ -z "$endpoint" ]]; then endpoint="${OPENSHELL_GATEWAY_ENDPOINT:-}" + endpoint_source="runner environment" fi if [[ -n "$endpoint" ]]; then - echo "Using the OpenShell gateway at ${endpoint}; skipping local Podman and gateway setup" + # The value is written to GITHUB_ENV below, where a newline would + # become a separate assignment for later steps, so it must be a + # single https:// URL with no whitespace. This also rejects + # whitespace-only configuration, which would otherwise suppress + # the fallback and select an unusable remote mode. + if [[ ! "$endpoint" =~ ^https://[^[:space:]]+$ ]]; then + echo "::error::OPENSHELL_GATEWAY_ENDPOINT must be a single https:// URL with no whitespace (got ${#endpoint} characters from ${endpoint_source})" + exit 1 + fi + echo "Using the OpenShell gateway (from ${endpoint_source}); skipping local Podman and gateway setup" echo "local=false" >> "${GITHUB_OUTPUT}" # The sandbox setup reads OPENSHELL_GATEWAY_ENDPOINT from the # environment; publish the resolved value for the later steps. diff --git a/docs/guides/infrastructure/advanced-setup.md b/docs/guides/infrastructure/advanced-setup.md index 23b28fc12c..1b626ea1de 100644 --- a/docs/guides/infrastructure/advanced-setup.md +++ b/docs/guides/infrastructure/advanced-setup.md @@ -106,15 +106,18 @@ configuration, and installs the OpenShell CLI. That suits GitHub-hosted runners, which start empty. A self-hosted runner can instead use an OpenShell gateway that runs -elsewhere. Set the `OPENSHELL_GATEWAY_ENDPOINT` repository variable to that -gateway's `https://` endpoint; the dispatch workflow passes it to the agent -action. When it is set, the action skips the Podman installation, the -rootless Podman configuration, and the local gateway configuration, and -sandboxes are created on the remote gateway. A non-empty repository variable -takes precedence over a value configured in the runner's own process -environment, which remains supported as a fallback for fleet-managed runner -images: set `OPENSHELL_GATEWAY_ENDPOINT` in the runner's environment and it -applies whenever the repository variable is unset. If the +elsewhere. Set the `OPENSHELL_GATEWAY_ENDPOINT` repository (or organization) +variable in the repository being dispatched to that gateway's `https://` +endpoint; the dispatch workflow passes it to the agent action. When it is +set, the action skips the Podman installation, the rootless Podman +configuration, and the local gateway configuration, and sandboxes are created +on the remote gateway. A non-empty repository variable deliberately takes +precedence over a value configured in the runner's own process environment: +repository administrators choose the gateway for their runs. The runner +environment remains supported as a fallback for fleet-managed runner images — +set `OPENSHELL_GATEWAY_ENDPOINT` in the runner's environment and it applies +whenever the repository variable is unset. The value must be a single +`https://` URL with no whitespace. If the `openshell` CLI is already on the runner's `PATH`, the action also skips the OpenShell CLI installer, which needs `sudo` and starts a local gateway service. Install the CLI version pinned in diff --git a/internal/scaffold/action_sandbox_host_test.go b/internal/scaffold/action_sandbox_host_test.go index 963f12176f..15eeccb04f 100644 --- a/internal/scaffold/action_sandbox_host_test.go +++ b/internal/scaffold/action_sandbox_host_test.go @@ -1,6 +1,7 @@ package scaffold import ( + "fmt" "os" "os/exec" "path/filepath" @@ -43,7 +44,7 @@ func loadRootActionSteps(t *testing.T) map[string]actionStep { // endpoint is nil, OPENSHELL_GATEWAY_ENDPOINT is left unset; when // workflowEndpoint is non-nil, FULLSEND_OPENSHELL_GATEWAY_ENDPOINT is set to // it (the channel the dispatch workflow passes from repository variables). -func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir string, workflowEndpoint *string) (map[string]string, map[string]string) { +func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir string, workflowEndpoint *string) (map[string]string, map[string]string, error) { t.Helper() bash, err := exec.LookPath("bash") require.NoError(t, err) @@ -66,7 +67,9 @@ func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir cmd := exec.Command(bash, scriptPath) cmd.Env = env out, err := cmd.CombinedOutput() - require.NoError(t, err, string(out)) + if err != nil { + return nil, nil, fmt.Errorf("%w: %s", err, out) + } parse := func(path string) map[string]string { raw, err := os.ReadFile(path) @@ -79,7 +82,7 @@ func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir } return parsed } - return parse(outputPath), parse(envPath) + return parse(outputPath), parse(envPath), nil } func TestActionDetectSandboxHostStep(t *testing.T) { @@ -96,6 +99,9 @@ func TestActionDetectSandboxHostStep(t *testing.T) { empty := "" remote := "https://gateway.example:8080" other := "https://other-gateway.example:8080" + whitespace := " " + injected := "https://gateway.example\nBASH_ENV=/tmp/x" + httpEndpoint := "http://gateway.example:8080" cases := []struct { name string @@ -105,22 +111,38 @@ func TestActionDetectSandboxHostStep(t *testing.T) { wantLocal string wantInstallShell string wantEndpoint string + wantErr bool }{ {name: "endpoint unset sets up a local sandbox host", pathDir: withCLI, wantLocal: "true", wantInstallShell: "true"}, {name: "empty endpoint sets up a local sandbox host", endpoint: &empty, pathDir: withCLI, wantLocal: "true", wantInstallShell: "true"}, - {name: "endpoint set with preinstalled CLI skips all local setup", endpoint: &remote, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false"}, - {name: "endpoint set without CLI still installs the CLI", endpoint: &remote, pathDir: emptyPath, wantLocal: "false", wantInstallShell: "true"}, + {name: "endpoint set with preinstalled CLI skips all local setup", endpoint: &remote, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false", wantEndpoint: remote}, + {name: "endpoint set without CLI still installs the CLI", endpoint: &remote, pathDir: emptyPath, wantLocal: "false", wantInstallShell: "true", wantEndpoint: remote}, {name: "workflow channel wins over the runner environment", endpoint: &remote, workflowEndpoint: &other, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false", wantEndpoint: other}, {name: "empty workflow channel falls back to the runner environment", endpoint: &remote, workflowEndpoint: &empty, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false", wantEndpoint: remote}, {name: "workflow channel alone skips local setup", workflowEndpoint: &remote, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false", wantEndpoint: remote}, + {name: "empty workflow channel and no runner endpoint sets up locally", workflowEndpoint: &empty, pathDir: withCLI, wantLocal: "true", wantInstallShell: "true"}, + {name: "whitespace-only endpoint is rejected", workflowEndpoint: &whitespace, pathDir: withCLI, wantErr: true}, + {name: "newline-injected endpoint is rejected", workflowEndpoint: &injected, pathDir: withCLI, wantErr: true}, + {name: "non-https endpoint is rejected", workflowEndpoint: &httpEndpoint, pathDir: withCLI, wantErr: true}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { - outputs, envWrites := runDetectSandboxHost(t, detect.Run, tc.endpoint, tc.pathDir, tc.workflowEndpoint) + outputs, envWrites, err := runDetectSandboxHost(t, detect.Run, tc.endpoint, tc.pathDir, tc.workflowEndpoint) + if tc.wantErr { + require.Error(t, err, string([]rune{})) + assert.NotNil(t, err) + return + } + require.NoError(t, err) assert.Equal(t, tc.wantLocal, outputs["local"]) assert.Equal(t, tc.wantInstallShell, outputs["install-openshell"]) + // The propagation is asserted unconditionally: remote cases must + // publish the resolved endpoint, local cases must write nothing. if tc.wantEndpoint != "" { assert.Equal(t, tc.wantEndpoint, envWrites["OPENSHELL_GATEWAY_ENDPOINT"]) + } else { + _, wrote := envWrites["OPENSHELL_GATEWAY_ENDPOINT"] + assert.False(t, wrote, "local setup must not publish a gateway endpoint") } }) } From 55a1b79ab114509b5ae61da1ae3713a2c17597df Mon Sep 17 00:00:00 2001 From: jtanner Date: Mon, 9 Nov 2026 21:01:17 -0500 Subject: [PATCH 3/8] fix(#9044): address review follow-ups on the gateway endpoint docs and test Review follow-ups on #9158: - The gateway setup steps were buried in one narrative paragraph; the guide now uses a numbered list, and names the repository the variable is read from: in a reusable workflow, `vars` comes from the calling workflow's repository (the repository with the fullsend shim, or the .fullsend config repository for prioritize, poller and harness-matrix runs), not the work-item repository. A variable set on the work-item repository is not read and fails silently, so the guide says so. - Drop a synthetic empty message and a redundant assertion in the sandbox-host detection test: require.Error(t, err) alone. Signed-off-by: jtanner --- docs/guides/infrastructure/advanced-setup.md | 43 ++++++++++++------- internal/scaffold/action_sandbox_host_test.go | 3 +- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/docs/guides/infrastructure/advanced-setup.md b/docs/guides/infrastructure/advanced-setup.md index 1b626ea1de..7e96f60663 100644 --- a/docs/guides/infrastructure/advanced-setup.md +++ b/docs/guides/infrastructure/advanced-setup.md @@ -106,21 +106,34 @@ configuration, and installs the OpenShell CLI. That suits GitHub-hosted runners, which start empty. A self-hosted runner can instead use an OpenShell gateway that runs -elsewhere. Set the `OPENSHELL_GATEWAY_ENDPOINT` repository (or organization) -variable in the repository being dispatched to that gateway's `https://` -endpoint; the dispatch workflow passes it to the agent action. When it is -set, the action skips the Podman installation, the rootless Podman -configuration, and the local gateway configuration, and sandboxes are created -on the remote gateway. A non-empty repository variable deliberately takes -precedence over a value configured in the runner's own process environment: -repository administrators choose the gateway for their runs. The runner -environment remains supported as a fallback for fleet-managed runner images — -set `OPENSHELL_GATEWAY_ENDPOINT` in the runner's environment and it applies -whenever the repository variable is unset. The value must be a single -`https://` URL with no whitespace. If the -`openshell` CLI is already on the runner's `PATH`, the action also skips the -OpenShell CLI installer, which needs `sudo` and starts a local gateway -service. Install the CLI version pinned in +elsewhere. Configure the endpoint in one of these ways: + +1. Set the `OPENSHELL_GATEWAY_ENDPOINT` repository (or organization) + variable to the gateway's `https://` endpoint, on the repository where + the workflow run is triggered (the one whose Actions tab shows the + run); the dispatch workflow passes it to the agent action. In a + reusable workflow, `vars` is read from that calling repository, not + from the repository holding the issue or pull request. For the + standard per-repo install the calling repository is the work-item + repository itself; for runs driven from the `.fullsend` config + repository (prioritize, poller and harness-matrix runs) it is the + config repository. An organization variable visible to the calling + repository also works. When the run starts from a different repository + than the work item, a variable set only on the work-item repository is + not read. +2. As a fallback, for fleet-managed runner images, set + `OPENSHELL_GATEWAY_ENDPOINT` in the runner's own process environment; + it applies whenever the variable from step 1 is unset. + +When an endpoint is configured, the action skips the Podman installation, +the rootless Podman configuration, and the local gateway configuration, +and sandboxes are created on the remote gateway. A non-empty repository +or organization variable deliberately takes precedence over a value +configured in the runner's process environment: repository +administrators choose the gateway for their runs. The value must be a single `https://` URL with no +whitespace. If the `openshell` CLI is already on the runner's `PATH`, the +action also skips the OpenShell CLI installer, which needs `sudo` and +starts a local gateway service. Install the CLI version pinned in `.github/scripts/openshell-version.sh` in the runner image. The action also needs the Python `jsonschema` package to validate agent diff --git a/internal/scaffold/action_sandbox_host_test.go b/internal/scaffold/action_sandbox_host_test.go index 15eeccb04f..281ed7d56a 100644 --- a/internal/scaffold/action_sandbox_host_test.go +++ b/internal/scaffold/action_sandbox_host_test.go @@ -129,8 +129,7 @@ func TestActionDetectSandboxHostStep(t *testing.T) { t.Run(tc.name, func(t *testing.T) { outputs, envWrites, err := runDetectSandboxHost(t, detect.Run, tc.endpoint, tc.pathDir, tc.workflowEndpoint) if tc.wantErr { - require.Error(t, err, string([]rune{})) - assert.NotNil(t, err) + require.Error(t, err) return } require.NoError(t, err) From 1c7e18f169d6b9d3542f33f0e269e83fc830b3f9 Mon Sep 17 00:00:00 2001 From: jtanner Date: Tue, 10 Nov 2026 20:11:16 -0500 Subject: [PATCH 4/8] fix(#9044): document the gateway registration prerequisite Review follow-up: the guide read as if setting the variable was all an installation needed. OpenShell matches the configured endpoint against the gateways registered on the runner (openshell gateway add, which stores the mTLS or authentication material), and a value that does not match a registered endpoint makes the sandbox fail later at the TLS or authentication handshake, with an error that does not point at the cause. The section now says the gateway must already be registered and that the variable must repeat the registered endpoint exactly. Signed-off-by: jtanner --- docs/guides/infrastructure/advanced-setup.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/guides/infrastructure/advanced-setup.md b/docs/guides/infrastructure/advanced-setup.md index 7e96f60663..31462891e8 100644 --- a/docs/guides/infrastructure/advanced-setup.md +++ b/docs/guides/infrastructure/advanced-setup.md @@ -127,11 +127,20 @@ elsewhere. Configure the endpoint in one of these ways: When an endpoint is configured, the action skips the Podman installation, the rootless Podman configuration, and the local gateway configuration, -and sandboxes are created on the remote gateway. A non-empty repository +and sandboxes are created on the remote gateway. The gateway must +already be registered on the runner: `openshell gateway add` stores the +gateway's mTLS or authentication material, and the action never +registers a gateway itself. Set the variable to the endpoint exactly as +it was registered — OpenShell matches the configured endpoint against +the registered gateways, and a value that does not match (for example +`https://gw:443` where `https://gw` is registered) makes the sandbox +fail later at the TLS or authentication handshake, with an error that +does not point at the mismatch. The runner operator who registered the +gateway can confirm the exact registered value. A non-empty repository or organization variable deliberately takes precedence over a value configured in the runner's process environment: repository -administrators choose the gateway for their runs. The value must be a single `https://` URL with no -whitespace. If the `openshell` CLI is already on the runner's `PATH`, the +administrators choose the gateway for their runs. The value must be a +single `https://` URL with no whitespace. If the `openshell` CLI is already on the runner's `PATH`, the action also skips the OpenShell CLI installer, which needs `sudo` and starts a local gateway service. Install the CLI version pinned in `.github/scripts/openshell-version.sh` in the runner image. From 62cf90a351eefe56dd239946d8c50c9eacfd2fb3 Mon Sep 17 00:00:00 2001 From: jtanner Date: Thu, 12 Nov 2026 09:10:50 -0500 Subject: [PATCH 5/8] fix(#9044): assert what the endpoint rejection tests actually reject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review follow-up: the wantErr branch accepted any non-zero exit, so the whitespace, newline-injection and non-https cases would also have passed if the script had failed for an unrelated reason (a syntax error, a missing tool on the restricted PATH). runDetectSandboxHost now returns the combined output and the parsed GITHUB_ENV/GITHUB_OUTPUT maps on failure too, and the rejection cases assert the step's own validation error is printed and that nothing is published to GITHUB_ENV or GITHUB_OUTPUT — the property the newline guard exists to protect. The runner-environment fallback channel, which turns a bad value that used to be accepted into a hard failure, now has its own rejection cases instead of only the workflow channel. Signed-off-by: jtanner --- internal/scaffold/action_sandbox_host_test.go | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/internal/scaffold/action_sandbox_host_test.go b/internal/scaffold/action_sandbox_host_test.go index 281ed7d56a..704c7aa99f 100644 --- a/internal/scaffold/action_sandbox_host_test.go +++ b/internal/scaffold/action_sandbox_host_test.go @@ -40,11 +40,14 @@ func loadRootActionSteps(t *testing.T) map[string]actionStep { } // runDetectSandboxHost runs the "Detect sandbox host" step script with only -// pathDir on PATH and returns the outputs it wrote to GITHUB_OUTPUT. When -// endpoint is nil, OPENSHELL_GATEWAY_ENDPOINT is left unset; when -// workflowEndpoint is non-nil, FULLSEND_OPENSHELL_GATEWAY_ENDPOINT is set to -// it (the channel the dispatch workflow passes from repository variables). -func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir string, workflowEndpoint *string) (map[string]string, map[string]string, error) { +// pathDir on PATH and returns its combined output, the values it wrote to +// GITHUB_OUTPUT and GITHUB_ENV, and the command error. The maps are returned +// on failure too, so rejection cases can assert what the step did and did +// not write. When endpoint is nil, OPENSHELL_GATEWAY_ENDPOINT is left unset; +// when workflowEndpoint is non-nil, FULLSEND_OPENSHELL_GATEWAY_ENDPOINT is +// set to it (the channel the dispatch workflow passes from repository +// variables). +func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir string, workflowEndpoint *string) (string, map[string]string, map[string]string, error) { t.Helper() bash, err := exec.LookPath("bash") require.NoError(t, err) @@ -67,13 +70,10 @@ func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir cmd := exec.Command(bash, scriptPath) cmd.Env = env out, err := cmd.CombinedOutput() - if err != nil { - return nil, nil, fmt.Errorf("%w: %s", err, out) - } parse := func(path string) map[string]string { - raw, err := os.ReadFile(path) - require.NoError(t, err) + raw, readErr := os.ReadFile(path) + require.NoError(t, readErr) parsed := map[string]string{} for line := range strings.SplitSeq(strings.TrimSpace(string(raw)), "\n") { if k, v, ok := strings.Cut(line, "="); ok { @@ -82,7 +82,11 @@ func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir } return parsed } - return parse(outputPath), parse(envPath), nil + outputs, envWrites := parse(outputPath), parse(envPath) + if err != nil { + return string(out), outputs, envWrites, fmt.Errorf("%w: %s", err, out) + } + return string(out), outputs, envWrites, nil } func TestActionDetectSandboxHostStep(t *testing.T) { @@ -121,15 +125,26 @@ func TestActionDetectSandboxHostStep(t *testing.T) { {name: "empty workflow channel falls back to the runner environment", endpoint: &remote, workflowEndpoint: &empty, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false", wantEndpoint: remote}, {name: "workflow channel alone skips local setup", workflowEndpoint: &remote, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false", wantEndpoint: remote}, {name: "empty workflow channel and no runner endpoint sets up locally", workflowEndpoint: &empty, pathDir: withCLI, wantLocal: "true", wantInstallShell: "true"}, - {name: "whitespace-only endpoint is rejected", workflowEndpoint: &whitespace, pathDir: withCLI, wantErr: true}, - {name: "newline-injected endpoint is rejected", workflowEndpoint: &injected, pathDir: withCLI, wantErr: true}, - {name: "non-https endpoint is rejected", workflowEndpoint: &httpEndpoint, pathDir: withCLI, wantErr: true}, + {name: "whitespace-only workflow endpoint is rejected", workflowEndpoint: &whitespace, pathDir: withCLI, wantErr: true}, + {name: "newline-injected workflow endpoint is rejected", workflowEndpoint: &injected, pathDir: withCLI, wantErr: true}, + {name: "non-https workflow endpoint is rejected", workflowEndpoint: &httpEndpoint, pathDir: withCLI, wantErr: true}, + {name: "whitespace-only runner endpoint is rejected", endpoint: &whitespace, pathDir: withCLI, wantErr: true}, + {name: "newline-injected runner endpoint is rejected", endpoint: &injected, pathDir: withCLI, wantErr: true}, + {name: "non-https runner endpoint is rejected", endpoint: &httpEndpoint, pathDir: withCLI, wantErr: true}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { - outputs, envWrites, err := runDetectSandboxHost(t, detect.Run, tc.endpoint, tc.pathDir, tc.workflowEndpoint) + out, outputs, envWrites, err := runDetectSandboxHost(t, detect.Run, tc.endpoint, tc.pathDir, tc.workflowEndpoint) if tc.wantErr { + // A rejection must be the step's own validation failing, not + // any non-zero exit: the error annotation is printed, and + // nothing is published to GITHUB_ENV or GITHUB_OUTPUT. require.Error(t, err) + assert.Contains(t, out, "::error::OPENSHELL_GATEWAY_ENDPOINT must be a single https:// URL") + _, wrote := envWrites["OPENSHELL_GATEWAY_ENDPOINT"] + assert.False(t, wrote, "a rejected endpoint must not be published to GITHUB_ENV") + _, decided := outputs["local"] + assert.False(t, decided, "a rejected endpoint must not produce a sandbox-host decision") return } require.NoError(t, err) From cdea0dbedaa4a59ed7f898d825860ff89f72ae4d Mon Sep 17 00:00:00 2001 From: jtanner Date: Sun, 15 Nov 2026 12:18:11 -0500 Subject: [PATCH 6/8] fix(#9044): qualify the gateway matching docs and reject plaintext explicitly Review follow-up: OpenShell matches the configured endpoint against the registered gateways only when OPENSHELL_GATEWAY is not set on the runner. When a fleet image sets it, the named gateway's registered material is used with whatever endpoint the variable holds, so on a shared runner pool a repository variable from any one repository decides where that gateway is used. The guide now says both, and states that plaintext http:// gateways are rejected (the breaking-change note on the validating commit). Signed-off-by: jtanner --- docs/guides/infrastructure/advanced-setup.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/guides/infrastructure/advanced-setup.md b/docs/guides/infrastructure/advanced-setup.md index 31462891e8..e7f1ce1067 100644 --- a/docs/guides/infrastructure/advanced-setup.md +++ b/docs/guides/infrastructure/advanced-setup.md @@ -131,11 +131,17 @@ and sandboxes are created on the remote gateway. The gateway must already be registered on the runner: `openshell gateway add` stores the gateway's mTLS or authentication material, and the action never registers a gateway itself. Set the variable to the endpoint exactly as -it was registered — OpenShell matches the configured endpoint against -the registered gateways, and a value that does not match (for example -`https://gw:443` where `https://gw` is registered) makes the sandbox -fail later at the TLS or authentication handshake, with an error that -does not point at the mismatch. The runner operator who registered the +it was registered, as an `https://` URL — plaintext `http://` gateways +are rejected. When `OPENSHELL_GATEWAY` is not set on the runner, +OpenShell matches the configured endpoint against the registered +gateways, and a value that does not match (for example `https://gw:443` +where `https://gw` is registered) makes the sandbox fail later at the +TLS or authentication handshake, with an error that does not point at +the mismatch. When a fleet image sets `OPENSHELL_GATEWAY`, no endpoint +matching happens: the named gateway's registered material is used with +whatever endpoint the variable holds, so on a runner pool shared across +repositories, a repository variable from any one repository decides +where that gateway is used. The runner operator who registered the gateway can confirm the exact registered value. A non-empty repository or organization variable deliberately takes precedence over a value configured in the runner's process environment: repository From 107ce7a169a300d09b10ee01176d227e75c75348 Mon Sep 17 00:00:00 2001 From: jtanner Date: Mon, 16 Nov 2026 09:56:22 -0500 Subject: [PATCH 7/8] fix(#9044): split the gateway docs and pin the no-logging rule with tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review follow-ups: - The gateway section had grown back into a single block; it is now short labelled paragraphs (what is skipped, registration, endpoint matching with and without OPENSHELL_GATEWAY, precedence and validation, shared runner pools, CLI preinstall for remote-gateway runners), the over-long line is rewrapped, and the mismatch failure quotes the actual OpenShell error (failed to read TLS CA under a gateways//mtls path) instead of describing a TLS or authentication handshake. The shared-pool warning names the OPENSHELL_GATEWAY precondition and says each repository's variable steers its own runs, and the migration note in the fallback item is version-agnostic and covers uppercase schemes. - The tests now assert that every endpoint value the case supplied — including the losing channel's value in the precedence case, and each line of a newline-injected value — never appears in the step's output, and that the success log names the channel the endpoint came from, so a future echo of the value cannot regress the redaction silently. Signed-off-by: jtanner --- docs/guides/infrastructure/advanced-setup.md | 58 ++++++++++++------- internal/scaffold/action_sandbox_host_test.go | 24 ++++++++ 2 files changed, 61 insertions(+), 21 deletions(-) diff --git a/docs/guides/infrastructure/advanced-setup.md b/docs/guides/infrastructure/advanced-setup.md index e7f1ce1067..7915ea0837 100644 --- a/docs/guides/infrastructure/advanced-setup.md +++ b/docs/guides/infrastructure/advanced-setup.md @@ -123,32 +123,48 @@ elsewhere. Configure the endpoint in one of these ways: not read. 2. As a fallback, for fleet-managed runner images, set `OPENSHELL_GATEWAY_ENDPOINT` in the runner's own process environment; - it applies whenever the variable from step 1 is unset. + it applies whenever the variable from step 1 is unset. The same rule + holds on this channel: the value must be a single `https://` URL with + no whitespace. Earlier releases accepted any non-empty value here, so + plaintext, scheme-less or uppercase-scheme runner values must be + migrated to lowercase `https://` URLs. When an endpoint is configured, the action skips the Podman installation, the rootless Podman configuration, and the local gateway configuration, -and sandboxes are created on the remote gateway. The gateway must -already be registered on the runner: `openshell gateway add` stores the -gateway's mTLS or authentication material, and the action never -registers a gateway itself. Set the variable to the endpoint exactly as -it was registered, as an `https://` URL — plaintext `http://` gateways -are rejected. When `OPENSHELL_GATEWAY` is not set on the runner, -OpenShell matches the configured endpoint against the registered -gateways, and a value that does not match (for example `https://gw:443` -where `https://gw` is registered) makes the sandbox fail later at the -TLS or authentication handshake, with an error that does not point at +and sandboxes are created on the remote gateway. + +**Registration.** The gateway must already be registered on the runner: +`openshell gateway add` stores the gateway's mTLS or authentication +material, and the action never registers a gateway itself. Set the +variable to the endpoint exactly as it was registered, as an `https://` +URL — plaintext `http://` gateways are rejected. The runner operator who +registered the gateway can confirm the exact registered value. + +**Endpoint matching.** When `OPENSHELL_GATEWAY` is not set on the +runner, OpenShell matches the configured endpoint against the registered +gateways. A value that does not match (for example `https://gw:443` +where `https://gw` is registered) is used as a gateway name instead, and +the sandbox fails with `failed to read TLS CA` under a +`gateways/https___gw_443/mtls` path — an error that does not point at the mismatch. When a fleet image sets `OPENSHELL_GATEWAY`, no endpoint matching happens: the named gateway's registered material is used with -whatever endpoint the variable holds, so on a runner pool shared across -repositories, a repository variable from any one repository decides -where that gateway is used. The runner operator who registered the -gateway can confirm the exact registered value. A non-empty repository -or organization variable deliberately takes precedence over a value -configured in the runner's process environment: repository -administrators choose the gateway for their runs. The value must be a -single `https://` URL with no whitespace. If the `openshell` CLI is already on the runner's `PATH`, the -action also skips the OpenShell CLI installer, which needs `sudo` and -starts a local gateway service. Install the CLI version pinned in +whatever endpoint the variable holds. + +**Precedence and validation.** A non-empty repository or organization +variable deliberately takes precedence over a value configured in the +runner's process environment: repository administrators choose the +gateway for their runs. Whatever the source, the value must be a single +`https://` URL with no whitespace. + +**Shared runner pools.** When a fleet image sets `OPENSHELL_GATEWAY` on +a runner pool shared across repositories, each repository's variable +decides which endpoint receives that gateway's registered credentials +for its runs. + +**CLI preinstall (remote gateway only).** On a remote-gateway runner, +if the `openshell` CLI is already on the runner's `PATH`, the action +also skips the OpenShell CLI installer, which needs `sudo` and starts a +local gateway service. Install the CLI version pinned in `.github/scripts/openshell-version.sh` in the runner image. The action also needs the Python `jsonschema` package to validate agent diff --git a/internal/scaffold/action_sandbox_host_test.go b/internal/scaffold/action_sandbox_host_test.go index 704c7aa99f..6a86d0a763 100644 --- a/internal/scaffold/action_sandbox_host_test.go +++ b/internal/scaffold/action_sandbox_host_test.go @@ -135,6 +135,22 @@ func TestActionDetectSandboxHostStep(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { out, outputs, envWrites, err := runDetectSandboxHost(t, detect.Run, tc.endpoint, tc.pathDir, tc.workflowEndpoint) + // The endpoint value is never logged: the step prints its source + // and, on rejection, its length, but not the value itself, which + // can carry credentials or internal addresses into public logs. + // Every value the case supplied is checked, including the losing + // channel's value in the precedence case, and each line of a + // newline-injected value, so a partial leak is caught too. + for _, supplied := range []*string{tc.endpoint, tc.workflowEndpoint} { + if supplied == nil || *supplied == "" { + continue + } + for _, line := range strings.Split(*supplied, "\n") { + if line != "" { + assert.NotContains(t, out, line, "the endpoint value must never appear in the run log") + } + } + } if tc.wantErr { // A rejection must be the step's own validation failing, not // any non-zero exit: the error annotation is printed, and @@ -147,6 +163,14 @@ func TestActionDetectSandboxHostStep(t *testing.T) { assert.False(t, decided, "a rejected endpoint must not produce a sandbox-host decision") return } + // The success log names the channel the endpoint came from. + if tc.wantEndpoint != "" { + if tc.workflowEndpoint != nil && *tc.workflowEndpoint != "" { + assert.Contains(t, out, "from repository variable") + } else if tc.endpoint != nil { + assert.Contains(t, out, "from runner environment") + } + } require.NoError(t, err) assert.Equal(t, tc.wantLocal, outputs["local"]) assert.Equal(t, tc.wantInstallShell, outputs["install-openshell"]) From c088e200b9713f1af2d98a0700acf3b7eadfb4ce Mon Sep 17 00:00:00 2001 From: jtanner Date: Mon, 16 Nov 2026 17:46:17 -0500 Subject: [PATCH 8/8] fix(#9044): lock the gateway endpoint to the runner's value on demand Review follow-up on the bearer-token finding: on a shared runner pool with a bearer-auth gateway (OIDC or Cloudflare edge, without pinned-CA mTLS), anyone who can write Actions variables in one repository could point OPENSHELL_GATEWAY_ENDPOINT at a host of their choosing, and the gateway's reusable bearer token would be sent there, because the repository variable wins over the runner's own value and the only validation is the https-URL shape. Add an operator lock: when the runner's process environment sets FULLSEND_OPENSHELL_GATEWAY_ENDPOINT_LOCKED=1 together with the runner's own OPENSHELL_GATEWAY_ENDPOINT, the runner value wins and a repository variable naming a different endpoint fails the job instead of redirecting the credentials. The lock is fail-closed: a repository variable also fails on a locked runner with no endpoint of its own (a fleet image may register the gateway under OPENSHELL_GATEWAY without exporting the endpoint), and a lock value other than 1, 0 or empty fails rather than silently meaning unlocked. The lock is opt-in and defends against variable-only writers; workflow writers remain a runner-group access-control concern. The guide states the bearer-token risk plainly, documents the lock and its runner-endpoint prerequisite, and the config-repository wording is updated to per-repo terms per ADR 0044. Signed-off-by: jtanner --- action.yml | 33 ++++++++++++++++++ docs/guides/infrastructure/advanced-setup.md | 34 +++++++++++++------ internal/scaffold/action_sandbox_host_test.go | 34 ++++++++++++++++--- 3 files changed, 87 insertions(+), 14 deletions(-) diff --git a/action.yml b/action.yml index da3d593432..a970f0d612 100644 --- a/action.yml +++ b/action.yml @@ -457,6 +457,39 @@ runs: endpoint="${OPENSHELL_GATEWAY_ENDPOINT:-}" endpoint_source="runner environment" fi + # Operator lock (#9044): on a shared runner pool, anyone who can + # write Actions variables in one repository could otherwise point + # the endpoint at a host of their choosing, and the gateway's + # bearer token (OIDC or edge) would be sent there. A runner + # operator sets FULLSEND_OPENSHELL_GATEWAY_ENDPOINT_LOCKED=1 to + # pin the endpoint to the runner's own value: the runner value + # then wins, and a repository variable that names a different + # endpoint fails the job instead of redirecting the credentials. + # The lock is fail-closed: a non-empty repository variable also + # fails when the runner has no endpoint of its own to pin to (a + # fleet image may register the gateway under OPENSHELL_GATEWAY + # without exporting OPENSHELL_GATEWAY_ENDPOINT), and a value other + # than 1, 0 or empty fails rather than silently meaning unlocked. + lock="${FULLSEND_OPENSHELL_GATEWAY_ENDPOINT_LOCKED:-}" + if [[ -n "$lock" && "$lock" != "1" && "$lock" != "0" ]]; then + echo "::error::FULLSEND_OPENSHELL_GATEWAY_ENDPOINT_LOCKED must be 1, 0 or empty (got ${#lock} characters)" + exit 1 + fi + if [[ "$lock" == "1" ]]; then + if [[ -z "${OPENSHELL_GATEWAY_ENDPOINT:-}" ]]; then + if [[ -n "$endpoint" ]]; then + echo "::error::This runner's gateway endpoint is locked (FULLSEND_OPENSHELL_GATEWAY_ENDPOINT_LOCKED=1) but the runner sets no OPENSHELL_GATEWAY_ENDPOINT to pin to, and a repository variable is set." + exit 1 + fi + else + if [[ -n "$endpoint" && "$endpoint" != "${OPENSHELL_GATEWAY_ENDPOINT}" ]]; then + echo "::error::This runner's gateway endpoint is locked (FULLSEND_OPENSHELL_GATEWAY_ENDPOINT_LOCKED=1) and the repository variable names a different endpoint." + exit 1 + fi + endpoint="${OPENSHELL_GATEWAY_ENDPOINT}" + endpoint_source="runner environment (locked)" + fi + fi if [[ -n "$endpoint" ]]; then # The value is written to GITHUB_ENV below, where a newline would # become a separate assignment for later steps, so it must be a diff --git a/docs/guides/infrastructure/advanced-setup.md b/docs/guides/infrastructure/advanced-setup.md index 7915ea0837..4928895a49 100644 --- a/docs/guides/infrastructure/advanced-setup.md +++ b/docs/guides/infrastructure/advanced-setup.md @@ -115,15 +115,15 @@ elsewhere. Configure the endpoint in one of these ways: reusable workflow, `vars` is read from that calling repository, not from the repository holding the issue or pull request. For the standard per-repo install the calling repository is the work-item - repository itself; for runs driven from the `.fullsend` config - repository (prioritize, poller and harness-matrix runs) it is the - config repository. An organization variable visible to the calling - repository also works. When the run starts from a different repository - than the work item, a variable set only on the work-item repository is - not read. + repository itself; for a custom poller or other external repository + calling the reusable workflow, it is that calling repository. An + organization variable visible to the calling repository also works. + When the run starts from a different repository than the work item, a + variable set only on the work-item repository is not read. 2. As a fallback, for fleet-managed runner images, set `OPENSHELL_GATEWAY_ENDPOINT` in the runner's own process environment; - it applies whenever the variable from step 1 is unset. The same rule + it applies whenever the variable from step 1 is unset, and always + when the runner's endpoint is locked (below). The same rule holds on this channel: the value must be a single `https://` URL with no whitespace. Earlier releases accepted any non-empty value here, so plaintext, scheme-less or uppercase-scheme runner values must be @@ -153,13 +153,27 @@ whatever endpoint the variable holds. **Precedence and validation.** A non-empty repository or organization variable deliberately takes precedence over a value configured in the runner's process environment: repository administrators choose the -gateway for their runs. Whatever the source, the value must be a single -`https://` URL with no whitespace. +gateway for their runs. The exception is a locked runner (below). +Whatever the source, the value must be a single `https://` URL with no +whitespace. **Shared runner pools.** When a fleet image sets `OPENSHELL_GATEWAY` on a runner pool shared across repositories, each repository's variable decides which endpoint receives that gateway's registered credentials -for its runs. +for its runs. On a bearer-auth gateway (OIDC or Cloudflare edge, without +pinned-CA mTLS), that means anyone who can write Actions variables in +one repository can send the gateway's reusable bearer token to any host +with a public certificate. Runner operators who need to prevent this can +set `FULLSEND_OPENSHELL_GATEWAY_ENDPOINT_LOCKED=1` in the runner's +process environment, together with the runner's own +`OPENSHELL_GATEWAY_ENDPOINT`: the runner value then wins, a repository +variable naming a different endpoint fails the job, and a repository +variable set on a runner with no endpoint of its own fails too — the +lock is fail-closed, and it requires the runner endpoint to pin to. The +lock defends against variable-only writers; anyone who can write +workflows that run on the pool can still set step `env:` overrides, so +limiting which repositories can use the runner group remains the control +against workflow writers. **CLI preinstall (remote gateway only).** On a remote-gateway runner, if the `openshell` CLI is already on the runner's `PATH`, the action diff --git a/internal/scaffold/action_sandbox_host_test.go b/internal/scaffold/action_sandbox_host_test.go index 6a86d0a763..4be3a2b5bc 100644 --- a/internal/scaffold/action_sandbox_host_test.go +++ b/internal/scaffold/action_sandbox_host_test.go @@ -47,7 +47,7 @@ func loadRootActionSteps(t *testing.T) map[string]actionStep { // when workflowEndpoint is non-nil, FULLSEND_OPENSHELL_GATEWAY_ENDPOINT is // set to it (the channel the dispatch workflow passes from repository // variables). -func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir string, workflowEndpoint *string) (string, map[string]string, map[string]string, error) { +func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir string, workflowEndpoint *string, lockValue *string) (string, map[string]string, map[string]string, error) { t.Helper() bash, err := exec.LookPath("bash") require.NoError(t, err) @@ -67,6 +67,9 @@ func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir if workflowEndpoint != nil { env = append(env, "FULLSEND_OPENSHELL_GATEWAY_ENDPOINT="+*workflowEndpoint) } + if lockValue != nil { + env = append(env, "FULLSEND_OPENSHELL_GATEWAY_ENDPOINT_LOCKED="+*lockValue) + } cmd := exec.Command(bash, scriptPath) cmd.Env = env out, err := cmd.CombinedOutput() @@ -107,10 +110,13 @@ func TestActionDetectSandboxHostStep(t *testing.T) { injected := "https://gateway.example\nBASH_ENV=/tmp/x" httpEndpoint := "http://gateway.example:8080" + lockTrue := "1" + lockTrueWord := "true" cases := []struct { name string endpoint *string workflowEndpoint *string + lockValue *string pathDir string wantLocal string wantInstallShell string @@ -131,10 +137,19 @@ func TestActionDetectSandboxHostStep(t *testing.T) { {name: "whitespace-only runner endpoint is rejected", endpoint: &whitespace, pathDir: withCLI, wantErr: true}, {name: "newline-injected runner endpoint is rejected", endpoint: &injected, pathDir: withCLI, wantErr: true}, {name: "non-https runner endpoint is rejected", endpoint: &httpEndpoint, pathDir: withCLI, wantErr: true}, + // Operator lock: the runner value wins, and a repository variable + // naming a different endpoint fails the job instead of redirecting + // the gateway's credentials. + {name: "locked runner value agrees with the repository variable", endpoint: &remote, workflowEndpoint: &remote, lockValue: &lockTrue, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false", wantEndpoint: remote}, + {name: "locked with only the runner value", endpoint: &remote, lockValue: &lockTrue, pathDir: withCLI, wantLocal: "false", wantInstallShell: "false", wantEndpoint: remote}, + {name: "locked with no runner value and a repository variable fails the job", workflowEndpoint: &remote, lockValue: &lockTrue, pathDir: withCLI, wantErr: true}, + {name: "locked with a near-miss lock value fails the job", endpoint: &remote, workflowEndpoint: &other, lockValue: &lockTrueWord, pathDir: withCLI, wantErr: true}, + {name: "locked with a differing repository variable fails the job", endpoint: &remote, workflowEndpoint: &other, lockValue: &lockTrue, pathDir: withCLI, wantErr: true}, + {name: "locked with no runner value and no repository variable sets up locally", lockValue: &lockTrue, pathDir: withCLI, wantLocal: "true", wantInstallShell: "true"}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { - out, outputs, envWrites, err := runDetectSandboxHost(t, detect.Run, tc.endpoint, tc.pathDir, tc.workflowEndpoint) + out, outputs, envWrites, err := runDetectSandboxHost(t, detect.Run, tc.endpoint, tc.pathDir, tc.workflowEndpoint, tc.lockValue) // The endpoint value is never logged: the step prints its source // and, on rejection, its length, but not the value itself, which // can carry credentials or internal addresses into public logs. @@ -156,7 +171,16 @@ func TestActionDetectSandboxHostStep(t *testing.T) { // any non-zero exit: the error annotation is printed, and // nothing is published to GITHUB_ENV or GITHUB_OUTPUT. require.Error(t, err) - assert.Contains(t, out, "::error::OPENSHELL_GATEWAY_ENDPOINT must be a single https:// URL") + if tc.lockValue != nil && *tc.lockValue != "1" && *tc.lockValue != "0" { + assert.Contains(t, out, "::error::FULLSEND_OPENSHELL_GATEWAY_ENDPOINT_LOCKED must be 1, 0 or empty") + } else if tc.lockValue != nil && *tc.lockValue == "1" && tc.endpoint == nil && tc.workflowEndpoint != nil { + assert.Contains(t, out, "::error::This runner's gateway endpoint is locked") + assert.Contains(t, out, "no OPENSHELL_GATEWAY_ENDPOINT to pin to") + } else if tc.lockValue != nil && *tc.lockValue == "1" { + assert.Contains(t, out, "::error::This runner's gateway endpoint is locked") + } else { + assert.Contains(t, out, "::error::OPENSHELL_GATEWAY_ENDPOINT must be a single https:// URL") + } _, wrote := envWrites["OPENSHELL_GATEWAY_ENDPOINT"] assert.False(t, wrote, "a rejected endpoint must not be published to GITHUB_ENV") _, decided := outputs["local"] @@ -165,7 +189,9 @@ func TestActionDetectSandboxHostStep(t *testing.T) { } // The success log names the channel the endpoint came from. if tc.wantEndpoint != "" { - if tc.workflowEndpoint != nil && *tc.workflowEndpoint != "" { + if tc.lockValue != nil && *tc.lockValue == "1" && tc.endpoint != nil { + assert.Contains(t, out, "from runner environment (locked)") + } else if tc.workflowEndpoint != nil && *tc.workflowEndpoint != "" { assert.Contains(t, out, "from repository variable") } else if tc.endpoint != nil { assert.Contains(t, out, "from runner environment")