fix(firewall): split UFW all-protocol port ranges (#13806)

This commit is contained in:
ssongliu
2026-09-14 15:46:14 +08:00
committed by GitHub
parent 56870504ac
commit ed51a5e1fa
2 changed files with 24 additions and 0 deletions

View File

@@ -1003,6 +1003,15 @@ func (s *FirewallService) createRules(ctx context.Context, request dto.FirewallR
"target": selected, "rule": describe(item.Rule), "count": len(rules),
}))
}
} else if selected == filter.ProviderUFW && strings.TrimSpace(item.Rule.DestinationPort) != "" {
protocol := strings.ToLower(strings.TrimSpace(item.Rule.Protocol))
if protocol == "" || protocol == "all" || protocol == "any" {
rules, err = filter.ExpandAtomicRules(applySelectedProviderScopeDefaults(item.Rule, selected))
if err != nil {
record(origin, "failed", err)
continue
}
}
}
for part, rule := range rules {
origin := itemOrigin{index: index, part: part, count: len(rules), rule: rule}

View File

@@ -117,6 +117,21 @@ func ExpandAtomicRules(input FirewallRule) ([]FirewallRule, error) {
families = []Family{FamilyIPv4, FamilyIPv6}
}
protocols := splitProtocols(input.Protocol)
if input.Scope.Provider == ProviderUFW {
protocol, err := normalizeProtocol(input.Protocol)
if err != nil {
return nil, err
}
if protocol == "all" {
destinationPort, err := normalizePortValue(input.DestinationPort, true)
if err != nil {
return nil, fmt.Errorf("%w: destination port: %v", ErrInvalidRule, err)
}
if strings.ContainsAny(destinationPort, ",-") {
protocols = []string{"tcp", "udp"}
}
}
}
sourceAddresses := splitValues(input.SourceAddress)
destinationAddresses := splitValues(input.DestinationAddress)
sourcePorts := splitValues(input.SourcePort)