Skip to content

fix(v2): keep the global VPC network when a function sets only egress - #2004

Open
Ultranmus wants to merge 1 commit into
firebase:masterfrom
Ultranmus:fix/vpc-merge-global
Open

Ultranmus wants to merge 1 commit into
firebase:masterfrom
Ultranmus:fix/vpc-merge-global

Conversation

@Ultranmus

@Ultranmus Ultranmus commented Nov 30, 2026 •

Copy link
Copy Markdown

Description

Fixes #2002.

A function that sets only vpcConnectorEgressSettings (or vpcEgress) no longer drops a vpcConnector set in setGlobalOptions. The deploy used to fail with "VPC settings on fn must specify either 'connector' or 'networkInterfaces'".

optionsToEndpoint builds a complete vpc object for the global options and another for the function's options, and each provider merges them with a shallow spread, so the function's vpc replaced the global one. This adds mergeVpc() to src/v2/options.ts and uses it in every v2 provider that builds an endpoint from global and function options (18 endpoints in 15 files, next to the existing labels merge):

  • The function's network (connector or networkInterfaces) replaces the global network when the function sets one. Otherwise the global network is kept. Setting a different kind replaces it, so a merged vpc never has both.
  • The function's egressSettings replaces the global one when the function sets it. Otherwise the global egress setting is kept.
  • A function whose vpc is a reset value still opts out of VPC.

The legacy __trigger annotations keep these options as flat keys, so the spread already merged them correctly; only __endpoint changes. v1 has no global options merge.

This only touches how global and function options are combined, not how optionsToEndpoint reads RESET_VALUE, so it should not conflict with #1978.

Code sample

setGlobalOptions({ vpcConnector: "my-connector" });

exports.fn = onRequest({ vpcConnectorEgressSettings: "ALL_TRAFFIC" }, handler);
// __endpoint.vpc: { connector: "my-connector", egressSettings: "ALL_TRAFFIC" }
// (was { egressSettings: "ALL_TRAFFIC" })

Testing

  • mergeVpc unit tests in spec/v2/options.spec.ts: no vpc, global only, function only, egress only over a global connector or global network interfaces, a connector only over a global egress, a different network kind, egress override, a function resetting only its egress, and both reset cases.
  • The issue's repro for onMessagePublished and onRequest in their provider specs.
  • With the old merge (the function's vpc replacing the global one), 6 of the new tests fail, including both repros.
  • npm test: 1012 passing. npm run build and npm run lint pass (no new warnings in the changed files).

Release notes

relnote: Fixed a global vpcConnector being dropped when a v2 function sets only its VPC egress setting. A v2 function that sets its own VPC connector or network interface, but no egress setting, now inherits the global VPC egress setting instead of the default.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new helper function mergeVpc in src/v2/options.ts to correctly merge global and function-specific VPC configurations. It ensures that setting a specific VPC connector/network interface or egress setting does not inadvertently drop the other global VPC configuration. This helper is integrated across all v2 event providers (including AI, Alerts, Database, Firestore, HTTPS, Pub/Sub, and others) to maintain consistent VPC merging behavior. Comprehensive unit tests have been added to verify various merging scenarios and reset behaviors. There are no review comments, and I have no additional feedback to provide.

@IzaakGough IzaakGough 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.

Hi @Ultranmus Thanks for the contribution! This fix looks right to me.

One suggestion for the release note: a function that sets its own vpcConnector or networkInterface but no vpcEgress now inherits the global vpcEgress. Before, it got the platform default (PRIVATE_RANGES_ONLY). It may be worth a line, for example: "A v2 function that sets its own VPC connector or network interface, but no egress setting, now inherits the global VPC egress setting instead of the default."

Comment thread spec/v2/options.spec.ts
).to.deep.equal({ vpc: { connector: "global", egressSettings: "ALL_TRAFFIC" } });
});

it("should reset vpc when the function resets it", () => {

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.

Could we add a case for a function resetting only its egress? Since the global egress is now inherited, vpcEgress: RESET_VALUE is the way to opt out, so it would be good to pin it:

it("should keep the global connector when the function resets only egress", () => {
  expect(
    mergeVpc(
      { vpc: { connector: "global", egressSettings: "ALL_TRAFFIC" } },
      { vpc: { egressSettings: RESET_VALUE } }
    )
  ).to.deep.equal({ vpc: { connector: "global", egressSettings: RESET_VALUE } });
});

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added, thanks. I also put your egress line in the release note.

optionsToEndpoint builds a complete vpc object for the global options and
another for the function's options, and the providers merge them with a
shallow spread. So a function that set only vpcConnectorEgressSettings (or
vpcEgress) replaced the global vpc, the connector was dropped, and the
deploy failed with "VPC settings on fn must specify either 'connector' or
'networkInterfaces'".

Add mergeVpc() and use it in every v2 provider that builds an endpoint from
global and function options. The function's network (connector or network
interfaces) replaces the global one when it sets one, its egress setting
replaces the global one when it sets one, and a reset vpc still opts out.

Fixes firebase#2002
@Ultranmus
Ultranmus force-pushed the fix/vpc-merge-global branch from 45a0b35 to d4405c1 Compare December 4, 2026 16:11
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.

Global vpcConnector is dropped when a function sets only VPC egress

2 participants