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

Validate TXT prefix #1507

Closed
wants to merge 1 commit into from
Closed

Conversation

ruudk
Copy link

@ruudk ruudk commented Apr 10, 2020

To prevent mistakes I think it's good to validate the txt prefix on startup.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 10, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ruudk
To complete the pull request process, please assign njuettner
You can assign the PR to them by writing /assign @njuettner in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ruudk
Copy link
Author

ruudk commented Apr 10, 2020

/assign @njuettner

@jgrumboe
Copy link
Contributor

If you want I can incorporate your validations into #1483.

@ruudk
Copy link
Author

ruudk commented Apr 13, 2020

@jgrumboe Thanks I think better for the maintainers to review this separately

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 12, 2020
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 14, 2020
@ruudk
Copy link
Author

ruudk commented Jul 14, 2020

Rebased the PR because #1483 was merged.

@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Aug 13, 2020
@seanmalloy
Copy link
Member

/remove-lifecycle rotten
/kind bug

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. and removed lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. labels Aug 13, 2020
@seanmalloy
Copy link
Member

/assign

@seanmalloy
Copy link
Member

/lgtm

@tariq1890 and @vinny-sabatini please take a look when you have some time. After you review I'd like to assign this to the external-dns approvers, and see if we can get this merged. Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 25, 2020
@seanmalloy
Copy link
Member

/cc @tariq1890

Copy link
Contributor

@vinny-sabatini vinny-sabatini left a comment

Choose a reason for hiding this comment

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

I believe the rest of this code change (except the one comment about the error creation) looks good to me.

One thing I am unsure of is if it matters if the txt record starts or ends with . or - characters.

registry/txt.go Outdated Show resolved Hide resolved
registry/txt.go Outdated Show resolved Hide resolved
Signed-off-by: Ruud Kamphuis <ruudk@users.noreply.github.com>
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 2, 2020
@ruudk
Copy link
Author

ruudk commented Sep 2, 2020

Applied the requested changes.

Copy link
Contributor

@Raffo Raffo left a comment

Choose a reason for hiding this comment

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

I added a couple of comments, I am not sure that the check that we are doing is accurate or enough. In case it is not accurate or complete I would rather not having a check.

require.Error(t, err, `invalid TXT prefix provided, expected "[a-z0-9-.]+" got "@invalid#"`)
_, err = NewTXTRegistry(p, "", "@invalid#", "owner", time.Hour)
require.Error(t, err, `invalid TXT suffix provided, expected "[a-z0-9-.]+" got "@invalid#"`)

Copy link
Contributor

Choose a reason for hiding this comment

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

If I add

	_, err = NewTXTRegistry(p, "valid....", "", "owner", time.Hour)
	require.Error(t, err)

That also looks invalid to me, but the test fails. Are you sure the check that we are doing is fine?

Copy link
Author

Choose a reason for hiding this comment

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

Then we need to improve the regex that is used. Any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

^([a-z0-9]+(-[a-z0-9]+)*)$ maybe?

Copy link
Member

Choose a reason for hiding this comment

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

@ruudk any thoughts on the suggestion from @Raffo

@@ -60,6 +60,26 @@ func testTXTRegistryNew(t *testing.T) {
_, err = NewTXTRegistry(p, "txt", "txt", "owner", time.Hour)
require.Error(t, err)

_, err = NewTXTRegistry(p, "@invalid#", "", "owner", time.Hour)
require.Error(t, err, `invalid TXT prefix provided, expected "[a-z0-9-.]+" got "@invalid#"`)
Copy link
Contributor

Choose a reason for hiding this comment

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

This message and the one on like 66 are not accurate, I recommend changing it like:

Suggested change
require.Error(t, err, `invalid TXT prefix provided, expected "[a-z0-9-.]+" got "@invalid#"`)
require.Error(t, err)

Copy link
Author

Choose a reason for hiding this comment

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

Why are they not accurate? By comparing the error string I make sure that the guard that returns the error works. If I just accept any error, it would make it less good, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because what is happening when you have an error is not that the TXT prefix is invalid, rather than it is expected to be invalid, but there is no error. The string you are providing is only changing the messaging to report, not changing any behavior at all. The default message instead, is correct.

Copy link
Member

Choose a reason for hiding this comment

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

@ruudk any thoughts on the suggestion from @Raffo

@Raffo
Copy link
Contributor

Raffo commented Oct 9, 2020

Given that this had no follow up, I'm going to close this, to keep a bit of clarity in the PRs that we have to review. Please reopen if you feel you can follow up on this @ruudk .

@Raffo Raffo closed this Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants