Skip to content

Bug 2027006,2036743: Fetch remote policies on Felt UI before launching Firefox#790

Open
victhorlopez wants to merge 1 commit intomozilla:enterprise-mainfrom
victhorlopez:bug/2027006
Open

Bug 2027006,2036743: Fetch remote policies on Felt UI before launching Firefox#790
victhorlopez wants to merge 1 commit intomozilla:enterprise-mainfrom
victhorlopez:bug/2027006

Conversation

@victhorlopez
Copy link
Copy Markdown
Contributor

@victhorlopez victhorlopez commented Apr 24, 2026

Description

Bugzilla: Bug-2027006

  • Moves remote policy fetching from Firefox startup to the Felt UI login flow, so policies are available before Firefox launches, and we can avoid extra startups in case of failures
  • Fetches user info and remote policies in parallel after SSO authentication completes
  • Passes policies to Firefox via a new IPC message
  • If either fetch fails, signs the user out, clears SSO cookies, signouts the user, and resets the Felt UI to the login page with a connection error

Dependencies / Related Issues

  • Depends on:

Screenshots


Testing

  • Added tests
  • Manual testing performed
  • I put a throw with a counter (to make it fail only the first time), and see how the sso works but fails on fetch

@victhorlopez victhorlopez self-assigned this Apr 24, 2026
@victhorlopez victhorlopez force-pushed the bug/2027006 branch 5 times, most recently from 3618d0f to 320b7b4 Compare April 29, 2026 10:29
[userInfo, remotePolicies] = await Promise.all([
lazy.ConsoleClient.getLoggedInUserInfo(),
lazy.ConsoleClient.getRemotePolicies(),
]);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

should we add here a check for
remotePolicies == "" or == "{}"

and count it as invalid (i.e throw), otherwise we will open firefox and throw there

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.

What is the justification for the try block?

Copy link
Copy Markdown
Contributor Author

@victhorlopez victhorlopez May 5, 2026

Choose a reason for hiding this comment

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

