Skip to content

feat: add login challenge security helpers#369

Open
hardy-dev-infinilabs wants to merge 25 commits into
mainfrom
pr/framework-login-challenge
Open

feat: add login challenge security helpers#369
hardy-dev-infinilabs wants to merge 25 commits into
mainfrom
pr/framework-login-challenge

Conversation

@hardy-dev-infinilabs
Copy link
Copy Markdown
Contributor

Summary

  • add password challenge helpers for challenge-response style login flows
  • add replay protection middleware and secure transport middleware for sensitive API endpoints
  • add targeted tests and a release note for the new security helpers

Included scope

  • core/security/passwordchallenge/*
  • core/security/replay/*
  • core/api/security.go and its tests

Explicitly excluded

  • agent instance / websocket / embedded API routing changes
  • unrelated core/api/web.go and core/api/api.go work from console_framework

hardy-dev-infinilabs and others added 3 commits May 26, 2026 11:34
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@medcl
Copy link
Copy Markdown
Member

medcl commented May 26, 2026

@copilot add a http_filter to seamless add these options to specific api on purpose: framework/modules/security/http_filters


challenge, ok := store.challenges[challengeID]
if !ok {
return Challenge{}, errors.New("login challenge is invalid")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return Challenge{}, errors.New("login challenge is invalid")
return Challenge{}, errors.New("login challenge not found")

Comment on lines +40 to +41
Method = "challenge"
Algorithm = "PBKDF2-SHA256"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这两个 const 好像没有用到

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

给调用者使用的

Copy link
Copy Markdown
Contributor

Copilot AI commented May 26, 2026

@copilot add a http_filter to seamless add these options to specific api on purpose: framework/modules/security/http_filters

Implemented via commit cec184f: added a new SecurityFilter under modules/security/http_filters that applies secure-transport and replay-protection checks based on per-API handler options (api.SecureTransportOption(...) and api.ReplayProtectionOption()). Also added focused tests for the new option wiring and filter behavior.

hardy-dev-infinilabs and others added 8 commits May 26, 2026 14:57
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ed-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hardy-dev-infinilabs
Copy link
Copy Markdown
Contributor Author

Follow-up changes related to the native account challenge rollout have been pushed to this PR branch:

  • keep framework JWT claims compatible with existing console username / user_id aliases during rollout
  • decorate /account/login responses with the console-consumed fields (username, id, roles, privilege, expires_at)
  • add shared ValidateAuthorizationHeader helper for downstream apps that are moving onto framework session handling
  • add framework POST /account/refresh so the shared account flow can cover refresh as well
  • add coverage for the claims compatibility and refresh path

These are the framework-side compatibility changes needed while console is still converging onto the shared auth/session stack.

…t <223556219+Copilot@users.noreply.github.com>
@hardy-dev-infinilabs
Copy link
Copy Markdown
Contributor Author

Additional follow-up for the same rollout has now been pushed:

  • framework can now accept app-provided password-login fallback providers, so products can move /account/login onto the shared framework handler without keeping a separate login implementation
  • session token responses now support app-provided decorators, which lets console keep its current privilege response semantics while reusing framework login/refresh
  • shared password material generation was extracted so downstream apps can stop carrying their own password-challenge helper wrappers

This is the next step toward removing console-owned /account/* auth flow code while keeping the existing frontend contract.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hardy-dev-infinilabs
Copy link
Copy Markdown
Contributor Author

Follow-up for the shared account-flow rollout:

  • replaced direct panics in modules/security/rbac/user.go for user-facing validation/business conflicts with explicit HTTP errors
  • CreateUser on the provider path now returns normal errors instead of aborting on weak passwords / duplicate emails
  • added a focused test to lock the weak-password validation behavior

This keeps the native account management path aligned with the earlier challenge-login/account-flow changes in this PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hardy-dev-infinilabs
Copy link
Copy Markdown
Contributor Author

Follow-up for the shared account-flow rollout:

  • removed remaining runtime panics in the framework auth/security request path where user input or backend failures should surface as normal errors
  • UserSessionInfo.IsValid() now returns false instead of panicking, so auth filter fallback and invalid-token handling keep following the intended error path
  • RBAC role/principal/entity helpers now return explicit HTTP errors or safe deny/empty results instead of aborting the request
  • added focused tests for incomplete session users, invalid claims, and nil-session token issuance

This is the cleanup pass after the earlier account-flow convergence work in this PR.

hardy-dev-infinilabs and others added 2 commits May 26, 2026 17:45
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hardy-dev-infinilabs
Copy link
Copy Markdown
Contributor Author

Small structure cleanup for reviewability:

  • removed the standalone core/security/account_flow.go
  • moved password-login fallback registration into core/security/service_registry.go alongside the other auth registries
  • moved token-response decorator registration into core/security/session.go alongside session issuance/decoration
  • no behavior change; this is only rehoming the same extension points to more natural locations

The console bridge keeps using the same hooks, but the framework side now reads as normal registry/session extension instead of a migration-specific file.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hardy-dev-infinilabs
Copy link
Copy Markdown
Contributor Author

Follow-up reviewability cleanup:

  • removed the dead lookupAccountByLogin compatibility wrapper and now call the native RBAC lookup directly
  • duplicate login/email matches now surface as explicit errors instead of being silently treated as "not found"
  • the legacy-password -> challenge-material upgrade remains best-effort, but no longer waits for an index refresh before returning from login
  • added focused coverage for the duplicate-account lookup behavior

This keeps the auth flow behavior the same for valid users while making error semantics and migration intent clearer for review.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hardy-dev-infinilabs
Copy link
Copy Markdown
Contributor Author

Follow-up simplification after confirming the rollout only targets new console + new framework together:

  • removed the legacy username / user_id JWT claim aliases from core/security/UserClaims
  • dropped the old-console-specific marshal/unmarshal compatibility layer entirely
  • kept the native framework claim shape (login / userid) only

This reduces review noise and keeps the framework token model product-neutral.

hardy-dev-infinilabs and others added 2 commits May 26, 2026 21:12
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

4 participants