-
Notifications
You must be signed in to change notification settings - Fork 58
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
builder: fix image label sanity checks #249
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.
The new regex allows empty label values which is invalid.
@chrisstaite that is surprising, according to the GCP docs, it does state that |
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.
You also assume lowercase ASCII (i.e. a-z) whereas the requirements from Google state lowercase letters implying lowercase non-latin characters are also allowed, specifically in UTF-8 encoding.
Absolutely, I misread that. However: "All characters must use UTF-8 encoding, and international characters are allowed. " |
You do make a point regarding lowercase letters though, I wonder what is the exact character set they allow there, I assume we can use a Unicode-friendly lowercase collation algorithm for those, but a regexp supporting those is likely tricky. I'll amend the PR to do that. |
You should be able to use the regex |
I might add that even the length check is somewhat broken in this case, as the length of the string according to their documentation is up-to 63 characters, not 63 bytes, so the length checks are likely broken too here. |
You are right though, it seems that |
078e699
to
d4e0780
Compare
@chrisstaite thanks for the pointer to |
I encountered #248 today, also. It appears that this validation happens after the image build process. If this validation is going to be performed by Packer, it would be much more useful for it to happen before the image build starts. If the build process has already completed, at that point you might as well just ask GCP to create the image. If there is an error, GCP's API will say so and that can be reported to the user. |
@jkoelndorfer this PR performs this check during the If you test this change on your build and an invalid key/value, you will see that the error is immediate now. |
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.
Thanks a lot @lbajolet-hashicorp for quickly fixing the bug I introduced 🙏
When the image sanity checks were introduced in v1.1.7, an error slipped in as the same regex was used to validate keys and labels, however the rules are slightly different between the two, as keys are mandated to start with [a-z], while values are not. This commit addresses this bug by changing to using two regexes, so we can still validate that both are valid before attempting to build the image, but we are not unnecessarily rejecting valid values in the map.
d4e0780
to
331117f
Compare
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 !
When the image sanity checks were introduced in v1.1.7, an error slipped in as the same regex was used to validate keys and labels, however the rules are slightly different between the two, as keys are mandated to start with [a-z], while values are not.
This commit addresses this bug by changing to using two regexes, so we can still validate that both are valid before attempting to build the image, but we are not unnecessarily rejecting valid values in the map.
Closes #248