Pr2 credential chain - #464
Draft
patelspratik wants to merge 11 commits into
Draft
Conversation
patelspratik
force-pushed
the
pr2-credential-chain
branch
from
August 27, 2026 15:34
3b2b051 to
f8d0e25
Compare
patelspratik
force-pushed
the
pr2-credential-chain
branch
from
August 27, 2026 15:45
f8d0e25 to
bda151d
Compare
patelspratik
force-pushed
the
pr2-credential-chain
branch
from
August 27, 2026 18:36
bda151d to
3c8b255
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## pr1-register-resiliency #464 +/- ##
==========================================================
Coverage ? 29.00%
==========================================================
Files ? 140
Lines ? 19795
Branches ? 0
==========================================================
Hits ? 5741
Misses ? 13464
Partials ? 590
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
patelspratik
force-pushed
the
pr2-credential-chain
branch
from
August 27, 2026 21:07
3c8b255 to
f243f41
Compare
drewmalin
reviewed
Aug 27, 2026
Comment on lines
177
to
180
| // Verify the user is authenticated before performing any local side effects. | ||
| if _, err := s.GetCurrentUser(); err != nil { | ||
| return breverrors.WrapAndTrace(err) | ||
| } |
Contributor
There was a problem hiding this comment.
Only do this if we're in the normal non-key mode?
Contributor
Author
There was a problem hiding this comment.
this should really be something like "isAuthenticated". I'll fix this with a better sentinel.
Rebased onto pr1-register-resiliency (post ssh-certs uptake). - BREV_ACCESS_KEY renamed to BREV_API_KEY (never released); all access-key identifiers and messages renamed to API key - Env-key orgs resolve in real time from the backend: the key is bound to exactly one org server-side, so no persisted org is consulted and staleness is impossible. Established logins keep persisted org behavior (APIKeyOrgID / active-org cache) - Single-org invariant hoisted to auth.SingleOrgForAPIKey, shared by register and the general resolution path - GetActiveOrganizationOrNil branches on credential source; env path returns the full org (name included) without a second GetOrganization round-trip - Register with no env key and no persisted credential now prompts the device-flow login (externalNodeAuth fallback) instead of erroring; tokens stay in memory, the login email is cached for pre-fill - Register tests moved/renamed to the APIKey convention
A declined login prompt used to spray stack-traced WARN/ERROR retry chatter through resty and print a multi-frame trace at exit. - auth: return DeclineToLoginError unwrapped from PromptForLogin, GetFreshAccessTokenOrLogin, and LoginAuth.GetAccessToken so the sentinel travels without trace wrapping - store: pass the sentinel through AuthHTTPStore/OnBeforeRequest unwrapped; quiet resty logger suppresses retry chatter for the decline message while logging everything else - cmderrors: friendly message + directive for declined login; no Sentry report, no stack trace - errors: export DeclineToLoginMessage const used by the log filter
patelspratik
force-pushed
the
pr2-credential-chain
branch
from
August 28, 2026 18:38
6a74781 to
c3da984
Compare
The GetCurrentUser probe existed to catch stale JWTs before local side effects. With an API key present that probe is redundant — the key is validated for real by the first API call it authenticates (ResolveOrgForAPIKey) — so skip it and let the org resolution surface any auth failure with a key-specific message.
A declined login prompt is not an error: the user deliberately said no, and the prompt itself is all the context they need. Handle it before any Sentry breadcrumb or switch processing — no breadcrumb, no message, no directive. Remove the now-redundant DeclineToLoginError case from the display switch. Also update TestGetAPIKeyOrgID_MissingPersistedOrgReturnsError to match the renamed MissingAPIKeyOrgIDMessage wording.
The analytics flag serialization sent every explicitly-set flag's value to PostHog, including the hidden global --api-key flag — disclosing the full credential on both success and failure capture paths. Fix generically: - redactFlagValue: values matching a Brev API key (bak- prefix) or a JWT shape (three dot-separated segments) are replaced with "[redacted]"; benign values pass through - MarkFlagSensitive: pflag annotation for flags that must always be redacted regardless of value shape - applied to the global --api-key flag and login's --token/--api-key flags; redaction is centralized in one visitor shared by both capture paths Flag names are still reported, so usage analytics survive.
The factory wired quietRestyLogger over discardLogger, so while the filter itself correctly forwarded non-decline messages, its sink swallowed everything: real HTTP errors, unexpected auth failures, and all debug output were silently dropped. The declined-login test masked this by replacing the sink after construction. Replace discardLogger with stderrLogger (mirrors resty's default: stderr, date+micro, WARN/ERROR RESTY prefixes) and test the full factory chain without sink replacement: declined login stays quiet, unrelated auth errors still reach stderr with their message.
- goprintffuncname: output -> outputf, write -> writef - wrapcheck: the two DeclineToLoginError passthrough returns are deliberate (the sentinel must reach DisplayAndHandleError unwrapped so it renders silently); annotate with //nolint:wrapcheck
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.