Skip to content

Don't create an account when looking up the most recent account email - #421

Open
amlaban65 wants to merge 1 commit into
caddyserver:masterfrom
amlaban65:fix-recent-account-email-default
Open

amlaban65 wants to merge 1 commit into
caddyserver:masterfrom
amlaban65:fix-recent-account-email-default

Conversation

@amlaban65

Copy link
Copy Markdown

Fixes #420

Problem

When no email is configured, setEmail falls back to mostRecentAccountEmail, which picks the most recently modified folder under users/ and then called loadOrCreateAccount with the folder name as the email.

saveAccount stores the registration first and the private key second. If another obtain lists the users/ folder between those two writes, the newest folder is users/default (an account without a contact), but its key isn't readable yet. loadAccount returns fs.ErrNotExist, so loadOrCreateAccount creates a new account with the email default. That value is returned as the "recent" email and kept in the package-level discoveredEmail, so the obtain (and every later one in the process) tries to register mailto:default, which CAs reject with invalidContact.

Fix

mostRecentAccountEmail only needs to read an existing account, so it now calls loadAccount instead of loadOrCreateAccount. If the account can't be loaded yet, no email is returned and the obtain goes on to the normal registration path (waiting on the register_acme_account lock 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

  • Added TestGetEmailFromRecentIgnoresPartiallySavedAccount, which stores only the registration of a contact-less account (the state between the two writes in saveAccount) and checks that setEmail ends up with no email and doesn't set discoveredEmail. It fails on master (got 'default') and passes with the fix.
  • go test -race ./... (Go 1.25.1) passes, except TestLookupNameserversOK and TestFindZoneByFqdn, which need external DNS and were skipped because my test environment has none. gofmt and go vet are clean.
  • I did not rerun the Pebble reproduction from the issue.

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>
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.

Concurrent obtains can register an ACME account with the contact mailto:default

1 participant