Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore: preview write access (#15060)

Max Deichmann82ddf1437165
diff --git a/.github/workflows/preview-autolabel.yml b/.github/workflows/preview-autolabel.yml
index 2b9fa96789..19e8226ed8 100644
--- a/.github/workflows/preview-autolabel.yml
+++ b/.github/workflows/preview-autolabel.yml
@@ -1,18 +1,17 @@
name: AWS preview auto-label
-# Auto-apply the `preview` label to same-repo PRs opened by an allowlisted
-# author, so the Argo CD ApplicationSet (in the infrastructure repo) picks them
-# up and builds a preview. Anyone with write access can also apply the label
-# by hand; the build workflow re-checks the PR author before building with a
-# cloud credential, so a manual label from a non-allowlisted author is inert.
+# Auto-apply the `preview` label to same-repo PRs on open, so the Argo CD
+# ApplicationSet (in the infrastructure repo) picks them up and builds a
+# preview. Anyone with write access can also apply the label by hand.
#
-# Uses the plain `pull_request` trigger (NOT pull_request_target): it holds no
-# cloud credentials, never checks out or executes PR code, and only calls
-# issues.addLabels. The label is not a security boundary β€” the build workflow
-# independently re-checks the PR author before using any credential β€” so
-# pull_request_target's tamper-resistance isn't needed here, and avoiding it
-# keeps this off the dangerous-triggers list. Same-repo PRs get a write token to
-# add the label; fork PRs are short-circuited below (and get a read-only token).
+# Trust boundary is WRITE access, not a per-author allowlist: opening a
+# same-repo PR requires push access, so labeling every same-repo PR is exactly
+# "auto-preview for write-access members." Fork PRs are short-circuited β€” they
+# can't mint an OIDC token to build anyway.
+#
+# Uses the plain `pull_request` trigger (NOT pull_request_target): no cloud
+# credentials, no checkout, no PR-code execution β€” only issues.addLabels β€” so it
+# stays off zizmor's dangerous-triggers list.
on:
pull_request:
types: [opened, reopened]
@@ -21,45 +20,33 @@ permissions: {}
jobs:
autolabel:
- name: Auto-label allowlisted PRs
+ name: Auto-label same-repo PRs
runs-on: ubuntu-latest
- if: vars.AWS_PREVIEW_ALLOWED_USERS != ''
+ # AWS_PREVIEW_ECR_PUSH_ROLE_ARN is the feature flag: unset => preview system
+ # off, so don't label.
+ if: vars.AWS_PREVIEW_ECR_PUSH_ROLE_ARN != ''
permissions:
pull-requests: write
steps:
- - name: Label allowlisted, same-repo PRs
+ - name: Label same-repo PRs
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
- env:
- ALLOWED_USERS: ${{ vars.AWS_PREVIEW_ALLOWED_USERS }}
with:
script: |
const pr = context.payload.pull_request;
const { owner, repo } = context.repo;
- // Same-repo only: fork PRs cannot mint an OIDC token, so the build
- // workflow could never push their image β€” an auto-labeled fork PR
- // would only create a broken environment.
+ // Same-repo only: opening a same-repo PR requires push (write)
+ // access, so this is "auto-preview for write-access members." Fork
+ // PRs can't mint an OIDC token to build, so skip them.
if (pr.head.repo.full_name !== `${owner}/${repo}`) {
core.info("Fork PR; auto-label is limited to same-repo branches.");
return;
}
- // Exact-match allowlist (never substring β€” a login that is a
- // substring of an allowlisted one must not pass).
- const allowed = (process.env.ALLOWED_USERS || "")
- .split(/[\s,]+/)
- .filter(Boolean)
- .map((u) => u.toLowerCase());
- const author = pr.user.login.toLowerCase();
- if (!allowed.includes(author)) {
- core.info(`Author ${author} is not on the preview allowlist; skipping.`);
- return;
- }
-
await github.rest.issues.addLabels({
owner,
repo,
issue_number: pr.number,
labels: ["preview"],
});
- core.info(`Applied 'preview' label to PR #${pr.number} (author ${author}).`);
+ core.info(`Applied 'preview' label to PR #${pr.number}.`);
diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml
index 9d8fd723fe..a878091541 100644
--- a/.github/workflows/preview-build.yml
+++ b/.github/workflows/preview-build.yml
@@ -5,18 +5,21 @@ name: AWS preview build
# tag exists for a labeled PR; this workflow only builds and pushes, then posts
# the preview URL on the PR.
#
-# Authorization is intentionally stricter than "the PR is labeled": the
-# `preview` label can be applied by any org member, but this job builds the PR
-# AUTHOR's code with an AWS (ECR push) credential, so it also requires the PR
-# author to be on AWS_PREVIEW_ALLOWED_USERS. Fork PRs cannot mint an OIDC token
-# (public repo, read-only token), so they can never push regardless β€” and the
-# ECR-push role's trust policy is additionally scoped to
+# Builds every SAME-REPO PR on open/update (write access is the gate β€” opening a
+# same-repo PR requires push access). It deliberately does NOT trigger on the
+# `preview` label: the auto-labeler applies that label with the default
+# GITHUB_TOKEN, and GitHub does not start workflow runs from GITHUB_TOKEN-applied
+# events (anti-recursion), so a `labeled` trigger would never fire for
+# auto-labeled PRs. The label is only the Argo *deploy* filter (infra repo), and
+# the deploy allowlist lives in the ApplicationSet β€” not here. Fork PRs are
+# excluded (the head.repo check below) and can't mint an OIDC token anyway
+# (public repo, read-only token); the ECR-push role's trust is scoped to
# sub=repo:langfuse/langfuse:pull_request AND ref=refs/pull/* (GitHub OIDC has no
# event_name claim), so pull_request_target / review β€” which carry the base
# branch ref β€” cannot assume it either.
on:
pull_request:
- types: [labeled, synchronize, reopened]
+ types: [opened, synchronize, reopened]
permissions: {}
@@ -25,45 +28,16 @@ concurrency:
cancel-in-progress: true
jobs:
- authorize:
- name: Authorize
- runs-on: ubuntu-latest
- # AWS_PREVIEW_ECR_PUSH_ROLE_ARN doubles as the feature flag: unset => the
- # whole workflow no-ops instead of failing on every labeled PR.
+ build:
+ name: Build and push preview images
+ # Any SAME-REPO PR (= write access) builds on open/update. No label gate here:
+ # the auto-labeler's GITHUB_TOKEN-applied label can't trigger this workflow,
+ # and the label is the Argo deploy filter, not the build trigger. Fork PRs are
+ # excluded (head.repo check) and can't mint OIDC anyway.
+ # AWS_PREVIEW_ECR_PUSH_ROLE_ARN doubles as the feature flag: unset => no-op.
if: >-
vars.AWS_PREVIEW_ECR_PUSH_ROLE_ARN != '' &&
- contains(github.event.pull_request.labels.*.name, 'preview') &&
github.event.pull_request.head.repo.full_name == github.repository
- permissions:
- pull-requests: read
- outputs:
- authorized: ${{ steps.gate.outputs.authorized }}
- steps:
- - name: Require an allowlisted PR author
- id: gate
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
- env:
- ALLOWED_USERS: ${{ vars.AWS_PREVIEW_ALLOWED_USERS }}
- with:
- script: |
- const author = context.payload.pull_request.user.login.toLowerCase();
- const allowed = (process.env.ALLOWED_USERS || "")
- .split(/[\s,]+/)
- .filter(Boolean)
- .map((u) => u.toLowerCase());
- const ok = allowed.includes(author);
- if (!ok) {
- core.warning(
- `PR author ${author} is not on the preview allowlist; not building. ` +
- "Ask an admin to add the author to AWS_PREVIEW_ALLOWED_USERS.",
- );
- }
- core.setOutput("authorized", ok ? "true" : "false");
-
- build:
- name: Build and push preview images
- needs: authorize
- if: needs.authorize.outputs.authorized == 'true'
runs-on: blacksmith-4vcpu-ubuntu-2404
permissions:
contents: read
@@ -86,10 +60,9 @@ jobs:
run: |
set -euo pipefail
commit_sha="$(git rev-parse HEAD)"
- short_sha="${commit_sha:0:12}"
# The ApplicationSet deploys pr-<n>-{{.head_sha}} β€” Argo's FULL 40-char
# SHA β€” so the pushed tag MUST use the full SHA or the deployed image
- # never resolves (permanent ImagePullBackOff). short_sha is display-only.
+ # never resolves (permanent ImagePullBackOff).
image_tag="pr-${PR_NUMBER}-${commit_sha}"
{
echo "commit_sha=${commit_sha}"
@@ -141,36 +114,44 @@ jobs:
# tag fails. Tags embed the commit SHA, so an existing tag is byte-for-
# byte the same image β€” skip build+push if it is already there (this
# makes workflow re-runs on an unchanged commit idempotent).
- image_present() {
- local image="$1" repo tag
- repo="${image%:*}"; repo="${repo##*/}"
+ #
+ # Only a definitive ImageNotFoundException counts as "absent -> build".
+ # A present image -> skip. ANY OTHER describe failure (throttling, a
+ # transient network blip, a missing ecr:DescribeImages grant) is
+ # inconclusive, so fail loudly here rather than falling through to a
+ # push that would hard-fail on the immutable tag with a confusing
+ # ImageAlreadyExistsException.
+ ensure_image() {
+ local image="$1"; shift # remaining args: docker build flags
+ local repo tag describe_out
+ repo="${image%:*}"; repo="${repo#*/}" # strip only the registry host; keep any namespace
tag="${image##*:}"
- aws ecr describe-images --repository-name "${repo}" \
- --image-ids imageTag="${tag}" >/dev/null 2>&1
+
+ if describe_out="$(aws ecr describe-images --repository-name "${repo}" \
+ --image-ids imageTag="${tag}" 2>&1)"; then
+ echo "${image} already present β€” skipping."
+ return 0
+ fi
+ if ! grep -q 'ImageNotFoundException' <<<"${describe_out}"; then
+ echo "::error::Cannot confirm ${image} in ECR β€” describe-images failed" \
+ "for a reason other than ImageNotFound; refusing to build+push" \
+ "against the tag-immutable repo. ${describe_out}"
+ return 1
+ fi
+
+ echo "${image} not found β€” building and pushing."
+ docker build "$@" -t "${image}" .
+ docker push "${image}"
}
- if image_present "${WEB_IMAGE}"; then
- echo "${WEB_IMAGE} already present β€” skipping."
- else
- docker build \
- --build-arg NEXT_PUBLIC_BUILD_ID="${COMMIT_SHA}" \
- --build-arg NEXT_PUBLIC_SIGN_UP_DISABLED=true \
- -f ./web/Dockerfile \
- -t "${WEB_IMAGE}" \
- .
- docker push "${WEB_IMAGE}"
- fi
-
- if image_present "${WORKER_IMAGE}"; then
- echo "${WORKER_IMAGE} already present β€” skipping."
- else
- docker build \
- --build-arg NEXT_PUBLIC_BUILD_ID="${COMMIT_SHA}" \
- -f ./worker/Dockerfile \
- -t "${WORKER_IMAGE}" \
- .
- docker push "${WORKER_IMAGE}"
- fi
+ ensure_image "${WEB_IMAGE}" \
+ --build-arg NEXT_PUBLIC_BUILD_ID="${COMMIT_SHA}" \
+ --build-arg NEXT_PUBLIC_SIGN_UP_DISABLED=true \
+ -f ./web/Dockerfile
+
+ ensure_image "${WORKER_IMAGE}" \
+ --build-arg NEXT_PUBLIC_BUILD_ID="${COMMIT_SHA}" \
+ -f ./worker/Dockerfile
- name: Mark preview image pushed
uses: ./.github/actions/preview-comment
@@ -187,8 +168,7 @@ jobs:
**API keys:** `${{ steps.meta.outputs.public_key }}` / `${{ steps.meta.outputs.secret_key }}`
**Commit:** ${{ steps.meta.outputs.commit_sha }}
- Synthetic preview data only β€” never enter a real credential. Remove
- the `preview` label or close the PR to destroy the environment.
+ Synthetic preview data only. Never add production data to public accounts.
- name: Report failure
if: failure()