Skip to content

🪪 feat: Option to Sync Only Existing Entra ID Groups - #16638

Open
jtodaroii wants to merge 5 commits into
LibreChat-AI:devfrom
jtodaroii:feat/entra-sync-only-existing-groups
Open

jtodaroii wants to merge 5 commits into
LibreChat-AI:devfrom
jtodaroii:feat/entra-sync-only-existing-groups

Conversation

@jtodaroii

@jtodaroii jtodaroii commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Login-time Entra sync creates a Group for every Entra group the user belongs to, so in large tenants thousands of groups that are never shared with end up in every user's ACL principal list. This adds an opt-in setting, permissions.syncOnlyExistingEntraGroups in librechat.yaml (env fallback ENTRA_ID_SYNC_ONLY_EXISTING_GROUPS), that skips creating missing groups during sync. Membership is still added and removed on groups already in the database, which are created when someone shares a resource with them. Default behavior is unchanged.

Closes #16633

Related to #15830, #16233

How it works

syncsOnlyExistingEntraGroups in packages/api/src/acl/principals.ts resolves the setting: the librechat.yaml value wins when set, otherwise the env flag decides. The OAuth callback runs before the config middleware, so oauth.js resolves the user's app config and passes it to syncUserEntraGroupMemberships, which skips steps 4–6 (fetch details, upsert, add) when the setting is on.

Type of change

  • Feature
  • Performance improvement

Testing

Tested environments/configuration:

  • Database: mongodb-memory-server
  • Settings: librechat.yaml true/false/unset, env flag true/unset

Automated tests:

  • api/server/services/PermissionService.spec.js: missing groups are not fetched or created with the env flag or the YAML setting; the user is still removed from existing groups they left; the YAML setting overrides the env flag. Each new case fails without the change.
  • packages/api/src/acl/principals.spec.ts: precedence of the YAML setting over the env flag.
  • PermissionService.spec.js plus the oauth, oauth.state and admin/auth.refresh route suites: 135 passed; principals.spec.ts: 7 passed.

Screenshots / recordings

No user-facing change

Risk / compatibility

  • New optional config field and env var, off by default.
  • Groups already created by earlier syncs are left in place; the setting stops new ones from being added.

- added `ENTRA_ID_SYNC_ONLY_EXISTING_GROUPS` to skip creating missing groups during login sync
Copilot AI balanced review requested due to automatic review settings October 1, 2026 20: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.

Copilot review overview

🟡 Changes recommended

The toggle lacks required YAML configuration support, and new backend behavior was added to the legacy CJS layer.

Review effort: Balanced
Findings: 3 Low severity

Open (3)
What changed in this PR

Adds an opt-in mode that limits login-time Entra synchronization to groups already stored locally, reducing ACL principal growth.

Changes:

  • Skips missing-group creation when the flag is enabled.
  • Documents the new environment variable.
  • Tests membership additions, removals, and skipped creation.
File Description
.env.example Documents the new toggle.
api/​server/​services/​PermissionService.js Applies existing-group-only synchronization.
api/​server/​services/​PermissionService.spec.js Tests enabled and default behavior.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .env.example
Comment thread api/server/services/PermissionService.js Outdated
Comment thread api/server/services/PermissionService.js Outdated
- added `permissions.syncOnlyExistingEntraGroups` to `librechat.yaml` and moved the setting resolution into `packages/api`
@jtodaroii
jtodaroii marked this pull request as ready for review October 1, 2026 20:38
@codegraph-librechat codegraph-librechat Bot added 🛡️ security review 🗺️ Access Control codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) labels Oct 1, 2026
@codegraph-librechat codegraph-librechat Bot added the 🗺️ Identity & Billing codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) label Oct 9, 2026
@jtodaroii

Copy link
Copy Markdown
Contributor Author

@danny-avila Merged current dev with no conflicts; ready for review. Closes #16633.

@codegraph-librechat codegraph-librechat Bot added the 🗺️ Auth codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) label Oct 19, 2026
…-existing-groups

# Conflicts:
#	librechat.example.yaml
#	packages/data-provider/src/config.ts

This branch has not been deployed

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

Labels

🗺️ Access Control codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) 🗺️ Auth codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) 🗺️ Identity & Billing codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) 🛡️ security review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants