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/.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 83cc1fcaa3..a970f0d612 100644 --- a/action.yml +++ b/action.yml @@ -432,19 +432,81 @@ 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 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:-}" + endpoint_source="repository variable" + if [[ -z "$endpoint" ]]; then + 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 + # 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. + 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..4928895a49 100644 --- a/docs/guides/infrastructure/advanced-setup.md +++ b/docs/guides/infrastructure/advanced-setup.md @@ -106,13 +106,79 @@ 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 -`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 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, 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 + 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. + +**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. + +**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. 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. 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 +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 210a34e18a..4be3a2b5bc 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" @@ -39,9 +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. -func runDetectSandboxHost(t *testing.T, script string, endpoint *string, pathDir string) map[string]string { +// 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, lockValue *string) (string, map[string]string, map[string]string, error) { t.Helper() bash, err := exec.LookPath("bash") require.NoError(t, err) @@ -51,25 +57,39 @@ 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) + } + if lockValue != nil { + env = append(env, "FULLSEND_OPENSHELL_GATEWAY_ENDPOINT_LOCKED="+*lockValue) + } 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, 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 { + parsed[k] = v + } } + return parsed + } + outputs, envWrites := parse(outputPath), parse(envPath) + if err != nil { + return string(out), outputs, envWrites, fmt.Errorf("%w: %s", err, out) } - return outputs + return string(out), outputs, envWrites, nil } func TestActionDetectSandboxHostStep(t *testing.T) { @@ -85,24 +105,109 @@ 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" + lockTrue := "1" + lockTrueWord := "true" cases := []struct { name string endpoint *string + workflowEndpoint *string + lockValue *string pathDir string 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 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}, + // 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) { - outputs := runDetectSandboxHost(t, detect.Run, tc.endpoint, tc.pathDir) + 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. + // 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 + // nothing is published to GITHUB_ENV or GITHUB_OUTPUT. + require.Error(t, err) + 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"] + 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.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") + } + } + 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") + } }) } }