Skip to content

Introduce policy Sync to customize sync state#313

Merged
1rneh merged 7 commits intoenterprise-mainfrom
policy-sync-settings
Feb 19, 2026
Merged

Introduce policy Sync to customize sync state#313
1rneh merged 7 commits intoenterprise-mainfrom
policy-sync-settings

Conversation

@1rneh
Copy link
Contributor

@1rneh 1rneh commented Dec 30, 2025

Exemplary policy setting:

{
  "policies": {
    "SyncSettings": {
      "SyncEnabled": true,
      "TypesEnabled": [
        "bookmarks",
        "passwords"
      ]
    }
  }
}

@1rneh 1rneh requested a review from a team December 30, 2025 21:06
@github-actions
Copy link
Contributor

(Automated Close) Please do not file pull requests here, see https://firefox-source-docs.mozilla.org/contributing/how_to_submit_a_patch.html

@github-actions github-actions bot closed this Dec 30, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Dec 30, 2025
@1rneh 1rneh reopened this Jan 5, 2026
@mozilla mozilla unlocked this conversation Jan 9, 2026
@1rneh 1rneh force-pushed the policy-sync-settings branch 2 times, most recently from 947b459 to 1ab7ce9 Compare February 18, 2026 16:32
if (isEnableSync === true) {
lazy.log.debug("Enable Sync");
if (!isSyncEnabled) {
await this.connectSync(manager);
Copy link
Contributor

@gcp gcp Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can throw from here: https://searchfox.org/firefox-main/rev/150ca809c7243bd6e994f28cc4a3750430783364/services/sync/modules/service.sys.mjs#977

Not sure if it can reasonably happen in our setup, but it would mean all the other policy/settings enforcement code below is skipped. We might want to eat the error and rethrow after we did that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you suggest doing anything in Policies.sys.mjs with that error besides logging the failure? Logging we could also just do here. We could also send back an event inconsistency event to the console, but then Sync would be the only policy to inform the console about such a failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a first step I wrapped connectSync and disconnectSync in a try-catch block.

@@ -991,6 +995,10 @@ Sync11Service.prototype = {

// resets/turns-off sync.
async startOver() {
Copy link
Contributor

@gcp gcp Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the callers, this seems to be more of an internal method that's called as part of a larger state change, so I think you want to do this block higher up to ensure consistency?

https://searchfox.org/firefox-main/rev/150ca809c7243bd6e994f28cc4a3750430783364/browser/base/content/browser-sync.js#2473 (okay, here it would only be false telemetry, so not that big of a deal)

https://searchfox.org/firefox-main/rev/150ca809c7243bd6e994f28cc4a3750430783364/services/sync/modules/SyncDisconnect.sys.mjs#135 (here you would still sign out, enable the service, ...so this usage worries me a bit)

https://searchfox.org/firefox-main/source/services/sync/modules/sync_auth.sys.mjs#213 (this seems harmless, i.e. dead code)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are actually guarding all entry points that trigger the callers:

  • We hide fxa-menu-account-signout-button
  • We hide fxaUnlinkButton in about:preferences#sync
  • We hide the Disconnect... button in about:preferences#sync if sync state is enabled and locked by Sync policy
  • We hide the Turn on syncing... button in about:preferences#sync if sync state is disabled locked by Sync policy

So if the sync state is locked, an update to the Sync policy is the only caller of Weave.startOver() and Weave.configure().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment in startOver and configure to inform that the callers are guarded.

Copy link
Contributor

@gcp gcp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should block startOver() but maybe rather modify its callers to no-op?

You could then maybe change this to assert that this is never called in the faulty state, that is, in Enterprise with changes blocked.

@1rneh 1rneh force-pushed the policy-sync-settings branch from 1ab7ce9 to 31b4561 Compare February 18, 2026 18:42
@1rneh 1rneh force-pushed the policy-sync-settings branch from 31b4561 to a7f58fc Compare February 18, 2026 22:12
@1rneh 1rneh requested a review from gcp February 18, 2026 22:25
Copy link
Member

@Mossop Mossop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell this looks good but my knowledge of the sync service isn't great. Do we have some plans to add automated tests for this?

Comment on lines +3930 to +3942
if (AppConstants.MOZ_ENTERPRISE) {
ChromeUtils.defineESModuleGetters(lazy, {
SyncPolicy: "resource:///modules/policies/SyncPolicy.sys.mjs",
});
Policies.Sync = {
async onBeforeAddons(manager, param) {
await lazy.SyncPolicy.applySettings(manager, param);
},
async onRemove(manager, _) {
await lazy.SyncPolicy.restoreSettings(manager);
}
}
} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative here is to define this as normal and do the MOZ_ENTERPRISE check within the policy to make it non-functional in the non-enterprise case. That might make it easier to find this as it then appears in the normal alphabetical list of policy declarations. But I don't have a strong opinion, leave this as it is if you like

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stretch goal is land this in m-c (Bug 2017722), so this should be temporary anyway.

@1rneh
Copy link
Contributor Author

1rneh commented Feb 19, 2026

From what I can tell this looks good but my knowledge of the sync service isn't great. Do we have some plans to add automated tests for this?

I filed Bug 2017837 to add an end-to-end test for the SyncPolicy.

@1rneh 1rneh force-pushed the policy-sync-settings branch from bd29602 to 56e5d77 Compare February 19, 2026 12:22
@1rneh 1rneh merged commit cdfa618 into enterprise-main Feb 19, 2026
1 check passed
@1rneh 1rneh deleted the policy-sync-settings branch February 19, 2026 16:13
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.

6 participants