Skip to content

fix: skip linking email identity that matches primary account's email - #136

Open
emsearcy wants to merge 2 commits into
mainfrom
lfxv2-2662-link-email-guard
Open

fix: skip linking email identity that matches primary account's email#136
emsearcy wants to merge 2 commits into
mainfrom
lfxv2-2662-link-email-guard

Conversation

@emsearcy

@emsearcy emsearcy commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Two related fixes for Auth0 email/profile sync edge cases found during the LFXV2-2662 alignment analysis:

  1. linkEmailIdentity checked for existing secondary "email" identities before creating/linking a new one, but never compared the candidate email against the primary account's own top-level email. This let the backfill and live sync paths link a redundant secondary identity duplicating the account's own primary email. Adds a guard that skips linking (idempotent no-op, logged as a warning) whenever the candidate email case-insensitively matches the primary account's own email.

  2. Neither syncProfileToAuth0 nor linkEmailIdentity checked whether the Auth0 account was blocked before writing to it. Blocked accounts are effectively deprovisioned, so pushing new profile data or linking new secondary email identities to them is unwanted. This addresses the ALIGNED / BLOCKED (and similar *_BLOCKED drilldown) buckets identified in the LFXV2-2662 alignment analysis: both functions now no-op (log a warning, return nil) when the primary Auth0 account is blocked.

Jira

LFXV2-2662

Testing

  • go build ./...
  • go test ./cmd/lfx-v1-sync-helper/... -run 'TestLinkEmailIdentity|TestSyncProfileToAuth0Blocked|TestSyncMergedUserProfile' -v
  • make check

🤖 Generated with GitHub Copilot (via OpenCode)

linkEmailIdentity previously only checked for existing secondary
'email' identities before creating/linking a new one, but never
compared the candidate email against the primary account's own
top-level email. This let the backfill and live sync paths link a
redundant secondary identity duplicating the account's own primary
email.

Add a guard that skips linking (idempotent no-op) whenever the
candidate email case-insensitively matches the primary account's
own email, logging a warning since this indicates upstream data
misalignment worth investigating.

Assisted-by: github-copilot:claude-sonnet-5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Copilot AI review requested due to automatic review settings July 17, 2026 23:13
@emsearcy
emsearcy requested a review from a team as a code owner July 17, 2026 23:13

Copilot AI 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.

Pull request overview

Prevents redundant Auth0 secondary identities when an alternate email matches the account’s primary email.

Changes:

  • Adds a case-insensitive primary-email guard.
  • Adds exact-case and mixed-case regression tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cmd/lfx-v1-sync-helper/auth0_mgmt.go Skips redundant identity linking.
cmd/lfx-v1-sync-helper/auth0_identity_test.go Tests primary-email matching behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Blocked Auth0 accounts are treated as inactive/deprovisioned. Both
syncProfileToAuth0 and linkEmailIdentity now check the primary
account's Blocked flag right after reading it and no-op (log a
warning, return nil) instead of pushing profile updates or linking
new secondary email identities to a blocked account.

This covers the ALIGNED/BLOCKED (and similar BLOCKED-drilldown)
buckets from the LFXV2-2662 alignment analysis: accounts flagged as
blocked in Auth0 should not receive further writes from the v1 sync
paths (live handlers and backfill), since they are effectively
deprovisioned.

Assisted-by: github-copilot:claude-sonnet-5
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Copilot AI review requested due to automatic review settings July 21, 2026 18:07

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment on lines +178 to +181
if existing.GetBlocked() {
logger.With("auth0_user_id", auth0UserID).
WarnContext(ctx, "Auth0 user is blocked, skipping profile sync")
return nil
Comment on lines +239 to +242
if primaryUser.GetBlocked() {
logger.With("auth0_user_id", primaryAuth0ID, "email", email).
WarnContext(ctx, "Auth0 user is blocked, skipping email link")
return nil
Comment on lines +249 to +252
if strings.EqualFold(primaryUser.GetEmail(), email) {
logger.With("auth0_user_id", primaryAuth0ID, "email", email).
WarnContext(ctx, "email matches primary account's own email, skipping link")
return nil
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.

2 participants