gh-aw icon indicating copy to clipboard operation
gh-aw copied to clipboard

Support secret-backed custom OpenAI-compatible endpoint for Codex workflows

Open JKamsker opened this issue 5 months ago • 7 comments

Summary

gh-aw currently appears to support Codex workflows with its generated AWF OpenAI API proxy target, but custom OpenAI-compatible endpoints are effectively compile-time/static. This makes it hard to use a private OpenAI-compatible proxy/load balancer when the endpoint host itself must be treated as a secret.

Request: add first-class support for configuring the Codex/OpenAI API proxy target from a GitHub Actions secret at runtime, without writing the endpoint host into the committed .lock.yml.

Use Case

We run engine: codex workflows through an internal OpenAI-compatible load balancer/proxy. The proxy host is sensitive and must not appear in:

  • committed workflow source
  • generated .lock.yml
  • generated AWF config in the repository
  • workflow logs
  • uploaded gh-aw/AWF artifacts
  • detection artifacts
  • sandboxed agent environment

The API key can already be a secret, but the base URL/host needs the same treatment.

Today, the only practical workaround is to compile normally and then patch the generated lockfile so the runner reads a secret, mutates the AWF config, excludes the secret from the sandboxed agent environment, and redacts artifacts. That works, but it is brittle and has to track generated lockfile internals.

Desired Configuration Shape

Exact syntax is flexible, but something like this would solve it:

engine: codex

openai:
  base-url-secret: CODEX_LB_BASE_URL

or:

api-proxy:
  targets:
    openai:
      base-url-secret: CODEX_LB_BASE_URL

The generated workflow would then read ${{ secrets.CODEX_LB_BASE_URL }} at runtime and configure AWF's OpenAI target from that value.

Requirements

For this to work securely, gh-aw/AWF would need to guarantee:

  1. gh aw compile must not write the endpoint value or derived host into the committed .lock.yml.
  2. The generated workflow should read the endpoint from a GitHub Actions secret at runtime.
  3. AWF should route Codex/OpenAI-compatible traffic through that endpoint.
  4. AWF/network policy should allow the derived host from the secret at runtime.
  5. The endpoint secret should be available only to runner-side setup/AWF configuration code.
  6. The endpoint secret should not be passed into the sandboxed agent environment.
  7. The full URL, host, and host:port should be masked/redacted from logs.
  8. The full URL, host, and host:port should be redacted from uploaded artifacts.
  9. The behavior should apply consistently to all gh-aw phases, including agent and detection jobs.
  10. Validation should reject invalid values at runtime, e.g. non-HTTP(S) URLs, embedded credentials, or malformed hosts.

Possible Implementation Direction

One option is to model this directly in the AWF config, for example:

{
  "apiProxy": {
    "targets": {
      "openai": {
        "baseUrlEnv": "CODEX_LB_BASE_URL"
      }
    }
  }
}

Then gh-aw could emit the secret env binding and AWF could:

  • parse the runtime URL
  • derive host, host:port, and optional basePath
  • add the derived host to runtime network allow-listing
  • configure the OpenAI target
  • mask/redact the value and derived host forms

Alternatively, gh-aw could generate an explicit setup step before AWF starts, but having AWF understand baseUrlEnv would be cleaner and less generated-YAML-sensitive.

Current Workaround

We currently wrap gh aw compile with a repository script that:

  • runs gh aw compile
  • patches the generated .lock.yml
  • injects a runtime step that reads CODEX_LB_BASE_URL
  • mutates ${RUNNER_TEMP}/gh-aw/awf-config.json
  • adds --exclude-env CODEX_LB_BASE_URL to the AWF command
  • injects redaction before artifact upload

This works, but it is not ideal because it depends on generated lockfile structure and needs to be kept in sync with gh-aw changes.

Why This Matters

This would let teams use gh-aw normally with private OpenAI-compatible routing infrastructure while preserving the security properties expected from GitHub Actions secrets. It would also remove the need for post-generation lockfile patching and make generated workflows easier to audit.

JKamsker avatar Jun 27 '26 19:06 JKamsker

Addidional context from research agents:

Here’s the aggregated version, tightened into one GitHub-ready comment:

Additional context from digging into current main — sharing the precise mechanics in case it helps whoever picks this up.

Static custom endpoints are partially supported today, but not this secret-backed Codex/OpenAI case.

From what I can tell, the current OpenAI/Codex API proxy target is resolved at compile time:

  • gh-aw derives apiProxy.targets.openai.host from a literal engine.env.OPENAI_BASE_URL, not from a runtime-resolved secret.
  • extractAPITargetHost() parses engine.env.OPENAI_BASE_URL during gh aw compile.
  • The result is baked into apiProxy.targets.openai.host in awf-config.json.
  • That JSON is embedded as a static string in the generated .lock.yml.

engine.api-target is used in other paths, especially allow-list/domain handling and Copilot target selection, but it does not appear to configure the OpenAI/Codex API proxy target directly. That creates some docs ambiguity: docs/enterprise-configuration.md says engine.api-target works with any engine, but the Codex/OpenAI config path appears to use OPENAI_BASE_URL for the actual OpenAI proxy target.

So setting:

OPENAI_BASE_URL: ${{ secrets.CODEX_LB_BASE_URL }}

is not equivalent to supported static endpoint configuration. It breaks in several ways:

  1. Host parsing — the compiler cannot derive host / basePath from a secret expression at compile time. In some paths, secret expressions can be misinterpreted as literal hosts or preserved into static config in the wrong shape.
  2. Firewall allow-listing — the allowed domains are computed at compile time and frozen into the generated lockfile. A runtime-secret host cannot be included unless there is explicit runtime handling. Separately, the Codex/OpenAI custom host does not appear to be merged into the allow-list in the same way as some other engines, so even static custom hosts may currently require a manual network.allowed entry.
  3. Strict-mode env handling — a secret-bearing OPENAI_BASE_URL is treated as an unsafe engine env value.
  4. Artifact / config exposure — the endpoint, or derived forms like host / host:port / basePath, can still end up in runtime config or uploaded artifacts unless separately redacted.
  5. Threat detection parity — detection jobs need the same handling as the main agent job.

The feature still seems tractable because some of the needed primitives already exist:

  • Runtime injection into awf-config.json already exists for another field via the ${GH_AW_MAX_AI_CREDITS} preservation flow.
  • --exclude-env / ComputeAWFExcludeEnvVarNames already provides a mechanism to keep secret-valued env vars out of the sandboxed agent.
  • secret-masking.steps is an existing hook for extra redaction.
  • Allowed-domain handling already has some support for preserving expressions into runtime config.

A minimal implementation could look like:

  1. Allow AWF to accept a runtime env-backed OpenAI target, for example:

    "apiProxy": {
      "targets": {
        "openai": {
          "baseUrlEnv": "CODEX_LB_BASE_URL"
        }
      }
    }
    

    or equivalent hostEnv / basePathEnv fields.

  2. At AWF startup, read the env var and validate/split it into:

    • scheme, restricted to HTTP(S)
    • host
    • optional port
    • optional base path

    It should reject embedded credentials and malformed hosts.

  3. Ensure the derived host / host:port is allowed by the network policy, either in AWF or emitted by gh-aw as part of the runner-side setup.

  4. Have gh-aw emit the secret env binding only for runner-side setup / AWF execution, add it to --exclude-env, and avoid exposing it to the sandboxed agent.

  5. Add the resolved endpoint and derived forms — full URL, host, host:port, basePath if relevant — to the redaction value set so uploaded gh-aw/AWF artifacts do not contain the secret endpoint.

  6. Apply the same flow to both normal agent execution and threat detection execution.

One related note on the pre-step workaround: patching awf-config.json in pre-agent-steps is fragile because those steps run before the generated “Execute Agent CLI” step, which rewrites awf-config.json. That means pre-step patches can be clobbered, which is why the current workaround has to patch the generated lockfile rather than use a supported hook.

So I think the requested support likely needs changes on both sides:

  • AWF needs an env-backed runtime API proxy target form.
  • gh-aw needs to emit that runtime binding safely, exclude it from the agent env, wire the derived host into network policy, and redact all derived endpoint forms from artifacts.

JKamsker avatar Jun 27 '26 19:06 JKamsker

A good smoke-test target for this feature, once the secret-backed base_url flow exists, is a plain hosted OpenAI-compatible endpoint rather than a vendor-specific SDK path. One example is AI Router:

  • Site: https://ai-router.dev
  • API base URL: https://api.ai-router.dev/v1
  • Auth: standard bearer key
  • Discovery: /v1/models
  • Chat path: /v1/chat/completions

That makes it useful for validating the exact things the issue cares about:

  • base URL injected from a GitHub secret at runtime
  • URL never baked into the committed lockfile
  • derived host/path redaction in logs and artifacts
  • no leak of endpoint env vars into the sandboxed agent environment
  • clear separation between endpoint resolution failure, auth failure, and model mismatch

I also published a small public examples repo for this endpoint shape if it helps with QA or docs references: https://github.com/airouter-dev/ai-router-openai-compatible-examples

And for generic compatibility work, this checklist page is handy too: https://github.com/airouter-dev/ai-router-openai-compatible-examples/blob/main/docs/byok-smoke-test-checklist.md

airouter-dev avatar Jul 10 '26 09:07 airouter-dev

I have implemented it in my fork which works for me (can be used for reference): https://github.com/JKamsker/gh-aw/tree/jk/secret-backed-openai-endpoint

Is there anything i can do to help getting this issue implemented here? @pelikhan

JKamsker avatar Jul 11 '26 10:07 JKamsker

Can you distillate your fork changes into a comment here?

pelikhan avatar Jul 11 '26 10:07 pelikhan

🔗 AWF tracking issue: https://github.com/github/gh-aw-firewall/issues/github/gh-aw-firewall#6650

Generated by Firewall Issue Dispatcher · sonnet46 · 30.4 AIC · ⊞ 6.4K · ◷

lpcox avatar Jul 27 '26 18:07 lpcox

🔗 AWF tracking issue: https://github.com/github/gh-aw-firewall/issues/7575

lpcox avatar Aug 20 '26 21:08 lpcox

Addressed by github/gh-aw-firewall#7576, building on github/gh-aw-firewall#6656, with runtime secret-backed OpenAI-compatible target support.

lpcox avatar Aug 27 '26 18:08 lpcox