Repository navigation
auth: show API key permissions in status - #333
Conversation
somanshreddy
left a comment
There was a problem hiding this comment.
Independent review at a0fb000f — my own pass + an unbiased Codex pass, reconciled at source. The API-key JSON path is genuinely additive, the --human fix is correct, and the tests are strong — but I'm holding the approve on one regression I verified at source (F2), and flagging the merge-order dependency as a hard gate (F1). Codex caught F2; I confirmed it against origin/main and the client transport. tai independently flagged F1 and the scope-fixture nit.
What's solid (verified):
- JSON envelope is unchanged.
mergeStatusEnvelopeproduces{"data":…,"credential":…}, andJSONFormatter.Dataignores thedataFieldarg entirely — so flipping the final call fromAPIDataFieldto""is a no-op for JSON. Existing consumers see strictly additive output. - The
--humanchange is a fix, not a regression.unwrapPayload(v, "data")would strip tov["data"]and drop thecredentialblock;""renders the whole object, so--humannow shows both sections (exactly as the description says). - OAuth is correctly gated away from
/v3/api_keys/self(isAPIKeybranch) — good, and F8-worthy. - Tests assert real behavior and fail on regression: success envelope, 500→hard-fail, 403-on-users/me→degrade (
dataabsent,credentialpresent), malformed-response rejection (invalid/missing/null), 401→ExitAuth with source-aware hint, non-auth 500→no hint mutation.
Blocking (recommend fixing before merge):
-
[F2 — confirmed regression, Codex's catch] OAuth status now renders pre-refresh metadata. This PR hoists
credMeta := credentialMetadata()to the top ofRunE(it needsisAPIKeyearly). But onorigin/mainthe order was the reverse —Execute(gen.UserMeGet)ran first, thencredentialMetadata()— so the metadata was captured after any token refresh. The OAuth transport (client.go:202-205) proactively refreshes a near-expiry access token before the request and persists the new tokens;credentialMetadata()reads the credential from disk/env with no network. So for an OAuth user whose token is near-expiry or expired-but-refreshable — the exact caseauth statusexists to diagnose — the request refreshes successfully while the output reports stale expiry/scope, and forCredentialTypeOAuthExpiredstampsexpired: trueright after a successful refresh. That contradicts the PR's "OAuth behavior is unchanged." Fix: for the OAuth path, re-resolvecredentialMetadata()after the/v3/users/merequest (or snapshot a post-refresh non-secret credential view), and add an expired/near-expiry OAuth test with a fake token endpoint asserting refreshed metadata renders. (API-key path is unaffected — it has no refresh.) -
[F1 — hard merge-order gate; tai + Codex + me]
/v3/api_keys/selfis an unguarded prerequisite. For an API key, the command calls/v3/api_keys/selfand returns the error on any failure (TestAuthStatus_APIKeySelfErrorcodifies a 500 → whole-command failure). If #333 merges before heygen-com/experiment-framework#49894, that endpoint 404s andheygen auth statushard-fails for every API-key caller — theisForbiddendegrade only covers a 403 on/v3/users/me, not a missing self-endpoint. The body says "merge after #49894," but nothing enforces it. Minimum: treat this as a release gate — do not merge this ahead of #49894. Better (belt): degrade specifically on endpoint-unavailable (404) — fall through to the legacy/v3/users/me+ local-credential envelope with a warning — so a premature or out-of-order merge can't brick the command, while still propagating 401/5xx.
Nonblocking / questions (none gate merge on their own):
- [F3, question] Is every 403 from
/v3/users/meonly "missingaccount.read"?isForbiddenconverts any 403 into exit 0 with the account section omitted — a suspension/plan/policy 403 would be silently swallowed as partial success. Consider gating the fallback on a stable insufficient-scope code rather than bare HTTP 403, and document the taxonomy the backend guarantees. - [F4, nonblocking, trade-off]
mergeAPIKeyMetadatablind-copies everydatakey intocredMeta. This is a deliberate forward-compat choice (it absorbs new backend fields likekey_idgenerically — a real virtue), but it also lets a future backend field namedtype/source/useroverwrite the locally-authoritative value. If you want both, keep the opaque copy-through for unknown keys but skip the handful of locally-owned names. Keep scope strings opaque either way so*:*/*:read/videos:readpass through untouched. - [F5, low] The missing-
account.readsuccess path emits{"credential":…}with nodatakey (result = json.RawMessage("{}")), a second successful envelope shape versus the stated stabledata/credentialcontract. Merging from{"data":{}}would keep both top-level keys present. - [F6, low] The
--humantest asserts the credential fields but not that the account section / email renders — so the "renders both sections" claim isn't fully pinned. Add aData:/email assertion, and consider an OAuth--humancase (the shared formatter call changed OAuth output too). - [F7, nit — tai + Codex + me] Scope fixture
"video.read"isn't the real grammar (videos:read/*:read/*:*). Cosmetic — the CLI echoes scope strings opaquely — but it's the value asserted in the human-output test, so it's the one that gets copied. Use realistic scopes.
Net: additive JSON, correct --human fix, strong tests, and clean OAuth gating. Two things to resolve: fix the OAuth pre-refresh metadata (F2), and treat the /v3/api_keys/self dependency as a hard merge-order gate (F1, ideally with a 404 fallback). Happy to stamp once F2 is addressed (or if you decide it's acceptable/out-of-scope, say so and I'll re-evaluate). Docs (README/SKILL) are accurate.
a0fb000 to
b5b754f
Compare
|
Addressed the review in
Validated with |
… status Addresses the review discussion on #333: `auth status` hard-failed on any /v3/api_keys/self error except 404, so a transient 5xx or a misconfigured gateway took down the whole command. `auth status` is a diagnostic -- it is run precisely when something already looks wrong. Failing to *enrich* the credential with permission metadata must not take down the answer the CLI can always give from disk: which credential is in use, and whether it authenticates. Only 401 stays fatal, because "this credential was rejected" is the one question the command must never answer optimistically -- degrading it would render "credential present, from local file" for a revoked key. Everything else degrades, each carrying its own reason, so the routine pre-deploy state and a genuine anomaly never render identically: 401 -> fail loudly (a credential verdict, not enrichment) 404 -> "this server does not support /v3/api_keys/self yet" 403 -> flagged as unexpected: the endpoint carries no x-heygen-required-scopes, so any valid key may introspect itself; a 403 points at a scope-exemption regression or an upstream proxy intercepting the request 5xx/other -> reported with the status, noted as usually transient no HTTP -> network/timeout, noted as usually transient The reason is recorded inline as credential.permissions_unavailable as well as on stderr, so a JSON consumer can tell "we could not read this key's permissions" apart from "this key has none" -- blank scope rows are the wrong answer to the question someone debugging a 403 is actually asking. Side effect worth having: an out-of-order CLI release now omits a labeled section instead of bricking `auth status` for every API-key caller, so the release-ordering discipline stops being load-bearing. TestAuthStatus_APIKeySelfError is replaced rather than amended: it pinned hard-fail-on-500, which is exactly the behaviour being changed. Signed-off-by: tai
|
Pushed What changed.
401 stays fatal because degrading it would render "credential present, from local file" for a revoked key — false reassurance about the single question this command exists to answer. Why 403 is not folded into 404's wording. Reason is inline, not just on stderr. It lands as One test deliberately replaced: Side effect worth having: an out-of-order release now omits a labeled section instead of bricking Verified locally: Note for anyone reviewing against the earlier discussion: the force-push to — tai |
somanshreddy
left a comment
There was a problem hiding this comment.
Re-reviewed at 8da972d — my F2 hold is resolved and every finding is addressed at source. Approving.
Verified each fix at the new head (Terence's b5b754f + tai's 8da972d):
- F2 (the OAuth pre-refresh regression I held on) — fixed. For the OAuth path,
credentialMetadata()is now re-resolved after/v3/users/me(which may proactively refresh + persist the token), so the rendered expiry/scope reflect the refreshed credential.TestAuthStatus_OAuthRefreshReportsUpdatedMetadatais a genuine guard: it seeds an expired token, returns a fresh one from the token endpoint, and assertsBearer fresh_access_tokenwas sent,scope == "openid refreshed_scope",expiredabsent, and a futureexpires_at— it would fail on all three if the re-resolve were reverted. - F1 — degrade-by-class, exactly the agreed taxonomy.
classifyAPIKeySelfFailure:401 → fatal;404 → calm "does not support … yet";403 → loud/anomalous(the endpoint is scope-exempt, so a 403 signals an exemption regression or upstream interception — not under-scoping);5xx/network → transient. The reason lands inline ascredential.permissions_unavailable, so a consumer distinguishes "couldn't read permissions" from "has none." Covered by dedicated tests for 401/403/404/5xx. - F3 — fixed. The
/v3/users/medegrade now gates onCode == "insufficient_api_key_scope", not bare HTTP 403 (TestAuthStatus_APIKeyOtherForbiddenDoesNotDegradepins it). - F4 — fixed.
mergeAPIKeyMetadataskips alocallyOwnedset{source, type, user}, so backend fields can't overwrite locally-authoritative values while the opaque copy-through still absorbs new fields likekey_id. - F5 — fixed. The degrade path emits
{"data":{}}, keeping both top-level keys. - F6 — fixed. The
--humantest now asserts the account section (Data:,Email, email) alongside the credential fields. - F7 — fixed. Fixture uses
videos:read(+key_id), asserted in the human-output test.
CI is 10/10 green at this head. One release-order note (not a code gate): per the thread, the CLI can merge anytime but should not be cut/released until EF#49894 is merged and deployed to prod — and with the 404-degradation now in place, an out-of-order cut is a labeled missing section, not a bricked command. LGTM.
|
Follow-up review addressed: the implementation at |
somanshreddy
left a comment
There was a problem hiding this comment.
Approving at 8da972d. Re-verified the full set at source: every finding from my review is resolved with discriminating tests, and CI is 10/10 green.
- F2 (my hold — OAuth pre-refresh regression): fixed — the OAuth path re-resolves credential metadata after
/v3/users/me, andTestAuthStatus_OAuthRefreshReportsUpdatedMetadatagenuinely guards it (seeds an expired token, serves a fresh one, asserts refreshed scope/expiry + noexpired). - Degrade taxonomy (F1):
classifyAPIKeySelfFailureis exactly the agreed shape — 401 fatal / 404 calm / 403 loud-anomalous (scope-exempt) / 5xx-network transient, reason inline ascredential.permissions_unavailable; one test per class. - F3/F4/F5/F6/F7: coded-403 gate (not bare 403), locally-owned-key overwrite guard,
{"data":{}}envelope, human test asserts the account section,videos:readfixture — all fixed.
Reminder that's a release-checklist item, not a code gate: hold the CLI release cut until EF#49894 is merged + deployed to prod (the 404-degradation makes an out-of-order cut a labeled missing section rather than a broken command). Nice work.
Description
Adds API-key governance details to the existing
heygen auth statuscommand. When the active credential is an API key, the CLI callsGET /v3/api_keys/selfand reports the key name, status, permission mode and scopes, lifecycle timestamps, and expiration alongside the local credential-source information. It continues to include account information when the key hasaccount.read; a valid custom-scoped key without that permission still gets its own metadata instead of failing status. JSON output keeps the existing top-leveldataandcredentialenvelope, while--humannow renders both available sections instead of hiding credential metadata.OAuth behavior is unchanged and does not call the API-key-only endpoint. This is intentionally a hand-written enhancement to
auth status; the backend endpoint is excluded from generated CLI commands and remains excluded from MCP.Backend dependency: heygen-com/experiment-framework#49894 provides the enriched API-key metadata endpoint. The CLI PR can merge independently because endpoint failures degrade to labeled partial status, but this change must not be cut or released until #49894 is merged and deployed to production: https://github.com/heygen-com/experiment-framework/pull/49894
Testing
go test ./...golangci-lint run ./...(v2.11.4)make buildaccount.read, malformed-response, error-path, and human-output tests