-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Limit FQDNS match name and pattern expressions to 255 characters #35577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @joestringer who opened the original issue
I'm a bit worried that the limit on match patterns constitutes a breaking change in the current form - if we don't offer some safe upgrade path, it's conceivable that this starts rejecting policies that were previously accepted. Or is there a reason why match patterns would be limited to 63 chars in practice anyway?
91d693f
to
bd10bf5
Compare
@bimmlerd thanks for the comments! Do you think a higher default (say |
I'm uncertain. It seems possible to construct contrived examples of matchPatterns which are longer but still valid - and we can't break those without making this a breaking change which would need a bit more consideration.
Or we could make the matchPattern validation flag default to 0, which would allow any length and warn on very long patterns, i.e. issue a deprecation. Then flip the flag to opt-out or remove the flag outright in a future release. I'd prefer this, because then the users which don't know about this feature/don't read the upgrade guide carefully don't end up with potentially broken policies, which would be bad. |
bd10bf5
to
0ec3bf1
Compare
This makes sense, I have defaulted to |
Yeah upgrade is the tricky aspect. So generally speaking it should be fine to set a maxLength of 255 for matchPatterns in the CRDs as well, for the same reason that matchNames can only be 255: RFC 1035 Section 2.3.4 states this as the maximum number of octets for a name. It doesn't make sense that a matchPattern would be longer if the actual FQDN is shorter than the matchpattern. Then yeah having a configurable limit seems fine. Then again, we should really be able to convince ourselves there's a future where that setting will be configured at a lower value and will support the majority of users. Otherwise we're just adding yet one more flag that will be rarely used. The other angle on upgrade is this suggestion from the original issue, we could potentially do something like this (doesn't need to be done in this PR):
I don't recall where I came up with the idea of limiting matchPatterns to 63 characters. If my original motivation there is that Cilium might take a long time to process such rules, then maybe instead of putting a low limit like 63, Cilium should just export some metric or something that would allow users to identify when the worst case policy calculation takes a long time due to FQDN rules. Or warn on "bad" patterns - long patterns like @bimmlerd suggested, or maybe if there's a matchPattern with excessive wildcards (we could pick a threshold, say 5 or more |
Didn't want to do this as this won't allow users with specific needs to configure it higher.
To ensure this we could have warnings that inform users to use shorter DNS matchPatterns if length is > 255 to improve performance. Having this knob definitely allows cluster admins to expose cilium functionality while also ensuring bad configurations don't affect overall performance. Not sure about how to do warnings though, let me have a look. @bimmlerd @joestringer do let me know if anything else makes more sense here. I have already disabled the matchPatterns check by default (value |
Could you expand more on the use case? If DNS names can't be longer than that, and matchPatterns inherently have a wildcard pattern which expands to one or more characters, then I don't understand how it's possible to use a higher value. Am I missing something?
Bear with me, as I'm developing my thinking on this topic as we discuss it. Here's where I'm currently thinking as a direction: We should provide the tooling for interested admins to measure the impact and take action. So metrics totally make sense for this. The more I think about it, the less I'm convinced that cluster admins are going to be able to come up with some reasonable configuration for this flag that realistically limits the performance impact. If there is a specific pattern that causes high performance impact it would be nice to know, but then the solution is to check the policy and change it. Probably a pattern as simple as The other thing I'm thinking is.. if we are going to impose a limit, then it is nice to have a (hidden) configuration for this option so that in the worst case it is easy to tweak if the new limit causes problems. But if the default is 0 then I'm not sure whether any user will actually configure the option. We have hundreds of flags in Cilium, so if users aren't specifically asking for a new flag for this configuration then maybe we don't need to be exporting an option to them. |
Some context here: K8s limits individual label strings to 63 characters. If we ever take a DNS name and try to put it into a k8s API field with that limit, it could cause problems. I don't know exactly whether we ever do that or how that limit might come up, so I couldn't argue to set that limit at this point. Just highlighting this context that I remembered after that post. |
@rudrakhp ping? |
@youngnick will get back to this, have been busy elsewhere. From what I gather as per the comments:
@joestringer patterns convoluted enough can lead to the patterns themselves exceeding the 255 limit, although practically that shouldn't be the case. If everyone is of the same opinion I can have a hard limit of 255 for regex as well.
Ok this makes sense, length of the regular expression will seldom affect the performance, it's more about how complex the final expression is. |
Yeah, I think that would be fine. 👍 |
0ce744b
to
e97c97c
Compare
/test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rudrakhp Thank you for this update!
e97c97c
to
7888d5c
Compare
Many tests were failing, looks like due to ImagePullBackOff issue with cilium-envoy, which I believe was a transient failure on |
/test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
7888d5c
to
36b21a4
Compare
/test |
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
Head branch was pushed to by a user without write access
36b21a4
to
1418327
Compare
/test |
DNS names are limited to 255 chars: https://datatracker.ietf.org/doc/html/rfc1035#section-2.3.4
DNS match pattern rules that are excessively long could cause Cilium agent to take a long time to process the rules. This change adds a strict limit of 255 to matchName and configurable limit to matchPattern with default 63.
Ref #21491
Please ensure your pull request adheres to the following guidelines:
description and a
Fixes: #XXX
line if the commit addresses a particularGitHub issue.
Fixes: <commit-id>
tag, thenplease add the commit author[s] as reviewer[s] to this issue.
Fixes: #21491