Repository navigation
Conversation
mostRecentAccountEmail used loadOrCreateAccount, so if the most recent account folder only had its registration stored (because another obtain was still in saveAccount), it created a new account with the folder name as the email, e.g. mailto:default. Load the account without creating one. Fixes caddyserver#420 Signed-off-by: Ahmed Laban <79754427+amlaban65@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #420
Problem
When no email is configured,
setEmailfalls back tomostRecentAccountEmail, which picks the most recently modified folder underusers/and then calledloadOrCreateAccountwith the folder name as the email.saveAccountstores the registration first and the private key second. If another obtain lists theusers/folder between those two writes, the newest folder isusers/default(an account without a contact), but its key isn't readable yet.loadAccountreturnsfs.ErrNotExist, soloadOrCreateAccountcreates a new account with the emaildefault. That value is returned as the "recent" email and kept in the package-leveldiscoveredEmail, so the obtain (and every later one in the process) tries to registermailto:default, which CAs reject withinvalidContact.Fix
mostRecentAccountEmailonly needs to read an existing account, so it now callsloadAccountinstead ofloadOrCreateAccount. If the account can't be loaded yet, no email is returned and the obtain goes on to the normal registration path (waiting on theregister_acme_accountlock and loading the saved account), as suggested in the issue.One behaviour change to note: if the most recent account folder is permanently missing its key, this no longer creates a new account under that folder's email; it returns no email instead, same as when no account folder exists.
Testing
TestGetEmailFromRecentIgnoresPartiallySavedAccount, which stores only the registration of a contact-less account (the state between the two writes insaveAccount) and checks thatsetEmailends up with no email and doesn't setdiscoveredEmail. It fails onmaster(got 'default') and passes with the fix.go test -race ./...(Go 1.25.1) passes, exceptTestLookupNameserversOKandTestFindZoneByFqdn, which need external DNS and were skipped because my test environment has none.gofmtandgo vetare clean.