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

fix(HMS-3152): LocationName regex to allow uppercase #21

Closed
wants to merge 1 commit into from

Conversation

pvoborni
Copy link
Contributor

As DNS labels are case insensitive and RFC 1035 allows upper case.

Before this change the regex was more restricitive than what was possible to define in IPA location.

@frasertweedale
Copy link
Contributor

From RFC 1123 section 2:

2.1  Host Names and Numbers

      The syntax of a legal Internet host name was specified in [RFC-952](https://datatracker.ietf.org/doc/html/rfc952)
      [DNS:4].  One aspect of host name syntax is hereby changed: the
      restriction on the first character is relaxed to allow either a
      letter or a digit.  Host software MUST support this more liberal
      syntax.

So, the regex should support digit in intial position of label.

@@ -979,7 +979,7 @@ components:
type: string
maxLength: 63
minLength: 1
pattern: ^[a-z][a-z0-9\-]*$
pattern: ^[a-zA-Z][a-zA-Z0-9\-]*$
Copy link
Contributor

@frasertweedale frasertweedale Sep 17, 2024

Choose a reason for hiding this comment

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

Per RFC 1123, first character can be a digit. Also, the last character must be a letter or digit, not -.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just for reference, similar utility method in IPA: https://github.com/freeipa/freeipa/blob/master/ipalib/util.py#L389

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the RFC 1123 and RFC 952; If I understand correctly, the corrections indicated by RFC 1123 would match the below:

<hname> ::= <name>*["."<name>]
<name>  ::= <let-or-digit>[*[<let-or-digit-or-hyphen>]<let-or-digit>]

Based on the above, the current change "^[a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])*$" would fit the above; but I have a question:

  • I think is correct the change, but should _ be considered? For me it is not the same underscore _ and hyphen -; please correct me if I were understanding wrongly the RFC; just in case _ should be considered.

I have tried some edge cases at: https://regex101.com/

  • a
  • 9
  • 9a
  • 9- fail => it is ok
  • a- fail => it is ok
  • 3-4
  • -2 fail => it is ok
  • 3A8
  • A

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was also thinking that we could allow any string and not have a regex here. We get the information from IPA server - IPA locations. So from that PoV we should support what it supports.

I just tried to define some random locations and it allows various other chars. It looks that the IPA location name is not much restricted even though it is defined as DNSNameParam.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks that the IPA location name is not much restricted even though it is defined as DNSNameParam.

hmmm... so there exists a real possibility that a customer could have non-conformant location data, which would cause registration failure.

I am OK with completely relaxing the location validation in our service. Bad data might (or might not, depending how their DNS is configured) be an operational issue for the IPA server. But I think we should not make the bad data prevent registration with idmsvc.

However, let's bring the issue up with the IPA team before committing. They might agree it's a bug and decide to properly restrict the field. Or we might be missing the reason why invalid DNS labels are allowed by IPA.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've opened #23 that is removing the pattern - so that we can choose which PR to merge.

As DNS labels are case insensitive and RFC 1035 allows upper case. Last character must
be a digit or letter.

Also per RFC 1123 section 2, the first character can be a digit.

Before this change the regex was more restricitive than what was possible to define in IPA location.

Signed-off-by: Petr Vobornik <[email protected]>
pvoborni added a commit to pvoborni/idmsvc-api that referenced this pull request Sep 23, 2024
Location name should be a DNS label and could be matched by a regex.

Correct one could be "^[a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])*$".

PR podengo-project#21 has a
discussion about it. But users can defined more values in IPA
location in the FreeIPA server than what the RFCs allow.

From this PoV, it is more important for idmsvc to pass registration
even with slightly invalid DNS label than being valid but failing.
Idmsvc doesn't use the value for DNS operations.

Signed-off-by: Petr Vobornik <[email protected]>
@frasertweedale
Copy link
Contributor

I think #23 is the one we should land - closing this one.

pvoborni added a commit to pvoborni/idmsvc-api that referenced this pull request Sep 27, 2024
Location name should be a DNS label and could be matched by a regex.

Correct one could be "^[a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])*$".

PR podengo-project#21 has a
discussion about it. But users can defined more values in IPA
location in the FreeIPA server than what the RFCs allow.

From this PoV, it is more important for idmsvc to pass registration
even with slightly invalid DNS label than being valid but failing.
Idmsvc doesn't use the value for DNS operations.

Signed-off-by: Petr Vobornik <[email protected]>
pvoborni added a commit to pvoborni/idmsvc-api that referenced this pull request Sep 27, 2024
Location name should be a DNS label and could be matched by a regex.

Correct one could be "^[a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])*$".

PR podengo-project#21 has a
discussion about it. But users can defined more values in IPA
location in the FreeIPA server than what the RFCs allow.

From this PoV, it is more important for idmsvc to pass registration
even with slightly invalid DNS label than being valid but failing.
Idmsvc doesn't use the value for DNS operations.

Signed-off-by: Petr Vobornik <[email protected]>
frasertweedale pushed a commit that referenced this pull request Sep 28, 2024
Location name should be a DNS label and could be matched by a regex.

Correct one could be "^[a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])*$".

PR #21 has a
discussion about it. But users can defined more values in IPA
location in the FreeIPA server than what the RFCs allow.

From this PoV, it is more important for idmsvc to pass registration
even with slightly invalid DNS label than being valid but failing.
Idmsvc doesn't use the value for DNS operations.

Signed-off-by: Petr Vobornik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants