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

nsupdate: fix 'index out of range' error when changing NS records #8614

Merged
merged 3 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8614-nsupdate-index-out-of-range.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "nsupdate - fix 'index out of range' error when changing NS records by falling back to authority section of the response"
artw marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion plugins/modules/nsupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ def modify_record(self):
except (socket_error, dns.exception.Timeout) as e:
self.module.fail_json(msg='DNS server error: (%s): %s' % (e.__class__.__name__, to_native(e)))

entries_to_remove = [n.to_text() for n in lookup.answer[0].items if n.to_text() not in self.value]
lookup_result = lookup.answer[0] if lookup.answer else lookup.authority[0]
entries_to_remove = [n.to_text() for n in lookup_result.items if n.to_text() not in self.value]
Comment on lines +373 to +374
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, in case lookup.answer does not exist, shouldn't entries_to_remove simply be set to []? In that situation there is no current NS value on that level that can be deleted, after all.

So something like

Suggested change
lookup_result = lookup.answer[0] if lookup.answer else lookup.authority[0]
entries_to_remove = [n.to_text() for n in lookup_result.items if n.to_text() not in self.value]
entries_to_remove = [n.to_text() for n in lookup.answer[0].items if n.to_text() not in self.value] if lookup.answer else []

maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my understanding of that block is bind9 will not let you rewrite the last NS record in the zone, so the new record is inserted first, and old one is deleted after. In my case it would not be the last, but the record does exist and needs to be deleted. But since the zone is subdelegated to another server, the data is in authority section. My guess is it was tested on the server where delegation was to another local zone so this was missed. If we do it like you suggest, we would have dupes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, ok. This still doens't sound right to me, but I don't use bind9 or the module so I don't know what really happens :)

In any case, this shouldn't break any existing behavior since if this happened so far, it resulted in an error, so in the worst case this is introducing wrong behavior in a case that didn't work at all before. If someone complains about it, we'll have to look into it again to figure out why exactly it works for you but not for them. And if nobody complains, I guess it's fine for everyone then :)

else:
update.delete(self.module.params['record'], self.module.params['type'])

Expand Down