Skip to content

Add error message to account registration error - #9233

Merged
alexzorin merged 11 commits into
certbot:masterfrom
osirisinferi:fix-9231
Mar 30, 2022
Merged

alexzorin merged 11 commits into
certbot:masterfrom
osirisinferi:fix-9231

Conversation

@osirisinferi

Copy link
Copy Markdown
Collaborator

Fixes #9231

I've opted to have the first character of the error message to be lower case, as it's the first character after a colon. For me personally, that has to be lower case instead of upper case.

@alexzorin alexzorin left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for picking this up.

I've opted to have the first character of the error message to be lower case, as it's the first character after a colon. For me personally, that has to be lower case instead of upper case.

I think if we choose to do this, we should do it consistently across Certbot's error handling. At the moment, it looks like all cases of errors following a colon, show the error verbatim.

I am also a little skeptical that it won't sometimes do the wrong thing. e.g. if the first word in the error message is ACME, you would get aCME, which is weirdly reminiscent of ASN.1 ;).

@osirisinferi

osirisinferi commented Mar 13, 2022 •

Copy link
Copy Markdown
Collaborator Author

Note that the error "Server requires external account binding. (...)" is actually a message from perform_registration() in client.py and not actually an error message from the ACME API.

I tried to trigger a registration error from the ACME server by manually modifying terms_of_service_agreed=True to False in the NewRegistration object when registering an account. This raises an error with the "Provided account did not agree to the terms of service" message from Pebble, but it's raised by acme/client.py and is not catched by the Certbot code.

Not sure if we can live with that or that we should catch ACME errors from the acme library somewhere in Certbot too? Although this is manually forced, not sure what errors one would expect when there's no manual tampering..

Addressed the above 🙂

@osirisinferi

osirisinferi commented Mar 13, 2022 •

Copy link
Copy Markdown
Collaborator Author

Code is a little bit more complicated now to also catch errors from the acme library. It raises acme.messages.Error and it contains the str detail if provided by the ACME API. If not, the acme library can return a human readable description of the ACME error type using the description property.

An example would be an urn:ietf:params:acme:error:serverInternal error without any detail message set. (Not sure if ACME servers would do that, but just in case.) Without the extra check the error message printed would be "Unable to register an account with ACME server. Error returned by the ACME server: None".

@osirisinferi
osirisinferi requested a review from alexzorin March 13, 2022 13:40
Comment thread certbot/certbot/_internal/main.py Outdated
Comment on lines +732 to +748
if isinstance(err, acme_messages.Error):
# `acme.messages.Error` has more details than `certbot.errors.Error`, so we
# can use these details to provide a human readable error message:
if err.detail:
# `detail` contains a human readable error message provided by the
# ACME server.
err_msg = err.detail
elif err.description:
# If `detail` is not provided, the `acme` library can return a human
# readable error message based on the error type in `description`.
err_msg = err.description
else:
# If no human readable error message can be found, the ACME error type
# is presented to the user.
err_msg = str(err)
else:
err_msg = str(err)

@alexzorin alexzorin Mar 30, 2022 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry for the delay reviewing this, it's been hard to find time.

For consistency and simplicity's sake, ISTM that we can just take advantage of __str__ on acme.messages.Error:

def __str__(self) -> str:
return b' :: '.join(
part.encode('ascii', 'backslashreplace') for part in
(self.typ, self.description, self.detail, self.title)
if part is not None).decode()

Would you be able to give that a try and see whether str(err) does the trick? I'd like to avoid having one-off code related to display here. If we do end up needing a new way to display errors to users, we should deal with it in a global way.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I noticed that function too when looking at it. But if we use str(err) it would mean a Certbot raised error would be a relative simple error message which would be very different than an error message raised by the ACME client, as that would be a long line with all the different fields separated by " :: ". To me, that difference was too big, so I build the code above to make it more the same with regard to a user experience: a simple to understand error message.

But of course KISS is always a good argument 😉

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's reasonable, and there's always the option to change what __str__ does, if we do decide it's unreadable.

https://datatracker.ietf.org/doc/html/rfc7807#section-3.1 is pretty clear that only title and detail are supposed to be human-readable.

I also recall reading a comment on the Certbot repo years ago from one of Boulder's developers, calling Certbot out for the way the description property is interpreting the problem type and mapping it into this dictionary. This was a misinterpretation of the ACME document, I think.

tl;dr; I'm sure we'd be open to changing it, but let's kick it to another issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'll make this code as simple as possible, so we can change anything, if required, from a single point in __str__() in the future.

@alexzorin alexzorin self-assigned this Mar 30, 2022
@osirisinferi

Copy link
Copy Markdown
Collaborator Author

I did leave the distinction between a Certbot generated error and ACME server generated error and I removed the "Error returned by the ACME server: " part for a Certbot generated error, as that was incorrect before.

Also note that the contents test_register_error_acme_type_and_detail() test would never be presented to the user by Certbot, as Certbot would have raised its own error when the user chooses not to agree with the ToS.. But I think it's worth having a test for that specific case anyway, the actual contents don't really matter in that regard I think.

@osirisinferi
osirisinferi requested a review from alexzorin March 30, 2022 10:05
Comment thread certbot/certbot/_internal/main.py Resolved
Comment thread certbot/tests/main_test.py Resolved
Comment thread certbot/tests/main_test.py Resolved
Comment thread certbot/tests/main_test.py Resolved
Comment thread certbot/tests/main_test.py Resolved
except (errors.Error, acme_messages.Error) as err:
logger.debug("", exc_info=True)
if isinstance(err, acme_messages.Error):
err_msg = f"Error returned by the ACME server: {str(err)}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lol:

if messages.is_acme_error(exc_value):
# Remove the ACME error prefix from the exception
_, _, exc_str = str(exc_value).partition(':: ')
logger.error(exc_str)

I am starting to wonder we should change this properly, now. I'm actually not sure whether messing with __str__ would be a breaking change, but we can always add a new method for display purposes. Let me find out.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hm, that code assumes that an ACME error always contains all three properties. But in acme.messages.Error all three properties have omitempty=True set. So if the ACME server doesn't e.g. provide the title for some reason, str(err) would only provide two partitions separated by :: , right? Not sure if Boulder actually does that and not sure if it's allowed by the RFCs, but still.

Also, not sure how it's tied into this PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would really like to not show the error type and the description field, but let's leave it for now. This PR fixes the problem it was supposed to, albeit slightly verbosely.

Put everything in this commit instead of using the "Commit suggestion"
feat on Github, which would resolve in 4 different tiny commits.
@alexzorin
alexzorin merged commit 4456a6b into certbot:master Mar 30, 2022
@osirisinferi
osirisinferi deleted the fix-9231 branch March 31, 2022 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

certbot register is swallowing error details

2 participants