Skip to content
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

clustermesh: fix pattern to match IPv4 address #2144

Conversation

mhofstetter
Copy link
Member

@mhofstetter mhofstetter commented Dec 4, 2023

Executing cilium clustermesh vm install install-external-workload.sh fails if the randomly generated IP (v4) contains a zero (0) in its first byte.

Error: Malformed CLUSTER_ADDR: 104.198.85.126:2379

Therefore, this commit changes the pattern that is used to detect an IPv4 address (with port).

Until now i don't understand why it's working with the prefix [^[] for all other cases but not if the first byte is containing a zero 🤷‍♂️ I just think that this part isn't necessary - and shouldn't break anything 🙏

Detected on a cilium/cilium CI run: https://github.com/cilium/cilium/actions/runs/7067930793/job/19241908576

Executing `cilium clustermesh vm install install-external-workload.sh`
fails if the randomly generated IP (v4) contains a zero (`0`) in its
first byte.

Error: `Malformed CLUSTER_ADDR: 104.198.85.126:2379`

Therefore, this commit changes the pattern that is used to detect
an IPv4 address (with port).

Signed-off-by: Marco Hofstetter <[email protected]>
@marseel
Copy link
Contributor

marseel commented Dec 4, 2023

I wanted to understand that before approving as it was not obvious to me as well. I simplified the case to:

shopt -s extglob

pattern='[^[]@(25[0-5]|2[0-4][0-9]|[1][0-9][0-9]|[1-9][0-9]|[0-9])'
pattern2='@(25[0-5]|2[0-4][0-9]|[1][0-9][0-9]|[1-9][0-9]|[0-9])'
data='255'
data2='205'

if [[ $data == $pattern ]]; then echo yes; else echo no; fi
if [[ $data == $pattern2 ]]; then echo yes; else echo no; fi
if [[ $data2 == $pattern ]]; then echo yes; else echo no; fi
if [[ $data2 == $pattern2 ]]; then echo yes; else echo no; fi

output:

yes
yes
no
yes

So what happens is that [^[] means match any character except for ']': explanation
so the rest of pattern thinks that IP starts with 0.

Looks like we also accept the 12345.123.123.123 IP in both cases 🤷

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Dec 4, 2023
@mhofstetter
Copy link
Member Author

mhofstetter commented Dec 4, 2023

Thanks @marseel

I think you meant any character except for [ ?

Now that this is clear, the reason for this might have been to prevent matching any ipv6 address (without [..]) with this match 🤔 (which i don't think is necessary because these should be separated with colon anyway)

@marseel
Copy link
Contributor

marseel commented Dec 4, 2023

I think you meant any character except for [ ?

yea, sorry for that.

(which i don't think is necessary because these should be separated with colon anyway)

I don't think it's necessary either.

Copy link
Contributor

@michi-covalent michi-covalent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a very innocent regex

@michi-covalent michi-covalent merged commit 47510d4 into cilium:main Dec 4, 2023
20 checks passed
@mhofstetter mhofstetter deleted the pr/mhofstetter/clustermesh_ipv4_validation branch December 4, 2023 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clustermesh kind/bug Something isn't working ready-to-merge This PR has passed all tests and received consensus from code owners to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants