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

Add DNS provider for VK Cloud #1706

Merged
merged 12 commits into from Sep 2, 2022
Merged

Add DNS provider for VK Cloud #1706

merged 12 commits into from Sep 2, 2022

Conversation

kluevandrew
Copy link
Contributor

@kluevandrew kluevandrew commented Aug 30, 2022

DNS Provider for VK Cloud. Closes #1705

  • add a description to your PR
  • be able to maintain this provider
  • have a homogeneous design with the other providers
  • add tests (units)
  • add tests ("live")
  • add a provider descriptor
  • generate CLI help, documentation, and readme.
  • be able to do ./lego -m your@email.com --dns YOUR_PROVIDER_NAME ....
  • pass the linter
  • do go mod tidy

Stdout of example

$ export VK_CLOUD_PROJECT_ID=<sensetive_information_truncated>
$ export VK_CLOUD_USERNAME=andrey.klyuev@vk.team
$ export VK_CLOUD_PASSWORD=<sensetive_information_truncated>
$ rm -rf .lego && ./lego --email andrey.klyuev@vk.team --dns vkcloud --domains "bet-statistic.ru" --domains "*.bet-statistic.ru"  -s https://acme-staging-v02.api.letsencrypt.org/directory run
2022/08/30 20:09:17 No key found for account andrey.klyuev@vk.team. Generating a P256 key.
2022/08/30 20:09:17 Saved key to /Users/andrey.klyuev/Projects/go-acme/lego/.lego/accounts/acme-staging-v02.api.letsencrypt.org/andrey.klyuev@vk.team/keys/andrey.klyuev@vk.team.key
2022/08/30 20:09:18 Please review the TOS at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017-w-v1.3-notice.pdf
Do you accept the TOS? Y/n
Y
2022/08/30 20:09:22 [INFO] acme: Registering account for andrey.klyuev@vk.team
!!!! HEADS UP !!!!

Your account credentials have been saved in your Let's Encrypt
configuration directory at "/Users/andrey.klyuev/Projects/go-acme/lego/.lego/accounts".

You should make a secure backup of this folder now. This
configuration directory will also contain certificates and
private keys obtained from Let's Encrypt so making regular
backups of this folder is ideal.
2022/08/30 20:09:22 [INFO] [bet-statistic.ru, *.bet-statistic.ru] acme: Obtaining bundled SAN certificate
2022/08/30 20:09:23 [INFO] [*.bet-statistic.ru] AuthURL: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/3485466163
2022/08/30 20:09:23 [INFO] [bet-statistic.ru] AuthURL: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/3485466173
2022/08/30 20:09:23 [INFO] [*.bet-statistic.ru] acme: use dns-01 solver
2022/08/30 20:09:23 [INFO] [bet-statistic.ru] acme: Could not find solver for: tls-alpn-01
2022/08/30 20:09:23 [INFO] [bet-statistic.ru] acme: Could not find solver for: http-01
2022/08/30 20:09:23 [INFO] [bet-statistic.ru] acme: use dns-01 solver
2022/08/30 20:09:23 [INFO] [*.bet-statistic.ru] acme: Preparing to solve DNS-01
2022/08/30 20:09:24 [INFO] [bet-statistic.ru] acme: Preparing to solve DNS-01
2022/08/30 20:09:24 [INFO] [*.bet-statistic.ru] acme: Trying to solve DNS-01
2022/08/30 20:09:24 [INFO] [*.bet-statistic.ru] acme: Checking DNS record propagation using [100.99.0.231:53 100.99.0.230:53]
2022/08/30 20:09:26 [INFO] Wait for propagation [timeout: 1m0s, interval: 2s]
2022/08/30 20:09:26 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:09:28 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:09:30 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:09:32 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:09:34 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:09:36 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:09:38 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:09:40 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:09:42 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:09:45 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:09:47 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:09:49 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:09:51 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/08/30 20:10:00 [INFO] [*.bet-statistic.ru] The server validated our request
2022/08/30 20:10:00 [INFO] [bet-statistic.ru] acme: Trying to solve DNS-01
2022/08/30 20:10:00 [INFO] [bet-statistic.ru] acme: Checking DNS record propagation using [100.99.0.231:53 100.99.0.230:53]
2022/08/30 20:10:02 [INFO] Wait for propagation [timeout: 1m0s, interval: 2s]
2022/08/30 20:10:09 [INFO] [bet-statistic.ru] The server validated our request
2022/08/30 20:10:09 [INFO] [*.bet-statistic.ru] acme: Cleaning DNS-01 challenge
2022/08/30 20:10:11 [INFO] [bet-statistic.ru] acme: Cleaning DNS-01 challenge
2022/08/30 20:10:14 [INFO] [bet-statistic.ru, *.bet-statistic.ru] acme: Validations succeeded; requesting certificates
2022/08/30 20:10:15 [INFO] [bet-statistic.ru] Server responded with a certificate.
Exiting.

@ldez
Copy link
Member

ldez commented Aug 30, 2022

Hello, in order for a PR adding a DNS provider to be accepted, you have to:

  • add a description to your PR
  • be able to maintain this provider
  • have a homogeneous design with the other providers
  • add tests (units)
make test
  • add tests ("live")
    func TestLivePresent(t *testing.T) {
    if !envTest.IsLiveTest() {
    t.Skip("skipping live test")
    }
    envTest.RestoreEnv()
    provider, err := NewDNSProvider()
    require.NoError(t, err)
    err = provider.Present(envTest.GetDomain(), "", "123d==")
    require.NoError(t, err)
    }
    func TestLiveCleanUp(t *testing.T) {
    if !envTest.IsLiveTest() {
    t.Skip("skipping live test")
    }
    envTest.RestoreEnv()
    provider, err := NewDNSProvider()
    require.NoError(t, err)
    time.Sleep(2 * time.Second)
    err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
    require.NoError(t, err)
    }
make test
make generate-dns
  • be able to do: (and put the output of this command to a comment in your PR)
rm -rf .lego

./lego -m your@email.com --dns YOUR_PROVIDER_NAME -d *.example.com -d example.com -s https://acme-staging-v02.api.letsencrypt.org/directory run

Note the wildcard domain is important.

make checks
  • do go mod tidy

@ldez ldez self-requested a review August 30, 2022 17:25
@kluevandrew kluevandrew mentioned this pull request Aug 30, 2022
5 tasks
@ldez ldez changed the title VK Cloud DNS provider Add DNS provider for VK Cloud Sep 1, 2022
@ldez
Copy link
Member

ldez commented Sep 1, 2022

As I changed the code, I will ask you to run again the command:

rm -rf .lego

./lego -m your@email.com --dns YOUR_PROVIDER_NAME -d *.example.com -d example.com -s https://acme-staging-v02.api.letsencrypt.org/directory run

@ldez ldez added this to the v4.9 milestone Sep 1, 2022
@kluevandrew
Copy link
Contributor Author

As I changed the code, I will ask you to run again the command:

ok, i will make it today

@kluevandrew
Copy link
Contributor Author

kluevandrew commented Sep 2, 2022

Unfortunately it stopped working, VK Cloud has not good API which works strange with trailing slash in URL, it required for each request except txt record deletion, i will fix it soon.

Unfortunately i must replace path.Join call with fmt.Sprintf because path.Join clears trailing slash

@kluevandrew
Copy link
Contributor Author

I fixed a bug with trailing slash, merged actual changes from master and now it works

2022/09/02 11:58:57 No key found for account andrey.klyuev@vk.team. Generating a P256 key.
2022/09/02 11:58:57 Saved key to /Users/andrey.klyuev/Projects/go-acme/lego/.lego/accounts/acme-staging-v02.api.letsencrypt.org/andrey.klyuev@vk.team/keys/andrey.klyuev@vk.team.key
2022/09/02 11:58:57 Please review the TOS at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017-w-v1.3-notice.pdf
Do you accept the TOS? Y/n
Y
2022/09/02 11:59:00 [INFO] acme: Registering account for andrey.klyuev@vk.team
!!!! HEADS UP !!!!

Your account credentials have been saved in your Let's Encrypt
configuration directory at "/Users/andrey.klyuev/Projects/go-acme/lego/.lego/accounts".

You should make a secure backup of this folder now. This
configuration directory will also contain certificates and
private keys obtained from Let's Encrypt so making regular
backups of this folder is ideal.
2022/09/02 11:59:00 [INFO] [bet-statistic.ru, *.bet-statistic.ru] acme: Obtaining bundled SAN certificate
2022/09/02 11:59:01 [INFO] [*.bet-statistic.ru] AuthURL: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/3512654573
2022/09/02 11:59:01 [INFO] [bet-statistic.ru] AuthURL: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/3512654583
2022/09/02 11:59:01 [INFO] [*.bet-statistic.ru] acme: use dns-01 solver
2022/09/02 11:59:01 [INFO] [bet-statistic.ru] acme: Could not find solver for: tls-alpn-01
2022/09/02 11:59:01 [INFO] [bet-statistic.ru] acme: Could not find solver for: http-01
2022/09/02 11:59:01 [INFO] [bet-statistic.ru] acme: use dns-01 solver
2022/09/02 11:59:01 [INFO] [*.bet-statistic.ru] acme: Preparing to solve DNS-01
2022/09/02 11:59:05 [INFO] [bet-statistic.ru] acme: Preparing to solve DNS-01
2022/09/02 11:59:05 [INFO] [*.bet-statistic.ru] acme: Trying to solve DNS-01
2022/09/02 11:59:05 [INFO] [*.bet-statistic.ru] acme: Checking DNS record propagation using [10.73.0.1:53 77.37.251.33:53 77.37.255.30:53]
2022/09/02 11:59:07 [INFO] Wait for propagation [timeout: 1m0s, interval: 2s]
2022/09/02 11:59:07 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 11:59:09 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 11:59:11 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 11:59:14 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 11:59:16 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 11:59:18 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 11:59:20 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 11:59:22 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 11:59:24 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 11:59:26 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 11:59:31 [INFO] [*.bet-statistic.ru] The server validated our request
2022/09/02 11:59:31 [INFO] [bet-statistic.ru] acme: Trying to solve DNS-01
2022/09/02 11:59:31 [INFO] [bet-statistic.ru] acme: Checking DNS record propagation using [10.73.0.1:53 77.37.251.33:53 77.37.255.30:53]
2022/09/02 11:59:33 [INFO] Wait for propagation [timeout: 1m0s, interval: 2s]
2022/09/02 11:59:40 [INFO] [bet-statistic.ru] The server validated our request
2022/09/02 11:59:40 [INFO] [*.bet-statistic.ru] acme: Cleaning DNS-01 challenge
2022/09/02 11:59:40 [INFO] [bet-statistic.ru] acme: Cleaning DNS-01 challenge
2022/09/02 11:59:41 [INFO] [bet-statistic.ru, *.bet-statistic.ru] acme: Validations succeeded; requesting certificates
2022/09/02 11:59:42 [INFO] [bet-statistic.ru] Server responded with a certificate.
Exiting.

@ldez
Copy link
Member

ldez commented Sep 2, 2022

I implemented a simpler solution.

the only case that can be a problem is on the delete.

Note: your solution had a problem:

package internal

import (
	"fmt"
	"strings"
	"testing"
)

func TestName(t *testing.T) {
	fmt.Println(joinURL("v2", "dns", "uri", "/")) // => "v2/dns/uri//" (double trailing slash)
}

func joinURL(parts ...string) string {
	return strings.Join(parts, "/")
}

@ldez
Copy link
Member

ldez commented Sep 2, 2022

I rethought the problem again and mimicked the go1.19 API.

@kluevandrew
Copy link
Contributor Author

I rethought the problem again and mimicked the go1.19 API.

Great solution, shall i test it again?

PS. I going to push trailing slash problem into DNS API team, hope they can fix it fast

@ldez
Copy link
Member

ldez commented Sep 2, 2022

Great solution, shall i test it again?

It's the same code as previously so I think you don't need to test it again.
I was just waiting for your feedback.

I going to push trailing slash problem into DNS API team, hope they can fix it fast

I will merge now unless you think that we have to wait for your DNS API team.

@kluevandrew
Copy link
Contributor Author

It's the same code as previously so I think you don't need to test it again. I was just waiting for your feedback.

It's not, something went wrong) I will check and fix it

[*.bet-statistic.ru] [*.bet-statistic.ru] acme: error presenting token: vkcloud: unable to fetch dns zones: request: Get "/public-dns/v2/dns/": unsupported protocol scheme ""

I will merge now unless you think that we have to wait for your DNS API team.

I think you can merge it after fix and not wait for DNS API team, when they fix api i will open new pull request with updates

@kluevandrew
Copy link
Contributor Author

kluevandrew commented Sep 2, 2022

Now it works, problem was in BaseURL parsing, the scheme and domain were lost during the second Parse call

2022/09/02 22:55:08 [INFO] [bet-statistic.ru, *.bet-statistic.ru] acme: Obtaining bundled SAN certificate
2022/09/02 22:55:09 [INFO] [*.bet-statistic.ru] AuthURL: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/3517180543
2022/09/02 22:55:09 [INFO] [bet-statistic.ru] AuthURL: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/3517180553
2022/09/02 22:55:09 [INFO] [*.bet-statistic.ru] acme: use dns-01 solver
2022/09/02 22:55:09 [INFO] [bet-statistic.ru] acme: Could not find solver for: tls-alpn-01
2022/09/02 22:55:09 [INFO] [bet-statistic.ru] acme: Could not find solver for: http-01
2022/09/02 22:55:09 [INFO] [bet-statistic.ru] acme: use dns-01 solver
2022/09/02 22:55:09 [INFO] [*.bet-statistic.ru] acme: Preparing to solve DNS-01
2022/09/02 22:55:25 [INFO] [bet-statistic.ru] acme: Preparing to solve DNS-01
2022/09/02 22:55:27 [INFO] [*.bet-statistic.ru] acme: Trying to solve DNS-01
2022/09/02 22:55:27 [INFO] [*.bet-statistic.ru] acme: Checking DNS record propagation using [10.73.0.1:53 77.37.251.33:53 77.37.255.30:53]
2022/09/02 22:55:29 [INFO] Wait for propagation [timeout: 1m0s, interval: 2s]
2022/09/02 22:55:29 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 22:55:31 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 22:55:33 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 22:55:35 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 22:55:37 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 22:55:39 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 22:55:41 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 22:55:43 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 22:55:45 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 22:55:47 [INFO] [*.bet-statistic.ru] acme: Waiting for DNS record propagation.
2022/09/02 22:55:53 [INFO] [*.bet-statistic.ru] The server validated our request
2022/09/02 22:55:53 [INFO] [bet-statistic.ru] acme: Trying to solve DNS-01
2022/09/02 22:55:53 [INFO] [bet-statistic.ru] acme: Checking DNS record propagation using [10.73.0.1:53 77.37.251.33:53 77.37.255.30:53]
2022/09/02 22:55:55 [INFO] Wait for propagation [timeout: 1m0s, interval: 2s]
2022/09/02 22:55:55 [INFO] [bet-statistic.ru] The server validated our request
2022/09/02 22:55:55 [INFO] [*.bet-statistic.ru] acme: Cleaning DNS-01 challenge
2022/09/02 22:57:20 [INFO] [bet-statistic.ru] acme: Cleaning DNS-01 challenge
2022/09/02 22:57:23 [INFO] [bet-statistic.ru, *.bet-statistic.ru] acme: Validations succeeded; requesting certificates
2022/09/02 22:57:23 [INFO] [bet-statistic.ru] Server responded with a certificate.
Exiting.

Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@ldez ldez merged commit 8fe27e0 into go-acme:master Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Support for provider: VK Cloud
2 participants