Skip to content

Add subproblems to errors (#7046) - #9258

Merged
bmw merged 7 commits into
certbot:masterfrom
pendo-io:rfc-8555-subproblems
Apr 6, 2022
Merged

bmw merged 7 commits into
certbot:masterfrom
pendo-io:rfc-8555-subproblems

Conversation

@JamesBalazs

@JamesBalazs JamesBalazs commented Apr 1, 2022 •

Copy link
Copy Markdown
Contributor

Added an optional subproblems field to acme.messages.Error and a property codes that returns a list of codes for the error, as suggested by @bmw in #7046

Errors now also have an optional Identifier which should only be populated for subproblems as in RFC8555 6.7

To surface the subproblems in the error trace when an error is returned, I've changed acme.messages.Error#__str__ - adding a new line to the string for each subproblem, with its own string representation, eg:

 acme.messages.Error: urn:ietf:params:acme:error:caa :: Certification Authority Authorization (CAA) records forbid the CA from issuing a certificate :: Error finalizing order :: Rechecking CAA for "xxxxx.xxxx.xx" and 1 more identifiers failed. Refer to sub-problems for more information
 Sub-problems:
 [string representation of first sub-problem]
 [string representation of second sub-problem]

The Identifier is tacked onto the end of the subproblems string representation, when present, and itself is represented as {type}={value}.

Pull Request Checklist

  • If the change being made is to a distributed component, edit the master section of certbot/CHANGELOG.md to include a description of the change being made.
  • Add or update any documentation as needed to support the changes in this PR.
  • Include your name in AUTHORS.md if you like.

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

I made a number of small suggestions, but at a high level I think this looks good. Thanks a lot for picking this up.

Comment thread acme/acme/messages.py Outdated
typ: str = jose.field('type', omitempty=True, default='about:blank')
title: str = jose.field('title', omitempty=True)
detail: str = jose.field('detail', omitempty=True)
identifier: Optional['Identifier'] = jose.field('identifier', omitempty=True)

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.

We'd need to move the class definitions of Identifier and its parent classes earlier in this file for this to work, but setting decoder here will cause this value to be converted into an Identifier object during parsing.

Suggested change
identifier: Optional['Identifier'] = jose.field('identifier', omitempty=True)
identifier: Optional['Identifier'] = jose.field('identifier', decoder=Identifier.from_json, omitempty=True)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done - thanks, I wasn't aware this wouldn't be parsed correctly without setting a decoder

Comment thread acme/acme/messages.py Outdated
title: str = jose.field('title', omitempty=True)
detail: str = jose.field('detail', omitempty=True)
identifier: Optional['Identifier'] = jose.field('identifier', omitempty=True)
subproblems: Optional[List['Error']] = jose.field('subproblems', omitempty=True)

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.

Similar to Order.identifiers.decoder in this file, I think we should define subproblems.decoder to convert each subproblem into an Error object.

I'd also change this to an Optional[Tuple['Error', ...]] to match some the other attributes like this in this file. Many of them define their type as a list, however, they're actually tuples which is kind of nice since they're immutable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done - I copied the decoder for Order.identifiers as suggested and added a test to ensure subproblems are constructed when using from_json.

Comment thread acme/acme/messages.py Outdated
return None

@property
def codes(self) -> Optional[List[str]]:

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.

While this property was initially my idea, I'd actually prefer we leave it out for now since we have no immediate use for it. When/if we have one, we can add it.

@JamesBalazs JamesBalazs Apr 4, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure - done 🙂

I was testing out retrying without the failed domains in another branch based on this one, and codes was useful there for cleanly checking for a CAA error. But it should definitely be added when/where it is used, not in this PR.

Comment thread acme/acme/messages.py Outdated
if part is not None).decode()

if self.identifier:
result += f' :: {self.identifier}'

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.

Playing with this PR a bit based on cpu's comment here, what do you think about instead of adding the identifier like this, we did something like prepended result with something like the following if self.identifier is set:

Problem for {self.identifier.value}: 

I think this makes the output of the sub-problem list even clearer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That seems nicer. I've changed this to prepend results with Problem for {self.identifier.value}: if self.identifier is present, and removed the Sub-problems: line above them so the output would be e.g.:

 acme.messages.Error: urn:ietf:params:acme:error:caa :: Certification Authority Authorization (CAA) records forbid the CA from issuing a certificate :: Error finalizing order :: Rechecking CAA for "xxxxx.xxxx.xx" and 1 more identifiers failed. Refer to sub-problems for more information
Problem for [first identifier value]: [string representation of first sub-problem]
Problem for [second identifier value]: [string representation of second sub-problem]

Hopefully that's more like what you intended.

