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

lib: add validation package + DNS label validation #12535

Merged
merged 12 commits into from
Mar 18, 2022
Merged

Conversation

eculver
Copy link
Contributor

@eculver eculver commented Mar 8, 2022

For future work with mesh federation, we want to validate peer names as valid RFC 1123 DNS labels. This validation already exists, but only in Enterprise and we need the functionality in both OSS and Enterprise. So, I pulled it out and put it into a standalone package under lib.

Note: the regex and tests are the same from the original code in Enterprise.

Ask for reviewers: Is this an ok place to put this? I'm also open to renaming things if it makes sense. I'll also link to the PRs in Enterprise that make use of this package and refactor the previous call sites to use this interface.

Notes to reviewers:

  • The calling code will show up in the future PRs that I alluded to above.
  • I decided to add both an IsValidDNSLabel and a RequireValidDNSLabel to a) preserve existing bool return + error messages and b) also allow validation rule to be returned to callers if need be -- this is how the mesh federation code does it.

@eculver eculver requested review from rboyer, freddygv, ndhanushkodi, kisunji and a team March 8, 2022 01:26
@github-actions github-actions bot added the theme/internals Serf, Raft, SWIM, Lifeguard, Anti-Entropy, locking topics label Mar 8, 2022
@vercel vercel bot temporarily deployed to Preview – consul March 8, 2022 01:31 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 8, 2022 01:31 Inactive
Copy link
Contributor

@kisunji kisunji left a comment

Choose a reason for hiding this comment

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

Assuming validation can grow to mean anything maybe let's rename the file lib/validation/dns.go?

@freddygv
Copy link
Contributor

freddygv commented Mar 9, 2022

I left a comment in the mirrored ent PR, I think it could be useful to merge this into the agent/dns package, since there's a InvalidNameRe there. Not sure why a separate pattern was added for tenancies.

@hashicorp-cla
Copy link

hashicorp-cla commented Mar 12, 2022

CLA assistant check
All committers have signed the CLA.

Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
@vercel vercel bot temporarily deployed to Preview – consul March 14, 2022 23:44 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 14, 2022 23:44 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 15, 2022 00:24 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 15, 2022 00:24 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 15, 2022 00:30 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 15, 2022 00:30 Inactive
@eculver eculver requested a review from kisunji March 15, 2022 00:42
@vercel vercel bot temporarily deployed to Preview – consul March 15, 2022 01:10 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 15, 2022 01:10 Inactive
Copy link
Contributor

@freddygv freddygv left a comment

Choose a reason for hiding this comment

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

Thanks for moving this! Have two small requests

.changelog/12535.txt Outdated Show resolved Hide resolved
"foo-": false,
"-foo-": false,
"-foo-bar-": false,
"no spaces allowed": false,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add cases for names that are at the boundary length-wise? 64 chars invalid, 63 chars valid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, sounds good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah, this is actually really interesting. I pulled the pattern from the existing code in Enterprise and looking at it more closely, it clearly allows 64 characters when it should only allow 63 according to the RFC.

So, we just fixed a very nuanced bug. Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed now, but I want to leave this comment exposed for posterity since it's so fun.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, this is why we test :P

@eculver eculver added the pr/no-changelog PR does not need a corresponding .changelog entry label Mar 17, 2022
@vercel vercel bot temporarily deployed to Preview – consul March 17, 2022 16:52 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 17, 2022 16:52 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 17, 2022 17:05 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 17, 2022 17:05 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 17, 2022 17:21 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 17, 2022 17:21 Inactive
Copy link
Contributor

@freddygv freddygv left a comment

Choose a reason for hiding this comment

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

LGTM assuming CI passes

@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 17, 2022 17:35 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 17, 2022 17:35 Inactive
@eculver eculver removed the pr/no-changelog PR does not need a corresponding .changelog entry label Mar 17, 2022
@eculver eculver merged commit e3e4810 into main Mar 18, 2022
@eculver eculver deleted the eculver/validation-pkg branch March 18, 2022 01:31
@hc-github-team-consul-core
Copy link
Contributor

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/608309.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/internals Serf, Raft, SWIM, Lifeguard, Anti-Entropy, locking topics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants