Repository navigation
Add subproblems to errors (#7046) - #9258
Conversation
bmw
left a comment
There was a problem hiding this comment.
I made a number of small suggestions, but at a high level I think this looks good. Thanks a lot for picking this up.
| 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) |
There was a problem hiding this comment.
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.
| identifier: Optional['Identifier'] = jose.field('identifier', omitempty=True) | |
| identifier: Optional['Identifier'] = jose.field('identifier', decoder=Identifier.from_json, omitempty=True) |
There was a problem hiding this comment.
Done - thanks, I wasn't aware this wouldn't be parsed correctly without setting a decoder
| 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Done - I copied the decoder for Order.identifiers as suggested and added a test to ensure subproblems are constructed when using from_json.
| return None | ||
|
|
||
| @property | ||
| def codes(self) -> Optional[List[str]]: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| if part is not None).decode() | ||
|
|
||
| if self.identifier: | ||
| result += f' :: {self.identifier}' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| return b' :: '.join( | ||
| subproblems = [] | ||
| if self.subproblems is not None: | ||
| subproblems = self.subproblems |
There was a problem hiding this comment.
This is a nitpick, but rather than doing this, I'd just use and check self.subproblems below.
There was a problem hiding this comment.
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...
| def __str__(self) -> str: | ||
| return f'{self.typ}={self.value}' |
There was a problem hiding this comment.
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.
| def __str__(self) -> str: | |
| return f'{self.typ}={self.value}' |
| def __str__(self) -> str: | ||
| return self.name | ||
|
|
There was a problem hiding this comment.
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.
| def __str__(self) -> str: | |
| return self.name | |
| def __str__(self) -> str: | |
| return self.name | |
| 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) | ||
|
|
There was a problem hiding this comment.
Thanks for writing this, but if you remove codes for now per my suggestion above, this will need to be deleted.
| 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) | |
| 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( |
There was a problem hiding this comment.
Reminder that this will need to be tweaked if we implement my suggested change to the output.
|
|
||
| ### Added | ||
|
|
||
| * Added RFC8555 subproblems to ACME errors |
There was a problem hiding this comment.
I just want to adjust this slightly.
| * Added RFC8555 subproblems to ACME errors | |
| * Added support for RFC8555 subproblems to our acme library. |
alexzorin
left a comment
There was a problem hiding this comment.
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.
|
Thanks for flagging that. I think this should be fixed by #9258 (comment) and #9258 (comment), but we should double check before merging this. |
…lems / identifiers
|
This looks good to me. The output now in the example Alex and I have been using is: I'm in the middle of doing a release, but once that's done and merged into Thanks again JamesBalazs. |
|
@JamesBalazs, if you can merge |
|
@bmw I've merged in |
|
Thanks for all the help with this @alexzorin and @bmw! |
Added an optional
subproblemsfield toacme.messages.Errorand a propertycodesthat returns a list of codes for the error, as suggested by @bmw in #7046Errors now also have an optional
Identifierwhich should only be populated for subproblems as in RFC8555 6.7To 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:The
Identifieris tacked onto the end of the subproblems string representation, when present, and itself is represented as{type}={value}.Pull Request Checklist
mastersection ofcertbot/CHANGELOG.mdto include a description of the change being made.AUTHORS.mdif you like.