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

cloudflare_dns: Fix setting SRV records with a root level entry #5972

Merged

Conversation

rlenferink
Copy link
Contributor

SUMMARY

This fixes a bug in the cloudflare_dns module where setting a root-level SRV record resulted in a 400 Bad Request. After some debugging apparently the following line removes the zone suffix from the record:

"name": params['record'][:-len('.' + params['zone'])],

Say, input data params['record'] = example.com and params['zone'] = example.com then name will be empty, which is not accepted by the Cloudflare API. Since the intention was to set a root-level entry, this PR ensures that in that specific case name will be equals to the zone.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

cloudflare_dns

ADDITIONAL INFORMATION

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module net_tools plugins plugin (any type) labels Feb 10, 2023
@rlenferink
Copy link
Contributor Author

I just noticed the following related issue: #5167

/cc @felixfontein

The suggested solution in that issue is incorrect because that breaks the ability to set SRV records for subdomains. This PR works for me in a idempotent way.

Copy link
Collaborator

@felixfontein felixfontein 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 the contribution. Could you please also update the description for the name option to mention the special case for SRV records?

plugins/modules/cloudflare_dns.py Outdated Show resolved Hide resolved
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-5 labels Feb 11, 2023
@ansibullbot ansibullbot added stale_ci CI is older than 7 days, rerun before merging and removed stale_ci CI is older than 7 days, rerun before merging labels Feb 19, 2023
@rlenferink
Copy link
Contributor Author

rlenferink commented Feb 22, 2023

Thanks for the contribution. Could you please also update the description for the name option to mention the special case for SRV records?

I started adding a note to the record field, but after a bit more of digging through the code I started wondering if that is even needed/wanted. I think this is just a technical detail in the module itself.

In the start of the module a check is done for @ and if that is the case, it will already replace the value with zone:

if self.record == '@':
self.record = self.zone

I am willing to add this (if wanted), but I am wondeirng if this 'technical detail' is interesting, since apparently @ is already substituted with zone internally (only incorrectly for SRV records)

@felixfontein
Copy link
Collaborator

If nobody objects, I'll merge this this weekend.

…ecord name

The cloudflare API accepts the record name + zone name to be sent. Removing that, will guarantee the module to be idempotent even though that line was added ~7 years ago for that specific reason: ansible/ansible-modules-extras@7477fe5

It seems the most logical explanition is that Cloudflare changed their API response somewhere over the last 7 years.
@github-actions

This comment was marked as outdated.

@felixfontein
Copy link
Collaborator

If nobody objects, I'll merge this by the end of this weekend.

@rlenferink
Copy link
Contributor Author

If nobody objects, I'll merge this by the end of this weekend.

Sounds good to me.

@felixfontein felixfontein merged commit 094dc6b into ansible-collections:main Feb 26, 2023
@patchback
Copy link

patchback bot commented Feb 26, 2023

Backport to stable-5: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-5/094dc6b69c6ca4f54a261581962cdbf2956c0233/pr-5972

Backported as #6096

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Feb 26, 2023
patchback bot pushed a commit that referenced this pull request Feb 26, 2023
* cloudflare_dns: Fix setting SRV records with a root level entry

* cloudflare_dns: Remove the part which deletes the zone from the SRV record name

The cloudflare API accepts the record name + zone name to be sent. Removing that, will guarantee the module to be idempotent even though that line was added ~7 years ago for that specific reason: ansible/ansible-modules-extras@7477fe5

It seems the most logical explanition is that Cloudflare changed their API response somewhere over the last 7 years.

* cloudflare_dns: Update the changelog fragment

(cherry picked from commit 094dc6b)
@patchback
Copy link

patchback bot commented Feb 26, 2023

Backport to stable-6: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-6/094dc6b69c6ca4f54a261581962cdbf2956c0233/pr-5972

Backported as #6097

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein
Copy link
Collaborator

@rlenferink thanks a lot for fixing this!

patchback bot pushed a commit that referenced this pull request Feb 26, 2023
* cloudflare_dns: Fix setting SRV records with a root level entry

* cloudflare_dns: Remove the part which deletes the zone from the SRV record name

The cloudflare API accepts the record name + zone name to be sent. Removing that, will guarantee the module to be idempotent even though that line was added ~7 years ago for that specific reason: ansible/ansible-modules-extras@7477fe5

It seems the most logical explanition is that Cloudflare changed their API response somewhere over the last 7 years.

* cloudflare_dns: Update the changelog fragment

(cherry picked from commit 094dc6b)
felixfontein pushed a commit that referenced this pull request Feb 26, 2023
…V records with a root level entry (#6096)

cloudflare_dns: Fix setting SRV records with a root level entry (#5972)

* cloudflare_dns: Fix setting SRV records with a root level entry

* cloudflare_dns: Remove the part which deletes the zone from the SRV record name

The cloudflare API accepts the record name + zone name to be sent. Removing that, will guarantee the module to be idempotent even though that line was added ~7 years ago for that specific reason: ansible/ansible-modules-extras@7477fe5

It seems the most logical explanition is that Cloudflare changed their API response somewhere over the last 7 years.

* cloudflare_dns: Update the changelog fragment

(cherry picked from commit 094dc6b)

Co-authored-by: Roy Lenferink <lenferinkroy@gmail.com>
felixfontein pushed a commit that referenced this pull request Feb 26, 2023
…V records with a root level entry (#6097)

cloudflare_dns: Fix setting SRV records with a root level entry (#5972)

* cloudflare_dns: Fix setting SRV records with a root level entry

* cloudflare_dns: Remove the part which deletes the zone from the SRV record name

The cloudflare API accepts the record name + zone name to be sent. Removing that, will guarantee the module to be idempotent even though that line was added ~7 years ago for that specific reason: ansible/ansible-modules-extras@7477fe5

It seems the most logical explanition is that Cloudflare changed their API response somewhere over the last 7 years.

* cloudflare_dns: Update the changelog fragment

(cherry picked from commit 094dc6b)

Co-authored-by: Roy Lenferink <lenferinkroy@gmail.com>
@rlenferink rlenferink deleted the fix-cloudflare-srv-record branch February 26, 2023 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug module module net_tools plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants