From c3f82374c6cc96c3ef70979a1aebc8fd418ea1f2 Mon Sep 17 00:00:00 2001 From: Alex Rhee Date: Sun, 22 Nov 2026 15:04:20 -0800 Subject: [PATCH] fix(gateway): pass organization scope --- .../templates/ai-gateway-configmap.yaml | 4 + .../tests/ai-gateway-configmap_test.yaml | 80 +++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/braintrust/templates/ai-gateway-configmap.yaml b/braintrust/templates/ai-gateway-configmap.yaml index dd524cf..55cdfac 100644 --- a/braintrust/templates/ai-gateway-configmap.yaml +++ b/braintrust/templates/ai-gateway-configmap.yaml @@ -14,6 +14,10 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} data: + ORG_NAME: {{ .Values.global.orgName | default "" | toString | trim | default "*" | quote }} + {{- with (.Values.global.allowedOrgIds | default "" | toString | trim) }} + ALLOWED_ORG_IDS: {{ . | quote }} + {{- end }} GATEWAY_ENV: "production" {{- if .Values.aiGateway.region }} GATEWAY_REGION: {{ .Values.aiGateway.region | quote }} diff --git a/braintrust/tests/ai-gateway-configmap_test.yaml b/braintrust/tests/ai-gateway-configmap_test.yaml index bd0bba5..ec9f599 100644 --- a/braintrust/tests/ai-gateway-configmap_test.yaml +++ b/braintrust/tests/ai-gateway-configmap_test.yaml @@ -24,6 +24,11 @@ tests: - equal: path: metadata.name value: braintrust-ai-gateway + - equal: + path: data.ORG_NAME + value: "test-org" + - isNull: + path: data.ALLOWED_ORG_IDS - equal: path: data.GATEWAY_ENV value: "production" @@ -163,3 +168,78 @@ tests: - equal: path: data.OTLP_HTTP_ENDPOINT value: "https://control.example.com/api/pulse/otel" + + - it: should forward a trimmed organization name and complete ID allowlist + values: + - __fixtures__/base-values.yaml + set: + aiGateway.enabled: true + global.orgName: " example.com " + global.allowedOrgIds: " 00000000-0000-4000-8000-000000000001,00000000-0000-4000-8000-000000000002 " + asserts: + - equal: + path: data.ORG_NAME + value: "example.com" + - equal: + path: data.ALLOWED_ORG_IDS + value: "00000000-0000-4000-8000-000000000001,00000000-0000-4000-8000-000000000002" + + - it: should preserve wildcard organization access with an ID allowlist + values: + - __fixtures__/base-values.yaml + set: + aiGateway.enabled: true + global.orgName: "*" + global.primaryOrgName: "example.com" + global.allowedOrgIds: "00000000-0000-4000-8000-000000000001" + asserts: + - equal: + path: data.ORG_NAME + value: "*" + - equal: + path: data.ALLOWED_ORG_IDS + value: "00000000-0000-4000-8000-000000000001" + + - it: should retain wildcard defaults when organization settings are omitted + values: + - __fixtures__/base-values.yaml + set: + aiGateway.enabled: true + global.orgName: "" + global.primaryOrgName: "example.com" + asserts: + - equal: + path: data.ORG_NAME + value: "*" + - isNull: + path: data.ALLOWED_ORG_IDS + + - it: should normalize blank organization settings + values: + - __fixtures__/base-values.yaml + set: + aiGateway.enabled: true + global.orgName: " " + global.primaryOrgName: "example.com" + global.allowedOrgIds: " " + asserts: + - equal: + path: data.ORG_NAME + value: "*" + - isNull: + path: data.ALLOWED_ORG_IDS + + - it: should tolerate null organization settings in reused values + values: + - __fixtures__/base-values.yaml + set: + aiGateway.enabled: true + global.orgName: null + global.primaryOrgName: "example.com" + global.allowedOrgIds: null + asserts: + - equal: + path: data.ORG_NAME + value: "*" + - isNull: + path: data.ALLOWED_ORG_IDS