fix: normalize Docker firewall rule sync (#13704)

This commit is contained in:
ssongliu
2026-09-03 18:22:48 +08:00
committed by GitHub
parent e99c6c08a5
commit 2948b8ffe8
3 changed files with 22 additions and 3 deletions
+3 -1
View File
@@ -790,7 +790,9 @@ func (p databaseSyncPlan) preview() dto.FirewallRuleSyncPreview {
result.Total++
case firewallRuleSyncBlocked:
result.Blocked++
result.Total++
if item.ReasonCode != firewallsync.ReasonReadOnlyRule {
result.Total++
}
case firewallsync.StatusRemove:
result.Removed++
}
+16 -1
View File
@@ -91,7 +91,10 @@ func PolicySyncKey(policy Policy) string {
if mode == ModeAllow && len(policy.Sources) == 0 {
mode = ModeAll
}
sources := append([]string(nil), policy.Sources...)
sources := make([]string, 0, len(policy.Sources))
for _, source := range policy.Sources {
sources = append(sources, canonicalPolicySource(source))
}
sort.Strings(sources)
return strings.Join([]string{
policy.UUID, policy.Family, CanonicalHost(policy.HostIP), strconv.Itoa(int(policy.HostPort)),
@@ -99,6 +102,18 @@ func PolicySyncKey(policy Policy) string {
}, "\x00")
}
func canonicalPolicySource(value string) string {
value = strings.TrimSpace(value)
if prefix, err := netip.ParsePrefix(value); err == nil {
return prefix.Masked().String()
}
if address, err := netip.ParseAddr(value); err == nil {
address = address.Unmap()
return netip.PrefixFrom(address, address.BitLen()).String()
}
return value
}
func PolicyStatesEqual(left, right []Policy) bool {
if len(left) != len(right) {
return false
@@ -205,7 +205,9 @@ const syncDisabled = computed(() => {
const detailItems = computed(() => {
if (!preview.value || !detailFilter.value) return [];
const items = preview.value.items || [];
if (detailFilter.value === 'total') return items.filter((item) => item.status !== 'remove');
if (detailFilter.value === 'total') {
return items.filter((item) => item.status !== 'remove' && item.reasonCode !== 'read_only_rule');
}
return items.filter((item) => item.status === detailFilter.value);
});