Comment thread acme/acme/messages.py Outdated
return b' :: '.join(
subproblems = []
if self.subproblems is not None:
subproblems = self.subproblems

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.

This is a nitpick, but rather than doing this, I'd just use and check self.subproblems below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was originally added to silence an error in tox -e lint when iterating over self.subproblems, as it could previously be None which is not iterable.

I tried removing this in the latest version, and it seems to work fine now though...

Comment thread acme/acme/messages.py Outdated
Comment on lines +243 to +244
def __str__(self) -> str:
return f'{self.typ}={self.value}'

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 think I prefer we leave this out for now and just let it fall back to __repr__. I'm struggling to come with a string I like here and if you implement one of my other suggestions, this will be unused.

Suggested change
def __str__(self) -> str:
return f'{self.typ}={self.value}'

Comment thread acme/acme/messages.py Outdated
Comment on lines +205 to +207
def __str__(self) -> str:
return self.name

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 think this is good, but it'll be unused without code coverage if you implement one of my other suggestions so I think we should probably just delete this.

Suggested change
def __str__(self) -> str:
return self.name
def __str__(self) -> str:
return self.name

Comment thread acme/tests/messages_test.py Outdated
Comment on lines +55 to +61
def test_codes(self):
from acme.messages import Error
self.assertEqual(['malformed'], self.error.codes)
self.assertEqual(['malformed', 'caa'], self.error_with_subproblems.codes)
self.assertIsNone(self.error_custom.codes)
self.assertIsNone(Error().codes)

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.

Thanks for writing this, but if you remove codes for now per my suggestion above, this will need to be deleted.

Suggested change
def test_codes(self):
from acme.messages import Error
self.assertEqual(['malformed'], self.error.codes)
self.assertEqual(['malformed', 'caa'], self.error_with_subproblems.codes)
self.assertIsNone(self.error_custom.codes)
self.assertIsNone(Error().codes)
def test_codes(self):
from acme.messages import Error
self.assertEqual(['malformed'], self.error.codes)
self.assertEqual(['malformed', 'caa'], self.error_with_subproblems.codes)
self.assertIsNone(self.error_custom.codes)
self.assertIsNone(Error().codes)

Comment thread acme/tests/messages_test.py Outdated
str(self.error_with_subproblems),
(u"{0.typ} :: {0.description} :: {0.detail} :: {0.title}\n"+
"Sub-problems:\n"+
u"{1.typ} :: {1.description} :: {1.detail} :: {1.title} :: {1.identifier}").format(

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.

Reminder that this will need to be tweaked if we implement my suggested change to the output.

Comment thread certbot/CHANGELOG.md Outdated

### Added

* Added RFC8555 subproblems to ACME errors

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 just want to adjust this slightly.

Suggested change
* Added RFC8555 subproblems to ACME errors
* Added support for RFC8555 subproblems to our acme library.

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

Just to surface one more thing which appears not to be caught by the tests here.

If I temporarily revert #9255 and try this PR, the subproblem rendering doesn't quite work:

$ sudo -E certbot certonly -d foo.in-addr.arpa -d bar.in-addr.arpa --webroot -w /tmp --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Simulating a certificate request for foo.in-addr.arpa and bar.in-addr.arpa
An unexpected error occurred:
urn:ietf:params:acme:error:rejectedIdentifier :: The server will not issue certificates for the identifier :: Error creating new order :: Cannot issue for "bar.in-addr.arpa": The ACME server refuses to issue a certificate for this domain name, because it is forbidden by policy (and 1 more problems. Refer to sub-problems for more information.)
Sub-problems:
frozendict(detail='Error creating new order :: The ACME server refuses to issue a certificate for this domain name, because it is forbidden by policy', identifier=frozendict(type='dns', value='bar.in-addr.arpa'), status=400, type='urn:ietf:params:acme:error:rejectedIdentifier')
frozendict(detail='Error creating new order :: The ACME server refuses to issue a certificate for this domain name, because it is forbidden by policy', identifier=frozendict(type='dns', value='foo.in-addr.arpa'), status=400, type='urn:ietf:params:acme:error:rejectedIdentifier')
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

@bmw

bmw commented Apr 1, 2022

Copy link
Copy Markdown
Member

Thanks for flagging that. I think this should be fixed by #9258 (comment) and #9258 (comment), but we should double check before merging this.

Comment thread acme/acme/messages.py Resolved
@JamesBalazs
JamesBalazs requested a review from bmw April 4, 2022 10:53
@bmw

bmw commented Apr 5, 2022

Copy link
Copy Markdown
Member

This looks good to me. The output now in the example Alex and I have been using is:

acme.messages.Error: urn:ietf:params:acme:error:rejectedIdentifier :: The server will not issue certificates for the identifier :: Error creating new order :: Cannot issue for "between-addr.in-addr.arpa": The ACME server refuses to issue a certificate for this domain name, because it is forbidden by policy (and 1 more problems. Refer to sub-problems for more information.)
Problem for between-addr.in-addr.arpa: urn:ietf:params:acme:error:rejectedIdentifier :: The server will not issue certificates for the identifier :: Error creating new order :: The ACME server refuses to issue a certificate for this domain name, because it is forbidden by policy
Problem for out-addr.in-addr.arpa: urn:ietf:params:acme:error:rejectedIdentifier :: The server will not issue certificates for the identifier :: Error creating new order :: The ACME server refuses to issue a certificate for this domain name, because it is forbidden by policy

I'm in the middle of doing a release, but once that's done and merged into master, we can resolve the changelog merge conflicts that will arise and merge this PR too.

Thanks again JamesBalazs.

@bmw

bmw commented Apr 6, 2022

Copy link
Copy Markdown
Member

@JamesBalazs, if you can merge master into this branch and move the changelog entry you added to the new 1.27.0 section I created here, I'll merge this.

@JamesBalazs

Copy link
Copy Markdown
Contributor Author

@bmw I've merged in master and moved the changelog entry now 🙂

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

Then it's time to merge!

@bmw
bmw merged commit 0fb5094 into certbot:master Apr 6, 2022
@JamesBalazs

Copy link
Copy Markdown
Contributor Author

Thanks for all the help with this @alexzorin and @bmw!

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.

3 participants