Skip to content

Support Firewall for public IPs in VPC#12706

Draft
harikrishna-patnala wants to merge 13 commits into
apache:mainfrom
shapeblue:FWinVPCpublicIP
Draft

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

Conversation

@harikrishna-patnala
Copy link
Copy Markdown
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
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@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
Copy Markdown

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

Copy link
Copy Markdown
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.

Comment thread engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42210to42300.java Outdated
Comment on lines 990 to +992
public boolean isVirtualRouterGateway(Network network) {
return isRoutedNetwork(network)
&& (networkServiceMapDao.canProviderSupportServiceInNetwork(network.getId(), Service.Gateway, Provider.VirtualRouter))
|| networkServiceMapDao.canProviderSupportServiceInNetwork(network.getId(), Service.Gateway, Provider.VPCVirtualRouter);
&& (networkServiceMapDao.canProviderSupportServiceInNetwork(network.getId(), Service.Gateway, Provider.VirtualRouter));
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

The removal of the VPCVirtualRouter check from the isVirtualRouterGateway(Network network) method creates an inconsistency with the overloaded isVirtualRouterGateway(NetworkOffering networkOffering) method at lines 996-999, which still checks for VPCVirtualRouter. This inconsistency could lead to different behavior depending on which method is called. Additionally, there's a potential operator precedence issue in lines 997-999 where the && operator may not bind as intended with the || operator without proper parentheses.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

check this once

Comment thread engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42210to42300.java Outdated
Comment thread engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42210to42300.java Outdated
Comment thread engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42210to42300.java Outdated
@blueorangutan
Copy link
Copy Markdown

[SF] Trillian Build Failed (tid-15532)

@harikrishna-patnala
Copy link
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@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
Copy Markdown

codecov Bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 11.07266% with 257 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.09%. Comparing base (1e512ab) to head (c3b397d).
⚠️ Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
...om/cloud/network/firewall/FirewallManagerImpl.java 11.49% 143 Missing and 11 partials ⚠️
...n/java/com/cloud/network/IpAddressManagerImpl.java 0.00% 36 Missing ⚠️
.../main/java/com/cloud/network/NetworkModelImpl.java 0.00% 25 Missing ⚠️
...i/command/user/firewall/CreateFirewallRuleCmd.java 44.44% 7 Missing and 3 partials ⚠️
...n/java/com/cloud/network/rules/FirewallRuleVO.java 14.28% 6 Missing ⚠️
...pi/command/user/nat/CreateIpForwardingRuleCmd.java 0.00% 5 Missing ⚠️
...ava/com/cloud/network/rules/StaticNatRuleImpl.java 0.00% 4 Missing ⚠️
...src/main/java/com/cloud/api/ApiResponseHelper.java 0.00% 4 Missing ⚠️
.../cloud/configuration/ConfigurationManagerImpl.java 0.00% 3 Missing ⚠️
...cloud/network/element/VpcVirtualRouterElement.java 40.00% 1 Missing and 2 partials ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##               main   #12706    +/-   ##
==========================================
  Coverage     18.08%   18.09%            
- Complexity    16706    16736    +30     
==========================================
  Files          6037     6037            
  Lines        542437   542827   +390     
  Branches      66420    66486    +66     
==========================================
+ Hits          98088    98206   +118     
- Misses       433333   433557   +224     
- Partials      11016    11064    +48     
Flag Coverage Δ
uitests 3.51% <ø> (-0.01%) ⬇️
unittests 19.25% <11.07%> (+0.01%) ⬆️

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
Copy Markdown
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.

Comment thread engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42210to42300.java Outdated
Comment thread engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42210to42300.java Outdated
Comment thread engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42210to42300.java Outdated
Comment thread server/src/main/java/com/cloud/server/ConfigurationServerImpl.java
@harikrishna-patnala
Copy link
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@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
Copy Markdown

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

@harikrishna-patnala
Copy link
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@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
Copy Markdown

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

@harikrishna-patnala
Copy link
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@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
Copy Markdown

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

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42210to42300.java Outdated
Comment thread engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java Outdated
Comment thread engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java Outdated
Comment thread systemvm/debian/opt/cloud/bin/configure.py Outdated
Comment thread systemvm/debian/opt/cloud/bin/cs/CsAddress.py Outdated
Comment thread server/src/main/java/com/cloud/server/ConfigurationServerImpl.java Outdated
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
Copy Markdown
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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

firewall case is skipped here and handled in next else case

Comment thread ui/src/views/offering/AddVpcOffering.vue
@github-actions
Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@blueorangutan
Copy link
Copy Markdown

[SF] Trillian Build Failed (tid-16045)

Network network = ApiDBUtils.findNetworkById(fwRule.getNetworkId());
response.setNetworkId(network.getUuid());
Long networkId = fwRule.getNetworkId();
if (networkId != null) {
Copy link
Copy Markdown
Member

@vishesh92 vishesh92 May 12, 2026

Choose a reason for hiding this comment

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

Do we also need to add VPC id here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

makes sense, I will add it

Copy link
Copy Markdown
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 23 out of 25 changed files in this pull request and generated 3 comments.

Account caller = CallContext.current().getCallingAccount();
Long sourceIpAddressId = rule.getSourceIpAddressId();
IPAddressVO sourceIp = getSourceIpForIngressRule(sourceIpAddressId);

Comment on lines +368 to +376
final Long accountIdFinal = accountId;
final Long domainIdFinal = domainId;
final Long resolvedNetworkIdFinal = null;
final Long resolvedVpcIdFinal = resolvedVpcId;
return Transaction.execute((TransactionCallbackWithException<FirewallRuleVO, NetworkRuleConflictException>) status -> {
FirewallRuleVO newRule = new FirewallRuleVO(xId, ipAddrId, portStart, portEnd, protocol.toLowerCase(), resolvedNetworkIdFinal, accountIdFinal, domainIdFinal, Purpose.Firewall,
sourceCidrList, destCidrList, icmpCode, icmpType, relatedRuleId, trafficType);
newRule.setVpcId(resolvedVpcIdFinal);
newRule.setType(type);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this seems to be valid.

Comment on lines +7230 to +7231
} else if (service == Service.Firewall) {
forVpc = true;
Copy link
Copy Markdown
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.

clgtm. just a few things which needs to be checked.

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