@@ -20,6 +20,7 @@ import (
2020
2121const (
2222 maxFirewallRuleLabelLen = 32
23+ maxFirewallRuleDescLen = 100
2324 maxIPsPerFirewall = 255
2425 maxRulesPerFirewall = 25
2526)
@@ -183,6 +184,16 @@ func chunkIPs(ips []string) [][]string {
183184 return chunks
184185}
185186
187+ // truncateFWRuleDesc truncates the description to maxFirewallRuleDescLen if it exceeds the limit.
188+ func truncateFWRuleDesc (desc string ) string {
189+ if len (desc ) > maxFirewallRuleDescLen {
190+ newDesc := desc [0 :maxFirewallRuleDescLen - 3 ] + "..."
191+ klog .Infof ("Firewall rule description '%s' is too long. Stripping it to '%s'" , desc , newDesc )
192+ desc = newDesc
193+ }
194+ return desc
195+ }
196+
186197// processACL takes the IPs, aclType, label etc and formats them into the passed linodego.FirewallCreateOptions pointer.
187198func processACL (fwcreateOpts * linodego.FirewallCreateOptions , aclType , label , svcName , ports string , ips linodego.NetworkAddresses ) error {
188199 ruleLabel := fmt .Sprintf ("%s-%s" , aclType , svcName )
@@ -205,10 +216,11 @@ func processACL(fwcreateOpts *linodego.FirewallCreateOptions, aclType, label, sv
205216 ipv4chunks := chunkIPs (ipv4s )
206217 for i , chunk := range ipv4chunks {
207218 v4chunk := chunk
219+ desc := fmt .Sprintf ("Rule %d, Created by linode-ccm: %s, for %s" , i , label , svcName )
208220 fwcreateOpts .Rules .Inbound = append (fwcreateOpts .Rules .Inbound , linodego.FirewallRule {
209221 Action : aclType ,
210222 Label : ruleLabel ,
211- Description : fmt . Sprintf ( "Rule %d, Created by linode-ccm: %s, for %s" , i , label , svcName ),
223+ Description : truncateFWRuleDesc ( desc ),
212224 Protocol : linodego .TCP , // Nodebalancers support only TCP.
213225 Ports : ports ,
214226 Addresses : linodego.NetworkAddresses {IPv4 : & v4chunk },
@@ -218,20 +230,22 @@ func processACL(fwcreateOpts *linodego.FirewallCreateOptions, aclType, label, sv
218230 ipv6chunks := chunkIPs (ipv6s )
219231 for i , chunk := range ipv6chunks {
220232 v6chunk := chunk
233+ desc := fmt .Sprintf ("Rule %d, Created by linode-ccm: %s, for %s" , i , label , svcName )
221234 fwcreateOpts .Rules .Inbound = append (fwcreateOpts .Rules .Inbound , linodego.FirewallRule {
222235 Action : aclType ,
223236 Label : ruleLabel ,
224- Description : fmt . Sprintf ( "Rule %d, Created by linode-ccm: %s, for %s" , i , label , svcName ),
237+ Description : truncateFWRuleDesc ( desc ),
225238 Protocol : linodego .TCP , // Nodebalancers support only TCP.
226239 Ports : ports ,
227240 Addresses : linodego.NetworkAddresses {IPv6 : & v6chunk },
228241 })
229242 }
230243 } else {
244+ desc := fmt .Sprintf ("Created by linode-ccm: %s, for %s" , label , svcName )
231245 fwcreateOpts .Rules .Inbound = append (fwcreateOpts .Rules .Inbound , linodego.FirewallRule {
232246 Action : aclType ,
233247 Label : ruleLabel ,
234- Description : fmt . Sprintf ( "Created by linode-ccm: %s, for %s" , label , svcName ),
248+ Description : truncateFWRuleDesc ( desc ),
235249 Protocol : linodego .TCP , // Nodebalancers support only TCP.
236250 Ports : ports ,
237251 Addresses : ips ,
@@ -453,7 +467,7 @@ func (l *LinodeClient) updateNodeBalancerFirewallWithACL(
453467 return nil
454468 }
455469
456- fwCreateOpts , err := CreateFirewallOptsForSvc (service . Name , []string {"" }, service )
470+ fwCreateOpts , err := CreateFirewallOptsForSvc (firewalls [ 0 ]. Label , []string {"" }, service )
457471 if err != nil {
458472 return err
459473 }
0 commit comments