Skip to content

feat(config): derive every Atlas API call from one overridable origin - #8

Open
binyangzhu000-sudo wants to merge 2 commits into
feat/upstream-oidc-rollout-prep-20260818from
feat/configurable-api-base
Open

feat(config): derive every Atlas API call from one overridable origin#8
binyangzhu000-sudo wants to merge 2 commits into
feat/upstream-oidc-rollout-prep-20260818from
feat/configurable-api-base

Conversation

@binyangzhu000-sudo

Copy link
Copy Markdown
Contributor

背景

src/constants.ts 把三个 Atlas API 地址写死成生产:

export const API_BASE = "https://api.atlascloud.ai/api/v1";
export const LLM_API_BASE = "https://api.atlascloud.ai/v1";
export const PUBLIC_API_BASE = "https://api.atlascloud.ai/public/v1";

后果是 staging 部署在拿生产数据做测试:用户身份由 staging 认证,API 调用却打生产。所以 staging 上只有生产的 API key 能用、凭据校验查的是错的账号库、而任何计费型测试都会扣真实账号的钱。

改了什么

三个地址统一从一个 origin 派生,可用 ATLASCLOUD_API_BASE_URL 覆盖,默认仍是生产:

ATLASCLOUD_API_BASE_URL=https://api.dev.atlascloud.ai

几个刻意的约束

  • 生产版本拒绝任何覆盖,直接启动失败。生产插件悄悄连到另一个 Atlas 不会自己暴露——它会在客户看到别人的数据时才暴露,所以宁可起不来。
  • 必须是裸 origin。三个 API 路径是拼在它后面的,带 path 会静默产生 /api/v1/api/v1/...
  • 拒绝 URL 里的凭据非 loopback 必须 https(本机开发允许 http://127.0.0.1)。
  • 末尾斜杠会被规范化,不会因为写法不同被拒。

验证

tsc 干净,npm test 82/82 通过(原 76 + 新增 6)。新增测试覆盖:默认值、合法覆盖、末尾斜杠、loopback 例外、非 loopback http 拒绝、生产覆盖拒绝(含"显式填默认值不算覆盖")、带 path/query/凭据/非法 URL 的拒绝、以及三个派生地址确实同源。

为什么现在需要它

V2(首次登录自动绑定 API key,#4没法在 dev 验证:dev 插件会去问 dev 的 kubedl 要 key,拿到的却是 dev 库的 key,而插件的校验打的是生产 API,必然失败并回落到手贴。有了这个开关,dev 插件可以整体指向 dev 的 Atlas,形成自洽闭环。

注意:光有这个改动还不够——dev 的 kubedl 目前没有对外 HTTPS 入口api.dev.atlascloud.ai / console.dev.atlascloud.ai/api/v1/health 都是 401,只有集群内直连才 200)。要在 dev 端到端验证 V2,还需要给它配一个 ingress。

The three Atlas base URLs were hard-coded to production, so a staging
deployment authenticated users against staging while calling the production
API. Only production API keys worked there, credential validation checked the
wrong account universe, and any billable test run charged a real account.

Derive all three from a single origin, overridable with
ATLASCLOUD_API_BASE_URL and defaulting to production, so an isolated
environment can be pointed at its own Atlas without patching call sites.

The override is refused outright in a production release. A production plugin
quietly talking to a different Atlas is not a failure that announces itself —
it surfaces when a customer sees another account's data — so it fails at
startup instead.

The value must be a bare origin: the API paths are appended to it, and a path
here would silently produce /api/v1/api/v1/... Credentials in the URL and
plaintext HTTP are rejected, the latter except for loopback so a local Atlas
can still be used during development.
Cluster-internal Service DNS (*.svc.cluster.local) never traverses the
public network, and demanding TLS there pushes toward the worse fix of
publishing internal services behind a public ingress. Public hostnames
still require https, and a hostname merely containing the suffix inside
a longer public domain stays rejected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant