Skip to content

Move WEBAUTHN_SESSION to RUNTIME_STORE#4360

Merged
senthalan merged 1 commit into
thunder-id:mainfrom
senthalan:refactor-runtime-store
Jul 26, 2026
Merged

Move WEBAUTHN_SESSION to RUNTIME_STORE#4360
senthalan merged 1 commit into
thunder-id:mainfrom
senthalan:refactor-runtime-store

Conversation

@senthalan

@senthalan senthalan commented Jul 26, 2026

Copy link
Copy Markdown
Member

Purpose

Move WEBAUTHN_SESSION to RUNTIME_STORE


⚠️ Breaking Changes

🔧 Summary of Breaking Changes

WEBAUTHN_SESSION table is removed and the data will be stored in the RUNTIME_STORE

💥 Impact

The data stored in the WEBAUTHN_SESSION will be lost. This is not a critical impact as it's have only the information related to the webauthn session. The users might need go through the flow again.


Approach

Related Issues

  • N/A

Related PRs

  • N/A

Checklist

  • Followed the contribution guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
    • Ran Vale and fixed all errors and warnings
  • Tests provided. (Add links if there are any)
    • Unit Tests
    • Integration Tests
  • Breaking changes. (Fill if applicable)
    • Breaking changes section filled.
    • breaking change label added.

Security checks

  • Followed secure coding standards in WSO2 Secure Coding Guidelines
  • Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.

Summary by CodeRabbit

  • Improvements

    • WebAuthn passkey sessions now use the shared runtime storage system for consistent session handling.
    • Expired runtime data cleanup now runs in configurable batches (with safe defaults) for more efficient maintenance.
  • Database Updates

    • WebAuthn session data is consolidated into runtime storage across PostgreSQL and SQLite.
    • PostgreSQL and SQLite schemas no longer maintain a separate WebAuthn session table; cleanup operations now target the consolidated runtime storage.
  • Tests

    • Updated passkey session store tests to reflect the new runtime-storage behavior.

@senthalan senthalan added skip-changelog Skip generating changelog for a particular PR breaking change The feature/ improvement will alter the existing behaviour trigger-pr-builder Add when the PR is ready for CI; starts the PR Builder for this and all later pushes labels Jul 26, 2026
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

WebAuthn session persistence moved to RuntimeStoreProvider. Runtime-store schema partitions, expiry cleanup, service initialization, the WebAuthn namespace constant, and passkey session-store tests were updated.

Changes

WebAuthn runtime store migration

