Skip to content

Support Firewall for public IPs in VPC#12706

Draft
harikrishna-patnala wants to merge 8 commits intoapache:mainfrom
shapeblue:FWinVPCpublicIP
Draft

Support Firewall for public IPs in VPC#12706
harikrishna-patnala wants to merge 8 commits intoapache:mainfrom
shapeblue:FWinVPCpublicIP

Conversation

@harikrishna-patnala
Copy link
Member

@harikrishna-patnala harikrishna-patnala commented Feb 25, 2026

Description

This PR adds support for firewall rules on public IPs in VPC networks.

Doc PR apache/cloudstack-documentation#633

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@harikrishna-patnala
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@harikrishna-patnala a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16942

Copy link
Contributor

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

This PR adds support for firewall rules on public IPs in VPC networks, which were previously only available for non-VPC isolated networks. This is a major feature addition that enables VPC users to configure ingress/egress firewall rules on their public IP addresses, similar to the functionality available in traditional isolated networks.

Changes:

  • Enabled Firewall service for VPC offerings and networks by removing it from the list of non-supported services
  • Added Firewall capability to VpcVirtualRouterElement by removing the code that previously excluded it
  • Updated UI to show firewall tabs for VPC public IPs in various states (source NAT, static NAT, port forwarding, load balancing)
  • Implemented iptables firewall chain logic in VPC virtual routers to support per-public-IP firewall rules
  • Added database migration to retrofit existing VPC offerings, VPC networks, and VPCs with Firewall service

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
ui/src/views/offering/AddVpcOffering.vue Adds Firewall service with VpcVirtualRouter provider to the list of services when creating VPC offerings
ui/src/views/network/PublicIpResource.vue Updates tab visibility logic to show firewall tab for VPC IPs in various states (source NAT, static NAT, etc.)
systemvm/debian/opt/cloud/bin/cs/CsAddress.py Implements PREROUTING firewall chain jump and firewall chain with default DROP policy for public IPs in VPC routers
systemvm/debian/opt/cloud/bin/configure.py Modifies ACL processing to use AclIP (per-IP firewall) instead of AclDevice for VPC firewall rules
server/src/main/java/org/apache/cloudstack/network/RoutedIpv4ManagerImpl.java Removes VPCVirtualRouter check from isVirtualRouterGateway method for Network parameter
server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java Removes Service.Firewall from the list of non-supported VPC services
server/src/main/java/com/cloud/network/element/VpcVirtualRouterElement.java Re-enables Firewall capability for VPC Virtual Router by removing the code that excluded it
server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java Updates network offering validation to no longer automatically set forVpc=false when Firewall service is included
plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Updates Kubernetes VPC network offering creation to include Firewall service with VPCVirtualRouter provider
engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42210to42300.java Adds database migration to insert Firewall service mappings for existing VPC offerings, networks, and VPCs
engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java Adds Firewall service to default VPC offering providers

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

@blueorangutan
Copy link

[SF] Trillian Build Failed (tid-15532)

@harikrishna-patnala
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@harikrishna-patnala a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 1.19048% with 83 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.92%. Comparing base (a5b6bc3) to head (1022c61).
⚠️ Report is 45 commits behind head on main.

Files with missing lines Patch % Lines
...ava/com/cloud/upgrade/dao/Upgrade42210to42300.java 0.00% 64 Missing ⚠️
...java/com/cloud/upgrade/DatabaseUpgradeChecker.java 0.00% 6 Missing ⚠️
...ain/java/com/cloud/network/vpc/VpcManagerImpl.java 16.66% 5 Missing ⚠️
...java/com/cloud/server/ConfigurationServerImpl.java 0.00% 4 Missing ⚠️
...ache/cloudstack/network/RoutedIpv4ManagerImpl.java 0.00% 2 Missing ⚠️
...tack/engine/orchestration/NetworkOrchestrator.java 0.00% 1 Missing ⚠️
...bernetes/cluster/KubernetesClusterManagerImpl.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #12706      +/-   ##
============================================
+ Coverage     17.89%   17.92%   +0.03%     
- Complexity    16092    16159      +67     
============================================
  Files          5936     5939       +3     
  Lines        532734   533229     +495     
  Branches      65165    65250      +85     
============================================
+ Hits          95347    95600     +253     
- Misses       426711   426887     +176     
- Partials      10676    10742      +66     
Flag Coverage Δ
uitests 3.66% <ø> (-0.02%) ⬇️
unittests 19.03% <1.19%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

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

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


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

