fix enterprise-level SAML configuration - #113
Conversation
WalkthroughThe changes introduce enterprise-level SAML handling for user data enrichment in the connector package. A new Changes
Sequence DiagramsequenceDiagram
participant Client
participant userResourceType
participant customClient
participant enterpriseSAML as Enterprise SAML Cache
Client->>userResourceType: List(ctx)
userResourceType->>userResourceType: Check org-level SAML enabled
alt Org SAML disabled
userResourceType->>customClient: loadEnterpriseSAMLData(ctx)
customClient->>enterpriseSAML: Fetch and cache enterprise SAML data
enterpriseSAML-->>userResourceType: SAML data loaded
end
userResourceType->>userResourceType: Iterate user logins
loop For each user
userResourceType->>enterpriseSAML: getEnterpriseSAMLEmail(login)
enterpriseSAML-->>userResourceType: primaryEmail, extraEmails
userResourceType->>userResourceType: Enrich user with email data
end
userResourceType-->>Client: Return enriched users
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
05f0b3f to
4617dd9
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@pkg/connector/user.go`:
- Around line 386-398: The function getEnterpriseSAMLEmail uses named return
values causing a no-named-returns lint failure; change its signature from named
returns to unnamed returns (return types string, []string), introduce local
variables (e.g., primaryEmailLocal, extraEmailsLocal) instead of assigning to
named returns, update all early returns to return explicit values ("" or nil) or
return primaryEmailLocal, extraEmailsLocal at the end, and update the branch
that sets samlData.SAMLNameID and appends samlData.VerifiedEmails to use those
local vars; keep references to enterpriseSAMLData, samlData, SAMLNameID, and
VerifiedEmails to locate the changes.
- Around line 343-349: The current error handling in the enterprise SAML loader
logs the error (l.Warn(..., zap.String("enterprise", enterprise),
zap.Error(err))) then uses "return nil", which aborts the entire loader and
skips remaining enterprises; change this to skip only the failing enterprise by
replacing the early return with a loop continue (or otherwise continue to the
next enterprise in the surrounding iteration) so that other enterprises are
still processed when loadEnterpriseConsumedLicenses/SAML loading fails for one.
| if err != nil { | ||
| l.Warn("failed to load enterprise consumed licenses for SAML data", | ||
| zap.String("enterprise", enterprise), | ||
| zap.Error(err)) | ||
| // Don't fail the sync, just continue without enterprise SAML data | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Don’t stop processing other enterprises on a single load error.
return nil exits the loader, so later enterprises are skipped when multiple are configured. Prefer skipping just the failing enterprise.
♻️ Suggested fix
- if err != nil {
- l.Warn("failed to load enterprise consumed licenses for SAML data",
- zap.String("enterprise", enterprise),
- zap.Error(err))
- // Don't fail the sync, just continue without enterprise SAML data
- return nil
- }
+ if err != nil {
+ l.Warn("failed to load enterprise consumed licenses for SAML data",
+ zap.String("enterprise", enterprise),
+ zap.Error(err))
+ // Don't fail the sync; skip this enterprise and continue.
+ break
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if err != nil { | |
| l.Warn("failed to load enterprise consumed licenses for SAML data", | |
| zap.String("enterprise", enterprise), | |
| zap.Error(err)) | |
| // Don't fail the sync, just continue without enterprise SAML data | |
| return nil | |
| } | |
| if err != nil { | |
| l.Warn("failed to load enterprise consumed licenses for SAML data", | |
| zap.String("enterprise", enterprise), | |
| zap.Error(err)) | |
| // Don't fail the sync; skip this enterprise and continue. | |
| break | |
| } |
🤖 Prompt for AI Agents
In `@pkg/connector/user.go` around lines 343 - 349, The current error handling in
the enterprise SAML loader logs the error (l.Warn(..., zap.String("enterprise",
enterprise), zap.Error(err))) then uses "return nil", which aborts the entire
loader and skips remaining enterprises; change this to skip only the failing
enterprise by replacing the early return with a loop continue (or otherwise
continue to the next enterprise in the surrounding iteration) so that other
enterprises are still processed when loadEnterpriseConsumedLicenses/SAML loading
fails for one.
When SAML is configured at the GitHub Enterprise level (not org level), the org-level SAML GraphQL query returns an error. This change: 1. Catches the "Enterprise SAML identity provider is available" error in hasSAML() and treats org-level SAML as disabled instead of failing 2. When enterprises config is set and org-level SAML is disabled, loads SAML identity data from the enterprise consumed-licenses endpoint 3. Uses enterprise SAML data (saml_name_id, verified_domain_emails) for user email enrichment when org-level SAML is unavailable This fixes sync failures for organizations that rely on enterprise-level SAML authentication. Fixes: CXH-918
4617dd9 to
c2ec7d4
Compare
|
Closing in favor of #112 which was merged. Our PR included additional enterprise SAML data fallback functionality that can be added in a follow-up if needed. |
Summary
When SAML is configured at the GitHub Enterprise level (not org level), the org-level SAML GraphQL query returns an error. This change:
Catches the "Enterprise SAML identity provider is available" error in
hasSAML()and treats org-level SAML as disabled instead of failingWhen
--enterprisesconfig is set and org-level SAML is disabled, loads SAML identity data from the enterprise consumed-licenses endpointUses enterprise SAML data (
saml_name_id,verified_domain_emails) for user email enrichment when org-level SAML is unavailableTesting
Tested against a GitHub Enterprise with Okta SAML configured:
users_with_saml_data: 1Note: Cannot fully replicate the original error locally because our test org's
samlIdentityProviderreturnsnull. Customer validation recommended.Test plan
Fixes: CXH-918