Skip to content

fix: replace panic with proper error handling in EmailMatchingUnaryInterceptor#4744

Merged
kodiakhq[bot] merged 1 commit into
v2from
fix/issue-4743-authentication-panic
Sep 13, 2025
Merged

fix: replace panic with proper error handling in EmailMatchingUnaryInterceptor#4744
kodiakhq[bot] merged 1 commit into
v2from
fix/issue-4743-authentication-panic

Conversation

@markphelps

Copy link
Copy Markdown
Collaborator

Summary

Fixes a panic in the EmailMatchingUnaryInterceptor middleware that occurs when authentication is not found in context (e.g., after pod restarts with in-memory session storage).

  • Root cause: When using OIDC with email_matches patterns and in-memory sessions, pod restarts cause sessions to be lost, leading to GetAuthenticationFrom(ctx) returning nil
  • Previous behavior: Application would panic with "authentication not found in context, middleware installed incorrectly"
  • New behavior: Returns proper errUnauthenticated error like other middleware functions in the same file

Changes

  • Modified internal/server/authn/middleware/grpc/middleware.go: Replace panic with proper error handling following established patterns
  • Updated internal/server/authn/middleware/grpc/middleware_test.go: Update existing test to expect error instead of panic

Test Plan

  • Updated existing test TestEmailMatchingUnaryInterceptorWithNoAuth to verify error handling
  • All authentication middleware tests pass
  • Go linting and formatting checks pass
  • Verified consistent logging level with other authentication scenarios

Backward Compatibility

Maintained - API behavior unchanged, clients still receive 401 Unauthorized responses. Only difference is proper error handling instead of application crash.

Fixes #4743

…terceptor

When using OIDC authentication with email_matches regex patterns and
in-memory session storage, pod restarts caused the application to panic
with "authentication not found in context, middleware installed incorrectly".

Replace the panic with proper error handling that returns errUnauthenticated,
following the same pattern used by other middleware functions in the same file.

- Replace panic with logger.Error() and return errUnauthenticated
- Update existing test to expect error instead of panic
- Maintain consistent logging level with other authentication scenarios

Fixes #4743

Signed-off-by: markphelps <[email protected]>
@markphelps
markphelps requested a review from a team as a code owner September 12, 2025 23:28
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Sep 12, 2025
@dosubot

dosubot Bot commented Sep 12, 2025

Copy link
Copy Markdown

Related Documentation

Checked 3 published document(s). No updates required.

How did I do? Any feedback?  Join Discord

@codecov

codecov Bot commented Sep 12, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.48%. Comparing base (ab6c91e) to head (17d74a7).
⚠️ Report is 1 commits behind head on v2.

Additional details and impacted files
@@             Coverage Diff             @@
##               v2    #4744       +/-   ##
===========================================
+ Coverage   36.92%   62.48%   +25.56%     
===========================================
  Files         124      132        +8     
  Lines       14931    15561      +630     
===========================================
+ Hits         5513     9724     +4211     
+ Misses       8861     5155     -3706     
- Partials      557      682      +125     
Flag Coverage Δ
integrationtests 36.91% <0.00%> (-0.01%) ⬇️
unittests 52.62% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@markphelps
markphelps requested a review from erka September 12, 2025 23:36

@erka erka 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.

nice

@erka erka added automerge Used by Kodiak bot to automerge PRs v2 Flipt v2 labels Sep 13, 2025
@kodiakhq
kodiakhq Bot merged commit 0f104cb into v2 Sep 13, 2025
44 of 45 checks passed
@github-project-automation github-project-automation Bot moved this to Done in Flipt V2 Sep 13, 2025
@kodiakhq
kodiakhq Bot deleted the fix/issue-4743-authentication-panic branch September 13, 2025 12:28
@dosubot

dosubot Bot commented Sep 13, 2025

Copy link
Copy Markdown

Documentation Updates

Checked 3 published document(s). No updates required.

You have 3 draft document(s). Publish docs to keep them always up-to-date

How did I do? Any feedback?  Join Discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Used by Kodiak bot to automerge PRs size:S This PR changes 10-29 lines, ignoring generated files. v2 Flipt v2

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

"authentication not found in context, middleware installed incorrectly" error after pod restarts

2 participants