Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(webapp): org-gated internal API origin in run env vars#4366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
755eb40
feat(webapp): org-gated internal API origin for deployed runs
myftija ecc1052
refactor(webapp): extract pure org-flag resolution for the internal A…
myftija beaf9b7
perf(webapp): resolve the internal-api-origin global default from the…
myftija b97446d
fix(webapp): read org flags from the replica and document global-flag…
myftija d90a794
feat(webapp): resolve the internal-api-origin org flag from in-memory…
myftija 4133bc0
feat(webapp): read internal-api-origin global default from the flags …
myftija File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| area: webapp | ||
| type: improvement | ||
| --- | ||
| Self-hosted instances can now serve deployed runs' API traffic from a different origin than the public one, per organization, via the `INTERNAL_API_ORIGIN` environment variable and a feature flag. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3 apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 31 additions & 2 deletions
33 apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,6 +12,7 @@ export const FEATURE_FLAG = { | ||
| hasSso: "hasSso", | ||
| mollifierEnabled: "mollifierEnabled", | ||
| workerQueueScheduledSplitEnabled: "workerQueueScheduledSplitEnabled", | ||
| internalApiOriginEnabled: "internalApiOriginEnabled", | ||
| realtimeBackend: "realtimeBackend", | ||
| computeMigrationEnabled: "computeMigrationEnabled", | ||
| computeMigrationFreePercentage: "computeMigrationFreePercentage", | ||
| @@ -38,6 +39,12 @@ export const FeatureFlagCatalog = { | ||
| [FEATURE_FLAG.hasSso]: z.coerce.boolean(), | ||
| [FEATURE_FLAG.mollifierEnabled]: z.coerce.boolean(), | ||
| [FEATURE_FLAG.workerQueueScheduledSplitEnabled]: z.coerce.boolean(), | ||
| // Routes deployed runs' TRIGGER_API_URL to INTERNAL_API_ORIGIN. Per-org, with | ||
| // INTERNAL_API_ORIGIN_ENABLED as the global default (org wins). No-op unless | ||
| // INTERNAL_API_ORIGIN is set. | ||
| // Strict z.boolean(): coercion turns the string "false" into true, which | ||
myftija marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // would silently enable the wrong orgs if written as a string. | ||
| [FEATURE_FLAG.internalApiOriginEnabled]: z.boolean(), | ||
| // Which backend serves the realtime run feed. Controllable | ||
| // globally and per-org (org wins). Defaults to "electric" when unset. | ||
| // "shadow" serves Electric but diffs the native path in the background. | ||
| @@ -104,6 +111,35 @@ export function validatePartialFeatureFlags(values: Record<string, unknown>) { | ||
| } | ||
| // Utility types for catalog-driven UI rendering | ||
| /** | ||
| * Resolve whether deployed runs should use the internal API origin, from the | ||
| * org's feature-flags JSON. Precedence: a per-org override wins in BOTH | ||
| * directions; the global default applies only when the org has not set the | ||
| * flag (or set it to something invalid). | ||
| */ | ||
| export function resolveInternalApiOriginEnabled({ | ||
| orgFeatureFlags, | ||
| globalDefault, | ||
| }: { | ||
| orgFeatureFlags: unknown; | ||
| globalDefault: boolean; | ||
| }): boolean { | ||
| const override = | ||
| orgFeatureFlags && typeof orgFeatureFlags === "object" && !Array.isArray(orgFeatureFlags) | ||
| ? (orgFeatureFlags as Record<string, unknown>)[FEATURE_FLAG.internalApiOriginEnabled] | ||
| : undefined; | ||
| if (override !== undefined) { | ||
| const parsed = FeatureFlagCatalog[FEATURE_FLAG.internalApiOriginEnabled].safeParse(override); | ||
| if (parsed.success) { | ||
| return parsed.data; | ||
| } | ||
| } | ||
| return globalDefault; | ||
| } | ||
| export type FlagControlType = | ||
| | { type: "boolean" } | ||
| | { type: "enum"; options: string[] } | ||
2 changes: 2 additions & 0 deletions
2 apps/webapp/app/v3/services/worker/workerGroupTokenService.server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { resolveInternalApiOriginEnabled } from "~/v3/featureFlags"; | ||
| describe("resolveInternalApiOriginEnabled", () => { | ||
| it("returns the global default when the org has no flags", () => { | ||
| expect(resolveInternalApiOriginEnabled({ orgFeatureFlags: null, globalDefault: false })).toBe( | ||
| false | ||
| ); | ||
| expect(resolveInternalApiOriginEnabled({ orgFeatureFlags: null, globalDefault: true })).toBe( | ||
| true | ||
| ); | ||
| expect(resolveInternalApiOriginEnabled({ orgFeatureFlags: {}, globalDefault: true })).toBe( | ||
| true | ||
| ); | ||
| }); | ||
| it("lets an org override win in both directions", () => { | ||
| expect( | ||
| resolveInternalApiOriginEnabled({ | ||
| orgFeatureFlags: { internalApiOriginEnabled: true }, | ||
| globalDefault: false, | ||
| }) | ||
| ).toBe(true); | ||
| expect( | ||
| resolveInternalApiOriginEnabled({ | ||
| orgFeatureFlags: { internalApiOriginEnabled: false }, | ||
| globalDefault: true, | ||
| }) | ||
| ).toBe(false); | ||
| }); | ||
| it("ignores invalid overrides and falls back to the global default", () => { | ||
| // Strict z.boolean(): the string "false" must not coerce to an enable. | ||
| expect( | ||
| resolveInternalApiOriginEnabled({ | ||
| orgFeatureFlags: { internalApiOriginEnabled: "false" }, | ||
| globalDefault: false, | ||
| }) | ||
| ).toBe(false); | ||
| expect( | ||
| resolveInternalApiOriginEnabled({ | ||
| orgFeatureFlags: { internalApiOriginEnabled: "true" }, | ||
| globalDefault: false, | ||
| }) | ||
| ).toBe(false); | ||
| expect( | ||
| resolveInternalApiOriginEnabled({ | ||
| orgFeatureFlags: { internalApiOriginEnabled: 1 }, | ||
| globalDefault: false, | ||
| }) | ||
| ).toBe(false); | ||
| // The fallback must follow the global default, not hardcode false. | ||
| expect( | ||
| resolveInternalApiOriginEnabled({ | ||
| orgFeatureFlags: { internalApiOriginEnabled: "false" }, | ||
| globalDefault: true, | ||
| }) | ||
| ).toBe(true); | ||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| it("ignores non-object flag containers", () => { | ||
| expect(resolveInternalApiOriginEnabled({ orgFeatureFlags: [], globalDefault: true })).toBe( | ||
| true | ||
| ); | ||
| expect(resolveInternalApiOriginEnabled({ orgFeatureFlags: "junk", globalDefault: false })).toBe( | ||
| false | ||
| ); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.