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: ptr search query #32

Merged
merged 1 commit into from
Dec 29, 2024
Merged

Conversation

BobVanB
Copy link
Contributor

@BobVanB BobVanB commented Dec 20, 2024

Issue: PTR Record Lookup Fails

Description of the Problem:

The current implementation of the PTR record lookup does not function as expected. An additional field ~=name=<fqdn> is added to the query deep in the codebase, which causes the PTR record search to be empty.

Code Reference:
infoblox.go: line 119

Current Behavior:

When searching for a PTR record, the following query is generated:

https://infoblox:443/wapi/v2.12/record:ptr?name=new.example.com&name~=new.example.com

This query does not return any results because of the additional name~= field, which does not align with how PTR records should be queried in Infoblox. And also name contains a reversed ipv4addr.

Expected Behavior:

The following query works as expected and returns the correct PTR record:

https://infoblox:443/wapi/v2.12/record:ptr?ptrdname=new.example.com

Alternatively, adding an additional search parameter, such as ipv4addr, makes the query even more specific and reliable:

https://infoblox:443/wapi/v2.12/record:ptr?ptrdname=new.example.com&ipv4addr=111.222.111.222

Root Cause:

  • The name field in the current implementation includes an IP address in reverse order with an additional extension. This must be reversed and handled properly.
  • Using ptrdname directly is more aligned with Infoblox's API specification for PTR record lookups.
  • Adding ipv4addr ensures precise matching when searching for a specific record.

Example:

    {
        "_ref": "record:ptr/Zay5ubA:222.111.222.111.in-addr.arpa/<view>",
        "extattrs": {},
        "ipv4addr": "111.222.111.222",
        "ipv6addr": "",
        "name": "222.111.222.111.in-addr.arpa",
        "ptrdname": "new.example.com",
        "ttl": 60,
        "use_ttl": true,
        "view": "<view>",
        "zone": "222.111.in-addr.arpa"
    }

Proposed Solution:

  1. Modify the code to replace the incorrect query logic and remove name~= for PTR record lookups.
  2. Update the query to use ptrdname directly:
    https://infoblox:443/wapi/v2.12/record:ptr?ptrdname=new.example.com
    
  3. For additional precision, optionally include ipv4addr in the query:
    https://infoblox:443/wapi/v2.12/record:ptr?ptrdname=new.example.com&ipv4addr=111.222.111.222
    

This pull request aims to improve the accuracy and reliability of PTR record lookups while aligning the implementation with Infoblox API best practices. Feedback is welcome!

@kuritka
Copy link
Collaborator

kuritka commented Dec 25, 2024

Thx for the PR @BobVanB. At all I have not much against implementation. Please squash your commits into single one otherwise release-plese action will generates multiple patches.

@k0da , it looks for searching PTR it generates

https://infoblox:443/wapi/v2.12/record:ptr?name=new.example.com&name~=new.example.com

instead of

https://infoblox:443/wapi/v2.12/record:ptr?ptrdname=new.example.com

do you know reason for this?

@BobVanB BobVanB force-pushed the fix_ptr_update_issue branch from c74c5cd to 1a47f1b Compare December 25, 2024 20:17
@kuritka
Copy link
Collaborator

kuritka commented Dec 27, 2024

thx @BobVanB and give us ⭐

@kuritka kuritka merged commit bbcb30d into AbsaOSS:main Dec 29, 2024
4 checks passed
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.

2 participants