Layer / File(s) Summary
Runtime-backed session storage
backend/internal/authn/passkey/store.go, backend/internal/authn/passkey/store_test.go, backend/pkg/thunderidengine/providers/constants.go
Passkey sessions are serialized through RuntimeStoreProvider under webauthn:session; tests cover in-memory round trips, missing and deletion behavior, marshal failures, and provider errors.
Runtime store schema and cleanup
backend/dbscripts/runtime_transient/*, backend/scripts/cleanup_runtime_transient_db.sh
WebAuthn sessions use the RUNTIME_STORE_WEBAUTHN_SESSION PostgreSQL partition, and PostgreSQL cleanup deletes expired runtime-store rows in configurable batches.
Passkey service initialization
backend/internal/authn/passkey/init.go, backend/cmd/server/servicemanager.go, backend/internal/authn/passkey/webauthn_service.go
Passkey initialization accepts the runtime store provider and runs after it is created; unused WebAuthn wrapper aliases are removed.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PasskeyService
  participant RuntimeStoreProvider
  participant RUNTIME_STORE
  PasskeyService->>RuntimeStoreProvider: Store or retrieve WebAuthn session
  RuntimeStoreProvider->>RUNTIME_STORE: Persist or query namespaced session
  RUNTIME_STORE-->>RuntimeStoreProvider: Session data or empty result
  RuntimeStoreProvider-->>PasskeyService: Return operation result
Loading

Possibly related PRs

Suggested reviewers: anushasunkada, thamindudilshan, darshanasbg, rajithacharith

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
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.
Title check ✅ Passed The title clearly summarizes the main change: moving WEBAUTHN_SESSION to RUNTIME_STORE.
Description check ✅ Passed The description follows the template and covers purpose, breaking changes, and impact.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 `@backend/internal/authn/passkey/init.go`:
- Around line 23-31: Update the relevant documentation under
docs/content/guides/ to describe the Initialize passkey session-store change:
remove references to Redis/configuration-based selection, identify the shared
RUNTIME_STORE replacement, and provide migration steps for existing self-hosted
deployments moving from the WEBAUTHN_SESSION table to the RUNTIME_STORE
partition, including the updated cleanup behavior.
🪄 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: e2aa1f9a-d5f4-4d7b-b4c7-4748e023451f

📥 Commits

Reviewing files that changed from the base of the PR and between caffca9 and 7dc64d6.

📒 Files selected for processing (14)
  • backend/cmd/server/servicemanager.go
  • backend/dbscripts/runtime_transient/postgres-cleanup.sql
  • backend/dbscripts/runtime_transient/postgres.sql
  • backend/dbscripts/runtime_transient/sqlite.sql
  • backend/internal/authn/passkey/init.go
  • backend/internal/authn/passkey/redisClient_mock_test.go
  • backend/internal/authn/passkey/redis_store.go
  • backend/internal/authn/passkey/redis_store_test.go
  • backend/internal/authn/passkey/store.go
  • backend/internal/authn/passkey/store_constants.go
  • backend/internal/authn/passkey/store_test.go
  • backend/internal/authn/passkey/webauthn_service.go
  • backend/pkg/thunderidengine/providers/constants.go
  • backend/scripts/cleanup_runtime_transient_db.sh
💤 Files with no reviewable changes (6)
  • backend/internal/authn/passkey/store_constants.go
  • backend/internal/authn/passkey/redisClient_mock_test.go
  • backend/internal/authn/passkey/redis_store.go
  • backend/internal/authn/passkey/webauthn_service.go
  • backend/dbscripts/runtime_transient/sqlite.sql
  • backend/internal/authn/passkey/redis_store_test.go

Comment on lines +23 to +31
"github.com/thunder-id/thunderid/pkg/thunderidengine/providers"
)

// Initialize initializes the WebAuthn authentication service.
func Initialize(entitySvc entity.EntityServiceInterface) PasskeyServiceInterface {
var store sessionStoreInterface
if config.GetServerRuntime().Config.Database.RuntimeTransient.Type == provider.DataSourceTypeRedis {
store = newRedisSessionStore(provider.GetRedisProvider())
} else {
store = newSessionStore()
}

return newPasskeyService(entitySvc, store)
func Initialize(
entitySvc entity.EntityServiceInterface,
runtimeStore providers.RuntimeStoreProvider,
) PasskeyServiceInterface {
return newPasskeyService(entitySvc, newSessionStore(runtimeStore))

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

🔴 Documentation Required
This PR introduces user-facing changes that are not covered by documentation updates under docs/.
Please update the relevant documentation before merging.

Missing documentation:

  • Removed Redis/config-based passkey session store selection: Initialize no longer branches on runtime configuration to choose Redis vs. DB-backed session storage; it now always uses the shared runtime store. Document this removed configuration knob and its replacement in a configuration reference or upgrade guide (e.g. docs/content/guides/).
  • WEBAUTHN_SESSION table removal / RUNTIME_STORE migration: the dedicated WEBAUTHN_SESSION table is dropped in favor of a RUNTIME_STORE partition (backend/dbscripts/runtime_transient/postgres.sql), and the cleanup script/table list changed accordingly (backend/scripts/cleanup_runtime_transient_db.sh). Document the required migration steps for existing self-hosted deployments in an upgrade/migration guide under docs/content/guides/.

As per path instructions: "Check whether this change introduces or modifies any of the following: ... Configuration options (YAML/TOML keys, environment variables, deployment settings) ... If ANY of the above are detected and the PR does NOT include corresponding updates under docs/ ... post a single consolidated PR-level comment."

🤖 Prompt for 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.

In `@backend/internal/authn/passkey/init.go` around lines 23 - 31, Update the
relevant documentation under docs/content/guides/ to describe the Initialize
passkey session-store change: remove references to Redis/configuration-based
selection, identify the shared RUNTIME_STORE replacement, and provide migration
steps for existing self-hosted deployments moving from the WEBAUTHN_SESSION
table to the RUNTIME_STORE partition, including the updated cleanup behavior.

Source: Path instructions

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@senthalan
senthalan force-pushed the refactor-runtime-store branch from 7dc64d6 to d656fe8 Compare July 26, 2026 18:35
@senthalan
senthalan enabled auto-merge July 26, 2026 18:54
@senthalan
senthalan added this pull request to the merge queue Jul 26, 2026
Merged via the queue into thunder-id:main with commit d155167 Jul 26, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change The feature/ improvement will alter the existing behaviour skip-changelog Skip generating changelog for a particular PR trigger-pr-builder Add when the PR is ready for CI; starts the PR Builder for this and all later pushes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants