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

GANDI: Gandi v5 auth changes #2726

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

llange
Copy link
Contributor

@llange llange commented Dec 16, 2023

This PR handles the new default auth mechanism for GANDI_V5 API (token) now that the apikey is officialy deprecated.
The change should be transparent for existing users still using the apikey entry.
Other changes to creds.json include:

  • introducing apiurl setting to control then endpoint and allowing to use the sandbox endpoint
  • introducing dryrun setting to allow DryRun use of certain API verbs (untested)

Please note that I had no success creating a domain in the sandbox environment, thus was not able to validate that everything was working as expected there. However, the API calls are (of course) properly sent to apiurl and the authentication works there.
(notifying maintainer: @TomOnTime @tlimoncelli)

@llange llange force-pushed the gandi_v5-auth-changes branch 2 times, most recently from 4256b96 to bd136ec Compare December 16, 2023 09:07
@llange llange marked this pull request as ready for review December 16, 2023 09:09
@llange
Copy link
Contributor Author

llange commented Dec 16, 2023

Well it looks that the promising dryrun parameter is in fact not used with the LiveDns API, so may be we should remove completely this commit.

@tlimoncelli
Copy link
Contributor

Yeah, I'd remove the dryrun feature. Seems like it will create more confusion than help.

// SharingID: client.sharingid,
// Debug: client.debug,
// })
// g := NewLiveDNSClient(client)
Copy link
Contributor

Choose a reason for hiding this comment

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

"N" should be lowercase. There's no need to export this function.

@tlimoncelli
Copy link
Contributor

I'm a Gandi user so I was very excited to see this PR. However I don't seem to be able to make this work with my configuration.

From the debug output, it looks like it is using the Bearer token for most system calls, but not all. In particular, GetNameservers and GetRegistrarCorrections don't seem to be updated to use the Bearer token (PAT).

My creds.json entry:

  "gandi_v5_tal": {
    "TYPE": "GANDI_V5",
    "token": "REDACTED_40_CHAR_TOKEN",
    "sharing_id": "REDACTED_SHARING_ID"
  },

The output with debug:

******************** Domain: tomontime.com
2024/01/03 11:00:14 gandi.go:182: Request:  curl -X 'GET' -H 'Authorization: Bearer REDACTED_40_CHAR_TOKEN' -H 'Content-Type: application/json' 'https://api.gandi.net/v5/livedns/domains/tomontime.com/nameservers?sharing_id=REDACTED_SHARING_ID'
2024/01/03 11:00:15 gandi.go:198: Response : [200 OK] X-Xss-Protection: [1; mode=block] Expires: [Wed, 03 Jan 2024 16:00:15 GMT] Pragma: [no-cache] Trace-Id: [97b081ebf0417304] Etag: [W/"3d-GBt9IXujKOWNHm1faEoIijw/IYM"] Server: [nginx] Cache-Control: [max-age=0, must-revalidate, no-cache, no-store] Vary: [Accept-Encoding, Accept-Language] Date: [Wed, 03 Jan 2024 16:00:15 GMT] Content-Length: [61] Strict-Transport-Security: [max-age=15768000;] X-Frame-Options: [DENY] Content-Type: [application/json; charset=utf-8] Connection: [keep-alive] Last-Modified: [Wed, 03 Jan 2024 16:00:15 GMT] X-Content-Type-Options: [nosniff] 
2024/01/03 11:00:15 gandi.go:199: Response body: ["ns-175-a.gandi.net","ns-9-b.gandi.net","ns-76-c.gandi.net"]
2024/01/03 11:00:15 gandi.go:182: Request:  curl -X 'GET' -H 'Authorization: Bearer REDACTED_40_CHAR_TOKEN' -H 'Content-Type: application/json' 'https://api.gandi.net/v5/livedns/domains/tomontime.com/records?sharing_id=REDACTED_SHARING_ID'
2024/01/03 11:00:15 gandi.go:198: Response : [200 OK] Content-Type: [application/json; charset=utf-8] Trace-Id: [9cb7836cbd7d1ccb] X-Content-Type-Options: [nosniff] X-Frame-Options: [DENY] Pragma: [no-cache] Total-Count: [19] Vary: [Accept-Encoding, Accept-Language] Strict-Transport-Security: [max-age=15768000;] Date: [Wed, 03 Jan 2024 16:00:15 GMT] Content-Length: [3822] Cache-Control: [max-age=0, must-revalidate, no-cache, no-store] Server: [nginx] Connection: [keep-alive] Expires: [Wed, 03 Jan 2024 16:00:15 GMT] Last-Modified: [Wed, 03 Jan 2024 16:00:15 GMT] Etag: [W/"eee-APQRA04x4QnKQTKyE+zYrZiUpb8"] X-Xss-Protection: [1; mode=block] 
2024/01/03 11:00:15 gandi.go:199: Response body: [{"rrset_name":"@","rrset_type":"A","rrset_ttl":300,"rrset_values":["198.185.159.144","198.185.159.145","198.49.23.144","198.49.23.145"],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/%40/A"},{"rrset_name":"@","rrset_type":"MX","rrset_ttl":86400,"rrset_values":["1 aspmx.l.google.com.","5 alt1.aspmx.l.google.com.","5 alt2.aspmx.l.google.com.","10 aspmx2.googlemail.com.","10 aspmx3.googlemail.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/%40/MX"},{"rrset_name":"calendar","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/calendar/CNAME"},{"rrset_name":"docs","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/docs/CNAME"},{"rrset_name":"drive","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/drive/CNAME"},{"rrset_name":"go","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/go/CNAME"},{"rrset_name":"goto","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/goto/CNAME"},{"rrset_name":"groups","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/groups/CNAME"},{"rrset_name":"hangouts","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/hangouts/CNAME"},{"rrset_name":"m","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/m/CNAME"},{"rrset_name":"mail","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/mail/CNAME"},{"rrset_name":"mz5nr947kcajxfzmb36m","rrset_type":"CNAME","rrset_ttl":300,"rrset_values":["verify.squarespace.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/mz5nr947kcajxfzmb36m/CNAME"},{"rrset_name":"plus","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/plus/CNAME"},{"rrset_name":"sheets","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/sheets/CNAME"},{"rrset_name":"sites","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/sites/CNAME"},{"rrset_name":"slides","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/slides/CNAME"},{"rrset_name":"start","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/start/CNAME"},{"rrset_name":"vault","rrset_type":"CNAME","rrset_ttl":86400,"rrset_values":["ghs.googlehosted.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/vault/CNAME"},{"rrset_name":"www","rrset_type":"CNAME","rrset_ttl":300,"rrset_values":["ext-cust.squarespace.com."],"rrset_href":"https://api.gandi.net/v5/livedns/domains/tomontime.com/records/www/CNAME"}]
   0: @ A 300 A tomontime.com 198.185.159.144 300
   1: @ A 300 A tomontime.com 198.185.159.145 300
   2: @ A 300 A tomontime.com 198.49.23.144 300
   3: @ A 300 A tomontime.com 198.49.23.145 300
   4: @ MX 86400 MX tomontime.com aspmx.l.google.com. 86400 pref=1
   5: @ MX 86400 MX tomontime.com alt1.aspmx.l.google.com. 86400 pref=5
   6: @ MX 86400 MX tomontime.com alt2.aspmx.l.google.com. 86400 pref=5
   7: @ MX 86400 MX tomontime.com aspmx2.googlemail.com. 86400 pref=10
   8: @ MX 86400 MX tomontime.com aspmx3.googlemail.com. 86400 pref=10
   9: calendar CNAME 86400 CNAME calendar.tomontime.com ghs.googlehosted.com. 86400
   10: docs CNAME 86400 CNAME docs.tomontime.com ghs.googlehosted.com. 86400
   11: drive CNAME 86400 CNAME drive.tomontime.com ghs.googlehosted.com. 86400
   12: go CNAME 86400 CNAME go.tomontime.com ghs.googlehosted.com. 86400
   13: goto CNAME 86400 CNAME goto.tomontime.com ghs.googlehosted.com. 86400
   14: groups CNAME 86400 CNAME groups.tomontime.com ghs.googlehosted.com. 86400
   15: hangouts CNAME 86400 CNAME hangouts.tomontime.com ghs.googlehosted.com. 86400
   16: m CNAME 86400 CNAME m.tomontime.com ghs.googlehosted.com. 86400
   17: mail CNAME 86400 CNAME mail.tomontime.com ghs.googlehosted.com. 86400
   18: mz5nr947kcajxfzmb36m CNAME 300 CNAME mz5nr947kcajxfzmb36m.tomontime.com verify.squarespace.com. 300
   19: plus CNAME 86400 CNAME plus.tomontime.com ghs.googlehosted.com. 86400
   20: sheets CNAME 86400 CNAME sheets.tomontime.com ghs.googlehosted.com. 86400
   21: sites CNAME 86400 CNAME sites.tomontime.com ghs.googlehosted.com. 86400
   22: slides CNAME 86400 CNAME slides.tomontime.com ghs.googlehosted.com. 86400
   23: start CNAME 86400 CNAME start.tomontime.com ghs.googlehosted.com. 86400
   24: vault CNAME 86400 CNAME vault.tomontime.com ghs.googlehosted.com. 86400
   25: www CNAME 300 CNAME www.tomontime.com ext-cust.squarespace.com. 300
2024/01/03 11:00:15 gandi.go:182: Request:  curl -X 'GET' -H 'Authorization: Apikey ' -H 'Content-Type: application/json' 'https://api.gandi.net/v5/domain/domains/tomontime.com/nameservers?sharing_id=REDACTED_SHARING_ID'
2024/01/03 11:00:15 gandi.go:198: Response : [401 Unauthorized] Content-Type: [application/json; charset=utf-8] Content-Length: [108] Connection: [keep-alive] Etag: [W/"6c-r8Dpx3ZQzNoyYTVga6EZpa8Tj0U"] Server: [nginx] Date: [Wed, 03 Jan 2024 16:00:15 GMT] 
2024/01/03 11:00:15 gandi.go:199: Response body: {"message":"You must provide an access token or an API Key. See https://api.gandi.net/docs/authentication/"}
ERROR
Error getting corrections (gandi_v5_tal): Response body is not json for status 401

@tlimoncelli
Copy link
Contributor

tlimoncelli commented Jan 3, 2024

For integration tests to work, the providers.json file needs to be updated:

$ git diff
diff --git a/integrationTest/providers.json b/integrationTest/providers.json
index ac55cbe5..79399654 100644
--- a/integrationTest/providers.json
+++ b/integrationTest/providers.json
@@ -107,7 +107,8 @@
   "GANDI_V5": {
     "TYPE": "GANDI_V5",
     "apikey": "$GANDI_V5_APIKEY",
-    "domain": "$GANDI_V5_DOMAIN"
+    "domain": "$GANDI_V5_DOMAIN",
+    "token": "$GANDI_V5_TOKEN"
   },
   "GCLOUD": {
     "TYPE": "GCLOUD",

@tlimoncelli
Copy link
Contributor

Another suggestion:
It would be helpful if the docs included the minimum specs for a PAT. From my testing so far, that is:

Domains:
Manage domain name technical configurations
(which implies "See and renew domain names")

@tlimoncelli
Copy link
Contributor

Drat. I can't figure out what settings are required to make a PAT that works for me.

$ dnscontrol preview
******************** Domain: best-spaghetti-sauce-ever.com
ERROR
Error getting corrections (gandi_v5_tal): Response body is not json for status 401

I even created a PAT that has all the DNS-related roles:

screencapture_2024-01-05_09 41 07

@llange
Copy link
Contributor Author

llange commented Feb 12, 2024

Another suggestion: It would be helpful if the docs included the minimum specs for a PAT. From my testing so far, that is:

Domains:
Manage domain name technical configurations
(which implies "See and renew domain names")

I agree with those settings, these are the ones I use with success. My PATs are even limited to "products" (domain names) to further isolate the impact.
I'll update the doc.

@llange
Copy link
Contributor Author

llange commented Feb 12, 2024

Drat. I can't figure out what settings are required to make a PAT that works for me.

$ dnscontrol preview
******************** Domain: best-spaghetti-sauce-ever.com
ERROR
Error getting corrections (gandi_v5_tal): Response body is not json for status 401

I even created a PAT that has all the DNS-related roles:

screencapture_2024-01-05_09 41 07

This seems linked to your previous error : "it looks like it is using the Bearer token for most system calls, but not all" ? If so it's unrelated to the PAT itself.

@llange
Copy link
Contributor Author

llange commented Feb 12, 2024

From the debug output, it looks like it is using the Bearer token for most system calls, but not all. In particular, GetNameservers and GetRegistrarCorrections don't seem to be updated to use the Bearer token (PAT).

It's my fault, I patched only the newLiveDNSClient() side, not the NewDomainClient() side. It did not occur in my tests as I was not dealing with the registrar (yet).
Let me know if this change works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants