-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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 acme account deletion without provider change #3664
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👼
Good catch. Well done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. Few remarks.
Could you also add some tests. You could maybe extract this new things into a function to be able to test more easily
provider/acme/provider.go
Outdated
if p.account != nil && p.account.Registration != nil { | ||
aru, err := url.Parse(p.account.Registration.URI) | ||
if err != nil { | ||
log.Error("Unable to parse account.Registration URL") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to return an error
provider/acme/provider.go
Outdated
} | ||
cau, err := url.Parse(p.CAServer) | ||
if err != nil { | ||
log.Error("Unable to parse CAServer URL") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to return an error
acme/acme.go
Outdated
if account != nil && account.Registration != nil { | ||
aru, err := url.Parse(account.Registration.URI) | ||
if err != nil { | ||
log.Error("Unable to parse account.Registration URL") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to return an error
acme/acme.go
Outdated
} | ||
cau, err := url.Parse(a.CAServer) | ||
if err != nil { | ||
log.Error("Unable to parse CAServer URL") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to return an error
provider/acme/provider.go
Outdated
log.Error("Unable to parse CAServer URL") | ||
} | ||
if strings.Compare(cau.Hostname(), aru.Hostname()) != 0 { | ||
log.Error("Account does not match the current CAServer") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please change the level of this log and improve the message with something like that
log.Info("Account URI does not match the current CAServer. The account will be reset")
provider/acme/provider.go
Outdated
log.Error("Unable to parse CAServer URL") | ||
} | ||
if strings.Compare(cau.Hostname(), aru.Hostname()) != 0 { | ||
log.Error("Account does not match the current CAServer") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please change the level of this log and improve the message with something like that
log.Info("Account URI does not match the current CAServer. The account will be reset")
acme/acme.go
Outdated
log.Error("Unable to parse CAServer URL") | ||
} | ||
if strings.Compare(cau.Hostname(), aru.Hostname()) != 0 { | ||
log.Error("Account does not match the current CAServer") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please change the level of this log and improve the message with something like that
log.Info("Account URI does not match the current CAServer. The account will be reset")
acme/acme.go
Outdated
log.Error("Unable to parse CAServer URL") | ||
} | ||
if strings.Compare(cau.Hostname(), aru.Hostname()) != 0 { | ||
log.Error("Account does not match the current CAServer") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please change the level of this log and improve the message with something like that
log.Info("Account URI does not match the current CAServer. The account will be reset")
provider/acme/provider.go
Outdated
if err != nil { | ||
log.Error("Unable to parse CAServer URL") | ||
} | ||
if strings.Compare(cau.Hostname(), aru.Hostname()) != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you don't return error before - cau
and aru
can be nil
acme/acme.go
Outdated
if err != nil { | ||
log.Error("Unable to parse CAServer URL") | ||
} | ||
if strings.Compare(cau.Hostname(), aru.Hostname()) != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you don't return error before - cau
and aru
can be nil
i have no proper go dev environment, it's a bit trail and error with simply a text editor... as i do not know how to properly write tests in go, it would be nice if someone could support me here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix.
You can start to add a function in provider/acme/provider_test.go
func TestIsAccountMatchingCaServer(t *testing.T) {
testCases := []struct {
desc string
accountURI string
serverURI string
expected bool
}{
{
desc: "description",
accountURI: "http://powpow.com/",
serverURI: "http://powpow2.com/",
expected: false,
},
{
desc: "description 2",
accountURI: "http://powpow.com/",
serverURI: "http://powpow.com/",
expected: true,
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
result := isAccountMatchingCaServer(test.accountURI, test.serverURI)
assert.Equal(t, test.expected, result)
})
}
}
acme/acme.go
Outdated
log.Infof("Unable to parse CAServer URL : %v", err) | ||
return false | ||
} | ||
return strings.Compare(cau.Hostname(), aru.Hostname()) != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should replace by
return cau.Hostname() == aru.Hostname()
provider/acme/provider.go
Outdated
log.Infof("Unable to parse CAServer URL : %v", err) | ||
return false | ||
} | ||
return strings.Compare(cau.Hostname(), aru.Hostname()) != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should replace by
return cau.Hostname() == aru.Hostname()
acme/acme.go
Outdated
@@ -183,7 +184,8 @@ func (a *ACME) leadershipListener(elected bool) error { | |||
account := object.(*Account) | |||
account.Init() | |||
// Reset Account values if caServer changed, thus registration URI can be updated | |||
if account != nil && account.Registration != nil && !strings.HasPrefix(account.Registration.URI, a.CAServer) { | |||
if account != nil && account.Registration != nil && isAccountMatchingCaServer(account.Registration.URI, a.CAServer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's should be !isAccountMatchingCaServer(account.Registration.URI, a.CAServer)
instead of isAccountMatchingCaServer(account.Registration.URI, a.CAServer)
no ?
provider/acme/provider.go
Outdated
@@ -130,7 +131,8 @@ func (p *Provider) Init(_ types.Constraints) error { | |||
} | |||
|
|||
// Reset Account if caServer changed, thus registration URI can be updated | |||
if p.account != nil && p.account.Registration != nil && !strings.HasPrefix(p.account.Registration.URI, p.CAServer) { | |||
if p.account != nil && p.account.Registration != nil && isAccountMatchingCaServer(p.account.Registration.URI, p.CAServer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's should be !isAccountMatchingCaServer(account.Registration.URI, a.CAServer)
instead of isAccountMatchingCaServer(account.Registration.URI, a.CAServer)
no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, my mistake
expected: false, | ||
}, | ||
{ | ||
desc: "malformed server url", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a test with 2 malformed url
Like that:
{
desc: "malformed account & server url",
accountURI: "/test.example.com/acme/acct/1234567",
serverURI: "/test.example.com/acme/acct/1234567",
expected: false,
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
problem is, it's not really malformed for the parser.. i'll find a different approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Great jobs @zyclonite 👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What does this PR do?
prevent traefik from deleting the acme.account without provider change
fixes issue #3650