Skip to content

[client] Don't ask for an SSO login when the login never reached management - #6983

Open
lixmal wants to merge 2 commits into
mainfrom
worktree-daemon-login-transport-error
Open

[client] Don't ask for an SSO login when the login never reached management#6983
lixmal wants to merge 2 commits into
mainfrom
worktree-daemon-login-transport-error

Conversation

@lixmal

@lixmal lixmal commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Describe your changes

The daemon treated every failed login attempt as "this peer needs to log in", so a login that never reached the management server (unreachable, restarting, dial timeout) surfaced as an SSO prompt with a device code instead of a retryable error. A netbird up that happened to run while management was briefly away asked the user to re-authenticate, even though the session was still valid.

  • Only start the SSO flow when management actually refused the peer's credentials; return any other login failure so the CLI's existing backoff can retry it
  • Keep the login outcome that was already classified by the login attempt, matching how the setup-key and JWT paths already handle it

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why): internal error handling in the daemon, no user-facing surface changes.

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Bug Fixes
    • Improved login handling when Management is unreachable by returning a retryable error and preserving the failed-login state.
    • Login now starts the SSO flow only when it’s actually required, avoiding incorrect SSO triggers on other error types.
    • Permission-denied during the auth check now correctly proceeds into the SSO sign-in flow.
  • Tests
    • Added coverage for Management connectivity failures, auth refusal behavior, and SSO login transition outcomes.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fcc0bc0c-8848-4bfe-97b2-1623577d9818

📥 Commits

Reviewing files that changed from the base of the PR and between 48578b8 and 6789014.

📒 Files selected for processing (1)
  • client/server/login_outcome_test.go

📝 Walkthrough

Walkthrough

The server adds an injectable login-attempt seam and updates login outcome handling. Tests verify unreachable Management errors are returned directly, while permission-denied refusals proceed toward SSO flow setup.

Changes

Login outcome handling

Layer / File(s) Summary
Injectable login attempt routing
client/server/server.go
Adds loginAttemptFn and routes initial, setup-key, and SSO completion login attempts through attemptLogin, with the existing implementation as the production fallback.
Login outcome branching and tests
client/server/server.go, client/server/login_outcome_test.go
Records and returns non-StatusNeedsLogin outcomes without starting SSO, while permission-denied refusals continue into SSO setup; tests cover both cases and invalidate the profile key for immediate setup failure.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Login
  participant Management
  participant StateRecorder
  participant SSOFlow

  Client->>Login: Login request
  Login->>Management: attempt login
  Management-->>Login: status and error
  alt Management unreachable
    Login->>StateRecorder: set StatusLoginFailed
    Login-->>Client: return transport error
  else authentication refusal
    Login->>SSOFlow: start SSO flow
    SSOFlow-->>Client: return flow setup result
  end
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main behavioral change: returning non-credential login failures instead of starting SSO.
Description check ✅ Passed The description matches the template and covers the change, testing, and docs status; the issue ticket/link section is the only blank part.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree-daemon-login-transport-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@client/server/login_outcome_test.go`:
- Around line 63-66: Strengthen the Login test around the
StatusNeedsLogin/refusal branch by asserting that the SSO setup transitions to
StatusLoginFailed when the deliberately invalid key is processed. Keep the
existing error and NotErrorIs assertions, and verify the resulting login status
through the state or outcome symbol exposed by the test flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 915d27f0-8b0e-432b-b5a1-50e594fc7aee

📥 Commits

Reviewing files that changed from the base of the PR and between c1f0006 and 48578b8.

📒 Files selected for processing (2)
  • client/server/login_outcome_test.go
  • client/server/server.go

Comment thread client/server/login_outcome_test.go
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown

Release artifacts

Built for PR head 6789014 in workflow run #17297.

Artifact Link
All release artifacts Download
Linux packages Download
Windows packages Download
macOS packages Download
UI artifacts Download
UI macOS artifacts Download

GHCR images (amd64)

This comment is updated by the Release workflow. Artifact links expire according to the workflow retention policy.

@sonarqubecloud

Copy link
Copy Markdown

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