those are network requests, if they throw an exception you end up with a "blank page" in the sso

]);
} catch (e) {
lazy.log.error(`Failed to fetch startup data: ${e}`);
await lazy.ConsoleClient.postSignout().catch(err =>
Copy link
Copy Markdown
Contributor Author

@victhorlopez victhorlopez Apr 29, 2026

Choose a reason for hiding this comment

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

in theory in this step, we actually managed to log in but either getRemotePolicies or getLoggedInUserInfo failed. I assumed we want to clean up everything?

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.

I defer to @1rneh for that

Comment thread browser/extensions/felt/content/window.js Outdated

pub static TOKENS: LazyLock<Arc<RwLock<Tokens>>> =
LazyLock::new(|| Arc::new(RwLock::new(Default::default())));
pub static POLICIES: OnceLock<Arc<String>> = OnceLock::new();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I assumed we write only once?

@victhorlopez victhorlopez requested review from 1rneh and lissyx April 29, 2026 11:53
@victhorlopez victhorlopez marked this pull request as ready for review April 29, 2026 11:54
@gcp gcp requested a review from Copilot April 29, 2026 14:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Moves remote enterprise policy retrieval for Felt from Firefox startup into the Felt UI login flow so policies are available before launching Firefox, and failures can be handled without extra Firefox startups.

Changes:

  • Fetch logged-in user info and remote policies in parallel after SSO completes, and handle failures by signing out/clearing cookies and returning to login with a connection error.
  • Introduce a new Felt IPC/XPCOM API to pass remote policies to Firefox at startup.
  • Update enterprise policy startup fetching logic and add/adjust Felt enterprise tests for the new failure/retry behavior.

Reviewed changes

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

Show a summary per file
File Description
toolkit/components/enterprisepolicies/EnterprisePoliciesParent.sys.mjs Switch Felt startup remote-policy source to Services.felt.getStartupPolicies() and remove Felt-specific shutdown logic.
browser/extensions/felt/content/FeltProcessParent.sys.mjs Fetch user info + policies in parallel; send policies to Firefox via new IPC; add cookie cleanup helper and error-to-login path.
browser/extensions/felt/api.js Add FeltParent:ShowLogin message handler to reset the Felt UI to the login view with an error.
browser/extensions/felt/content/window.js Listen for reset-to-login to reset the UI to login (with optional error type).
browser/components/enterprise/modules/ConsoleClient.sys.mjs Add postSignout() helper for the new failure path.
browser/extensions/felt/rust/nsIFelt.idl Add sendPolicies() / getStartupPolicies() XPCOM methods for passing startup policies.
browser/extensions/felt/rust/src/message.rs Add Policies(String) IPC message and bump IPC version.
browser/extensions/felt/rust/src/components.rs Implement the new XPCOM methods to send/store startup policy payload.
browser/extensions/felt/rust/src/client.rs Receive/store the policies payload from IPC on the Firefox side.
browser/extensions/felt/rust/src/utils.rs Add global storage for startup policies.
testing/enterprise/test_felt_browser_init_failures.py Extend the failure test to assert error UI and successful login after failure.
testing/enterprise/felt_tests.py Make the SSO test server simulate “existing session cookie skips login form” behavior.
Comments suppressed due to low confidence (1)

toolkit/components/enterprisepolicies/EnterprisePoliciesParent.sys.mjs:1073

  • fetchPoliciesOnStartup() no longer fetches remote policies for non-Felt runs: res remains undefined when Services.felt?.isFeltBrowser() is false, which makes the subsequent !res?.policies branch always set _failed = true and prevents policies from loading until/if polling later succeeds. This looks like an unintended regression; consider keeping the previous lazy.ConsoleClient.getRemotePolicies() call for the non-Felt path (and optionally falling back to it if getStartupPolicies() throws/returns invalid JSON in the Felt path).
    let res;
    try {
      if (Services.felt?.isFeltBrowser()) {
        res = JSON.parse(Services.felt.getStartupPolicies());
      }
    } catch (e) {
      console.error(`Failed to fetch remote policies on startup: ${e}`);
      this._failed = true;
      return;
    }
    if (!res?.policies) {
      console.error(
        `No policies were found in the response: ${JSON.stringify(res)}.`
      );
      this._failed = true;
    } else {

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

Comment thread browser/extensions/felt/content/FeltProcessParent.sys.mjs Outdated
Comment thread browser/extensions/felt/rust/src/client.rs
@victhorlopez victhorlopez added enhancement New feature or request branch:main PR that should be merged on enterprise-main branch labels May 5, 2026
Comment thread browser/components/enterprise/modules/ConsoleClient.sys.mjs Outdated
resetFeltFirefoxWindowReady();
gFeltFirefoxReadyNotified = false;

this.lastRemotePolicies = remotePolicies;
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.

Since we persist here, do we want to persist also on disk? Would it make any sense? @1rneh what is your opinion?

Copy link
Copy Markdown
Contributor Author

@victhorlopez victhorlopez May 5, 2026

Choose a reason for hiding this comment

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

just to add context on why I am saving this.. it is because if firefox crashes, we need to restart it instantly ( and it uses another path), but.... now I have another question, is this well behaved if the policies changed during runtime? Maybe 1rneh had another idea, to populate also the policies storage from the browser and populate the storage, cause otherwise we might start with old policies?

Comment on lines +743 to +745
// Clear SSO cookies so the provider does not auto-authenticate
// on the next login attempt.
this.removeAllCookies();
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.

I think we should do that earlier.

Copy link
Copy Markdown
Contributor Author

@victhorlopez victhorlopez May 5, 2026

Choose a reason for hiding this comment

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

Can you elaborate what would be optimal?

As of now here the cookies are deleted after trying to signout, we did successfully SSO but something failed in whoami/policies

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.

technically since it's private browsing, even quickly after the <browser> is dismissed it's already gone, so I think reloading the window would already be enough

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me know what would you do in here, (also to have an optimal user experience), cause I tried some things and did not manage to make it work properly until I cleared the cookies (i.e I had problems if I was trying to login a second time)

// on the next login attempt.
this.removeAllCookies();
Services.cpmm.sendAsyncMessage("FeltParent:ShowLogin", {
reason: "felt-browser-error-connection",
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.

Likely we want a more focused error message, but this is UX we should discuss with Matthew ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is related to your question about what we type of exceptions we can get.. 401 should be handled already(would be weird to get it in this step but you never know), so I would expect here to get a no connection error/ server errors etc (or no policies setup on the console).

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did some changes based on your comment, I hope I went in the right direction.

Regarding like the others, the other they "reset the window", in this case the form is always visible, so we should not call show window cause it opens another window.

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.

I think the actor solution is better

break;
}

this.loggedInUserInfo = userInfo;
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.

Why do we add this now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because this changed in here

         - this.loggedInUserInfo =
         -  await lazy.ConsoleClient.getLoggedInUserInfo();
         + let userInfo, remotePolicies;
         + try {
         +  // TODO: Bug 2003001 - Pass user info from Felt to Firefox to avoid network request on startup
         +   [userInfo, remotePolicies] = await Promise.all([
         +    lazy.ConsoleClient.getLoggedInUserInfo(),
         +     lazy.ConsoleClient.getRemotePolicies(),
         +  ]);

Comment thread browser/extensions/felt/content/FeltProcessParent.sys.mjs Outdated
Comment on lines +1061 to +1063
if (Services.felt?.isFeltBrowser()) {
res = JSON.parse(Services.felt.getStartupPolicies());
}
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.

WOo, that is rather intrusive, I dont know how it collides with the work @1rneh is doing on policies

@victhorlopez victhorlopez marked this pull request as draft May 5, 2026 14:41
@victhorlopez victhorlopez removed the request for review from 1rneh May 5, 2026 14:41
@victhorlopez victhorlopez force-pushed the bug/2027006 branch 3 times, most recently from cee2307 to 609ac61 Compare May 5, 2026 17:11
@victhorlopez victhorlopez force-pushed the bug/2027006 branch 2 times, most recently from 520f691 to 69d04c3 Compare May 5, 2026 18:06
@victhorlopez
Copy link
Copy Markdown
Contributor Author

@github-copilot review

@victhorlopez victhorlopez changed the title Bug 2027006: Fetch remote policies on Felt UI before launching Firefox Bug 2027006,2036743: Fetch remote policies on Felt UI before launching Firefox May 6, 2026
@victhorlopez victhorlopez marked this pull request as ready for review May 6, 2026 11:38
@victhorlopez victhorlopez requested a review from 1rneh May 6, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch:main PR that should be merged on enterprise-main branch enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants