Skip to content

Fix --webroot-path action - #10509

Merged
ohemorange merged 3 commits into
certbot:mainfrom
jsha:fix-webroot-path-action
Dec 9, 2025
Merged

ohemorange merged 3 commits into
certbot:mainfrom
jsha:fix-webroot-path-action

Conversation

@jsha

@jsha jsha commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

Fixes #10506.

When --webroot-path was specified multiple times, Certbot was erroring with DNSName SAN compared to non-SAN. That's because, in the _WebrootPathAction that builds namespace.webroot_path, we were passing domain (type san.DNSName) as the keys. The other code that modifies or accesses namespace.webroot_path expects the keys to be of type str. In particular webroot.Authenticator._set_webroots does:

            for achall in achalls:
                self.conf("map").setdefault(achall.domain, webroot_path)

Where achall.domain is a str.

Two existing unittests would have caught this: test_multiwebroot and test_webroot_map_partial_without_perform. However, they faked out the parsing of the --domains flag, and that faked out code was not updated in #10468. Since this bug is caused by an interaction between the types produced by the --domains flag and those produced by the --webroot-path flag, the tests failed to catch the problem. I've updated the tests and confirmed that they fail before the fix is applied.

jsha added 2 commits December 8, 2025 21:19
In the actual CLI, the `action` for the `--domain` arg parses domain strings
into san.DNSName. Make the test reflect that.
This was adding to webroot_map with a key of type `san.DNSName`, but the other
places that add to webroot_map use a key of type `str`. We should use `str` here
too.
@bmw
bmw requested review from a team and bmw and removed request for a team December 9, 2025 06:23
bmw
bmw previously approved these changes Dec 9, 2025

@bmw bmw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

since this PR exists and no one else seems to be complaining at #10506, i vote we go forward with this instead of my reversion PR

because of that, i think this needs a changelog entry. i'd propose what i did in my PR which is to create newsfragments/10506.fixed with the contents:

Fixed a regression that caused certbot to crash if multiple --webroot-path values were set on the command line.

i don't think we need to block this PR on that though as we can always quickly add it in a follow up PR

other than that and my inline comment with praise and an idea you can implement if you really want to for some reason, this LGTM!

self.parser = argparse.ArgumentParser()
self.parser.add_argument("-d", "--domains",
action="append", default=[])
action=cli._DomainsAction, default=[])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i love that making this a more real test is so simple and reliably catches the bug. great idea imo 👏

part of me wants to rename _DomainsAction to DomainsAction as using code "private" to the cli module is a bit hacky here, but i'm honestly not too worried about that right now. i'm just happy to have a real fix with tests here

@bmw
bmw requested review from a team and ohemorange and removed request for a team December 9, 2025 06:36
@zoracon zoracon added this to the 5.2.2 milestone Dec 9, 2025
@zoracon
zoracon requested a review from wgreenberg December 9, 2025 23:20

@ohemorange ohemorange left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fix looks good to me, appreciate the fixed test as well. We should go ahead and get this out, but are there other places that might have had similar problems now that we know this might be a pattern in our code? Probably worth a scan.

@ohemorange
ohemorange merged commit f6d2ae3 into certbot:main Dec 9, 2025
14 checks passed
wgreenberg pushed a commit that referenced this pull request Dec 10, 2025
Fixes #10506.

When --webroot-path was specified multiple times, Certbot was erroring
with `DNSName SAN compared to non-SAN`. That's because, in the
_WebrootPathAction that builds `namespace.webroot_path`, we were passing
`domain` (type `san.DNSName`) as the keys. The other code that modifies
or accesses `namespace.webroot_path` expects the keys to be of type
`str`. In particular `webroot.Authenticator._set_webroots` does:

```python
            for achall in achalls:
                self.conf("map").setdefault(achall.domain, webroot_path)
```

Where `achall.domain` is a `str`.

Two existing unittests would have caught this: `test_multiwebroot` and
`test_webroot_map_partial_without_perform`. However, they faked out the
parsing of the `--domains` flag, and that faked out code was not updated
in #10468. Since this bug is caused by an interaction between the types
produced by the `--domains` flag and those produced by the
`--webroot-path` flag, the tests failed to catch the problem. I've
updated the tests and confirmed that they fail before the fix is
applied.
wgreenberg added a commit that referenced this pull request Dec 10, 2025
Cherry-picks #10509 which fixes #10506. This will eventually make its
way into the 5.2.2 point release

Co-authored-by: Jacob Hoffman-Andrews <[email protected]>
ohemorange pushed a commit that referenced this pull request Dec 16, 2025
…10514)

as i mentioned at
#10509 (comment), i
didn't love how the tests were using `_DomainsAction` when i think the
leading underscore suggests the class is internal to the cli/cl_utils
module

this PR fixes that

also, i don't think this PR requires two reviews
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.

[Bug]: Can't renew multiple domains (certonly, webroot, nginx)

4 participants