Skip to content

Commit

Permalink
Trim ACL names according to RFC1123
Browse files Browse the repository at this point in the history
We didn't consider this tiny hack that we do
https://github.com/openshift/ovn-kubernetes/blob/44ad75466e486cce605e39513a3ecd9e0b306e7d/go-controller/pkg/libovsdbops/acl.go#L60
there when we wrote openshift/ovn-kubernetes#1259
and unit tests don't actually scream loudly for longer names.

Without this PR we break users who have namespace names
longer than 45 characters.

Signed-off-by: Surya Seetharaman <suryaseetharaman.9@gmail.com>
Co-authored-by: Patrk Diak <pdiak@redhat.com>
  • Loading branch information
tssurya and kyrtapz committed Sep 26, 2022
1 parent 1c44211 commit f341a90
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion go-controller/pkg/ovn/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func hashedPortGroup(s string) string {
return util.HashForOVN(s)
}

func trimNameRFC1123(name string) string {
return fmt.Sprintf("%.63s", name)
}

// updateStaleDefaultDenyACLNames updates the naming of the default ingress and egress deny ACLs per namespace
// oldName: <namespace>_<policyname> (lucky winner will be first policy created in the namespace)
// newName: <namespace>_egressDefaultDeny OR <namespace>_ingressDefaultDeny
Expand All @@ -125,7 +129,7 @@ func (oc *Controller) updateStaleDefaultDenyACLNames(npType knet.PolicyType, gre
}
// loop through the cleanUp map and per namespace update the first ACL's name and delete the rest
for namespace, aclList := range cleanUpDefaultDeny {
newName := namespacePortGroupACLName(namespace, "", gressSuffix)
newName := trimNameRFC1123(namespacePortGroupACLName(namespace, "", gressSuffix))
if len(aclList) > 1 {
// this should never be the case but delete everything except 1st ACL
ingressPGName := defaultDenyPortGroup(namespace, ingressDefaultDenySuffix)
Expand Down
4 changes: 2 additions & 2 deletions go-controller/pkg/ovn/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ var _ = ginkgo.Describe("OVN NetworkPolicy Operations", func() {

// ACL3: leftover default deny ACL egress with old name (namespace_policyname)
leftOverACL3FromUpgrade := libovsdbops.BuildACL(
"leftover1"+"_"+networkPolicy2.Name,
"youknownothingjonsnowyouknownothingjonsnowyouknownothingjonsnow"+"_"+networkPolicy2.Name,
nbdb.ACLDirectionFromLport,
types.DefaultDenyPriority,
"inport == @"+pgHash+"_"+egressDenyPG,
Expand Down Expand Up @@ -1929,7 +1929,7 @@ var _ = ginkgo.Describe("OVN NetworkPolicy Operations", func() {
"apply-after-lb": "true",
}
leftOverACL3FromUpgrade.Options = egressOptions
newDefaultDenyEgressACLName := "leftover1_" + egressDefaultDenySuffix
newDefaultDenyEgressACLName := "youknownothingjonsnowyouknownothingjonsnowyouknownothingjonsnow" // trims it according to RFC1123
newDefaultDenyIngressACLName := "leftover1_" + ingressDefaultDenySuffix
leftOverACL3FromUpgrade.Name = &newDefaultDenyEgressACLName
leftOverACL4FromUpgrade.Name = &newDefaultDenyIngressACLName
Expand Down

0 comments on commit f341a90

Please sign in to comment.