@harikrishna-patnala
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@harikrishna-patnala a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16957

@harikrishna-patnala
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@harikrishna-patnala a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16959

@harikrishna-patnala
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@harikrishna-patnala a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16983

Copy link
Contributor

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

Copilot reviewed 11 out of 13 changed files in this pull request and generated 7 comments.


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

Comment on lines +148 to +155
// VPC IPs with static nat have firewall (only if associatednetworkid present)
if (this.resource.isstaticnat) {
if (this.resource.virtualmachinetype === 'DomainRouter') {
this.tabs = this.defaultTabs.concat(this.$route.meta.tabs.filter(tab => tab.name === 'vpn'))
let tabs = this.defaultTabs.concat(this.$route.meta.tabs.filter(tab => tab.name === 'vpn'))
if (this.resource.associatednetworkid) {
tabs = this.defaultTabs.concat(this.$route.meta.tabs.filter(tab => ['vpn', 'firewall'].includes(tab.name)))
}
this.tabs = tabs
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

The updated comment says “VPC IPs with static nat have firewall…”, but in the virtualmachinetype === 'DomainRouter' branch the code still only adds the vpn tab unless associatednetworkid is present. Either adjust the comment to match the actual behavior, or update the tab logic to reflect the intended UX.

Copilot uses AI. Check for mistakes.
while (networksRs.next()) {
long networkId = networksRs.getLong(1);
try (PreparedStatement insertService = conn.prepareStatement(
"INSERT INGORE INTO `cloud`.`ntwk_service_map` " +
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

The SQL statement string has a typo: INSERT INGORE should be INSERT IGNORE. As written, this migration will fail at runtime when updating ntwk_service_map.

Suggested change
"INSERT INGORE INTO `cloud`.`ntwk_service_map` " +
"INSERT IGNORE INTO `cloud`.`ntwk_service_map` " +

Copilot uses AI. Check for mistakes.

for (String filePath : filesPathUnderViewsDirectory) {
LOGGER.debug("Executing PROCEDURE script [{}].", filePath);
LOGGER.debug(String.format("Executing PROCEDURE script [%s].", filePath));
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

Avoid String.format inside LOGGER.debug(...) here: it eagerly allocates even when debug logging is disabled and bypasses SLF4J parameterized logging. Prefer LOGGER.debug("Executing PROCEDURE script [{}].", filePath) (and similarly after normalizing filePath if you want the logged value to match what is executed).

Suggested change
LOGGER.debug(String.format("Executing PROCEDURE script [%s].", filePath));
LOGGER.debug("Executing PROCEDURE script [{}].", filePath);

Copilot uses AI. Check for mistakes.
filePath = filePath.substring(1);
}

InputStream viewScript = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

getResourceAsStream(filePath) can return null; runScript(conn, viewScript) will then throw a NullPointerException (not caught in runScript). Add a null check and throw a CloudRuntimeException that includes the resolved filePath to make failures actionable.

Suggested change
InputStream viewScript = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
InputStream viewScript = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
if (viewScript == null) {
String message = String.format("Unable to find PROCEDURE script resource [%s] on the classpath.", filePath);
LOGGER.error(message);
throw new CloudRuntimeException(message);
}

Copilot uses AI. Check for mistakes.
Comment on lines +445 to 449
LOGGER.debug(String.format("Executing VIEW script [%s].", filePath));
if (filePath.startsWith("/")) {
filePath = filePath.substring(1);
}

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

Same as above: String.format eagerly builds the message even when debug logging is disabled. Prefer SLF4J parameterized logging (LOGGER.debug("Executing VIEW script [{}].", filePath)) and consider logging the normalized path if that’s what is executed.

Suggested change
LOGGER.debug(String.format("Executing VIEW script [%s].", filePath));
if (filePath.startsWith("/")) {
filePath = filePath.substring(1);
}
if (filePath.startsWith("/")) {
filePath = filePath.substring(1);
}
LOGGER.debug("Executing VIEW script [{}].", filePath);

Copilot uses AI. Check for mistakes.
filePath = filePath.substring(1);
}

InputStream viewScript = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

Same null-safety issue for view scripts: if getResourceAsStream(filePath) returns null, runScript will NPE. Add an explicit null check and fail with a clear exception that includes the script path.

Suggested change
InputStream viewScript = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
InputStream viewScript = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
if (viewScript == null) {
String message = String.format("VIEW script resource [%s] could not be found on the classpath.", filePath);
LOGGER.error(message);
throw new CloudRuntimeException(message);
}

Copilot uses AI. Check for mistakes.
Comment on lines +528 to +533
services.push({
name: 'Firewall',
provider: [
{ name: 'VpcVirtualRouter' }
]
})
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

Firewall is only added to the services list for the non-NSX/non-Netris path. Since the backend changes add Firewall support to VPC offerings (including NSX/Netris VPC offerings via VpcVirtualRouter), the UI should also include the Firewall service in the NSX and Netris branches; otherwise those offerings can’t be configured with Firewall from the UI.

Copilot uses AI. Check for mistakes.
Copy link
Member

@vishesh92 vishesh92 left a comment

Choose a reason for hiding this comment

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

I had some doubts about a few changes. Left some comments.

updateVpcOfferingsWithFirewallService(conn);
}

private void updateNetworkDefaultOfferingsForVPCWithFirewallService(Connection conn) {
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if we should update the existing service offerings. IMO, it would be better to add new service offerings. This will change the behavior of a network after a network restart with cleanup.

@@ -327,7 +327,10 @@ protected void executeProcedureScripts() {
Connection conn = txn.getConnection();

for (String filePath : filesPathUnderViewsDirectory) {
LOGGER.debug("Executing PROCEDURE script [{}].", filePath);
LOGGER.debug(String.format("Executing PROCEDURE script [%s].", filePath));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
LOGGER.debug(String.format("Executing PROCEDURE script [%s].", filePath));
LOGGER.debug("Executing PROCEDURE script [{}].", filePath);

@@ -439,7 +442,10 @@ protected void executeViewScripts() {
Connection conn = txn.getConnection();

for (String filePath : filesPathUnderViewsDirectory) {
LOGGER.debug("Executing VIEW script [{}].", filePath);
LOGGER.debug(String.format("Executing VIEW script [%s].", filePath));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
LOGGER.debug(String.format("Executing VIEW script [%s].", filePath));
LOGGER.debug("Executing VIEW script [{}].", filePath);

Comment on lines +708 to +709
continue
if self.config.is_vpc() and not ("purpose" in self.dbag[item] and self.dbag[item]["purpose"] == "Firewall"):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
continue
if self.config.is_vpc() and not ("purpose" in self.dbag[item] and self.dbag[item]["purpose"] == "Firewall"):
continue
if self.config.is_vpc() and not ("purpose" in self.dbag[item] and self.dbag[item]["purpose"] == "Firewall"):

@@ -632,6 +632,18 @@ def fw_vpcrouter(self):
(self.address['network'], self.address['network'])])

if self.get_type() in ["public"]:
# Add PREROUTING firewall chain jump for public IP
self.fw.append(["mangle", "front",
Copy link
Member

Choose a reason for hiding this comment

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

We seem to be adding this for all the VPC Offerings which might not have firewall as a supported service.

@@ -1186,6 +1188,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
internalLbOffProviders.put(Service.Gateway, Provider.VPCVirtualRouter);
internalLbOffProviders.put(Service.Lb, Provider.InternalLbVm);
internalLbOffProviders.put(Service.SourceNat, Provider.VPCVirtualRouter);
internalLbOffProviders.put(Service.Firewall, Provider.VPCVirtualRouter);
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure about this. But if the LB is internal, the firewall will work only on public traffic for VPC Virtual router. Is this change required here?

}
defaultKubernetesServiceNetworkOfferingProviders.put(Service.Firewall, Network.Provider.VPCVirtualRouter);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
defaultKubernetesServiceNetworkOfferingProviders.put(Service.Firewall, Network.Provider.VPCVirtualRouter);
defaultKubernetesServiceNetworkOfferingProviders.put(Service.Firewall, forNsx ? Network.Provider.Nsx : provider);

continue
if self.config.is_vpc():
continue
if self.config.is_vpc() and not ("purpose" in self.dbag[item] and self.dbag[item]["purpose"] == "Firewall"):
Copy link
Member

Choose a reason for hiding this comment

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

I am not exactly sure about this change.

services.push({
name: 'Firewall',
provider: [
{ name: 'VpcVirtualRouter' }
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if we can add providers (NSX, etc.) other than VpcVirtualRouter here.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants