Skip to content

Latest commit

 

History

History
86 lines (68 loc) · 5.02 KB

auth.md

File metadata and controls

86 lines (68 loc) · 5.02 KB

Auth: the model of the advisory review

The analysis step of the review (square2 review run) runs the pinned codex CLI (@openai/codex@0.171.0 in square2-review.yml) against an Azure OpenAI resource, or against an OpenAI-compatible gateway, through the Responses API. This page says what the step needs and what it passes on. For the review as a whole, see the guide and the trust model.

Settings

Name Kind Meaning
SQ2_AZURE_OPENAI_ENDPOINT repository variable https://<resource>.openai.azure.com/
SQ2_AZURE_OPENAI_API_KEY secret the key; it reaches only the analyze job
SQ2_REVIEW_MODEL repository variable the deployment of the reviewer
SQ2_REVIEW_FALLBACK_MODEL repository variable, optional the deployment for one retry after a failure
SQ2_LLM_BASE_URL repository variable, optional a gateway, used in place of the Azure endpoint
SQ2_LLM_RETRIES repository variable, optional the request and stream retries of the provider, 0 to 100, default 20
SQ2_ANALYZE_RUNS_ON repository variable, optional a JSON runs-on value for the analyze job only

review run needs the key, and either the endpoint or the gateway. Without them it stops with [S2-REVIEW-MODEL], exit 2, before any model call.

What square² passes to codex

square2 review run starts codex exec with:

  • the provider sq2azure, given with -c model_provider="sq2azure" and -c model_providers.sq2azure={ name = "sq2azure", base_url = "<base url>", env_key = "SQ2_AZURE_OPENAI_API_KEY", wire_api = "responses", request_max_retries = <n>, stream_max_retries = <n>, stream_idle_timeout_ms = 600000 }. The base URL is <SQ2_AZURE_OPENAI_ENDPOINT>/openai/v1, or SQ2_LLM_BASE_URL as it is when that is set. <n> is SQ2_LLM_RETRIES: a deployment with a low tokens-per-minute quota throttles the many turns of codex, and a few retries give up too early. The stream idle time of ten minutes covers a throttled stream that pauses;
  • -m <deployment>: --model, else SQ2_REVIEW_MODEL, else the model of the selected reviewer of review.json. The variable overrides the model only when it belongs to the selected reviewer's family (an entry of reviewers with that deployment, else the family that its name shows); otherwise it is ignored with a notice. After a failure the step tries once more with --fallback-model or SQ2_REVIEW_FALLBACK_MODEL, under the same family rule;
  • codex exec --ignore-user-config --ignore-rules --ephemeral --sandbox read-only, a fresh home directory for codex, and an environment that holds the key and the endpoint and nothing else secret.

A deployment whose name does not show its family must be listed under reviewers in .square2/review.json, with its family. A deployment given with --model or --fallback-model that is not of the family of the selected reviewer is refused with [S2-REVIEW-FAMILY], unless --allow-same-family is given.

Setup

  1. Create or reuse an Azure OpenAI resource and deploy the reviewer model; note the deployment names.
  2. Set the repository variables SQ2_AZURE_OPENAI_ENDPOINT, SQ2_REVIEW_MODEL and, if you want one, SQ2_REVIEW_FALLBACK_MODEL.
  3. Set the secret from standard input: gh secret set SQ2_AZURE_OPENAI_API_KEY, paste the key, then Ctrl-D. Never write the key to a file, a log or a chat.

A local run reads the same names from the environment of the one command.

A gateway instead of Azure

Set SQ2_LLM_BASE_URL to a gateway that serves the OpenAI Responses API, for example http://127.0.0.1:3425/v1 for a gateway on the runner itself. It is used as it is as the base URL of the provider. It must be an https:// URL; plain http:// is accepted only for a loopback host (127.0.0.1, ::1, localhost), and a URL with credentials is refused. A bad value stops review run with exit 2 before any model call.

  • The key is still read from SQ2_AZURE_OPENAI_API_KEY and sent as the bearer token. A gateway that does its own upstream auth may accept any value that is not empty; set the secret anyway.
  • SQ2_AZURE_OPENAI_ENDPOINT may stay unset.
  • The model names are what the gateway calls its models, and the family rule still holds.
  • A loopback gateway needs the analyze job on a runner where the gateway runs: set SQ2_ANALYZE_RUNS_ON, for example to ["self-hosted","sq2-analyze"]. Only the analyze job runs there; run the runner as a user without root.

Key rotation

An Azure OpenAI resource has two keys, so a rotation needs no downtime:

  1. Regenerate the key that is not in use (Key 2) in the Azure portal.
  2. Run gh secret set SQ2_AZURE_OPENAI_API_KEY with Key 2, and run the review once by hand to see that it works.
  3. Regenerate Key 1. Next time, rotate the other way.

Rotate at once when a key was ever pasted anywhere outside the secret store. A leaked key cannot reach an issue through square² (output that holds it stops the run), but it can be used against the resource until it is regenerated.