Fix X509AuthenticationToken principal#43932
Conversation
|
Pinging @elastic/es-security |
bizybot
left a comment
There was a problem hiding this comment.
LGTM, after addressing the comments. Thank you.
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/pki/PkiRealm.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/pki/PkiRealm.java
Outdated
Show resolved
Hide resolved
|
Thanks a lot @bizybot for the fast review here as well! |
|
I understand the rationale for this, but it risks being a breaking change (audit events rely on the The behaviour is certainly wrong (in the sense that are some configurations that won't work even though they should), but did you evaluate the impact against the benefit? |
The principal in the audit log is wrong, as it could be parsed by any other installed PKIRealm, and not the one doing the actual authentication. This is a manifestation of the bug. I don't think we should wait for someone to complain about it to fix this.
When making the code changes I have followed where the |
|
The most common scenario for PKI is a single realm. (*) Because in their case there is only a single This bug only manifests if you have 2 PKI realms, with different That's a scenario that we imply will work (because the settings allow it, and the docs don't call it out as unsupported) but I doubt we've ever had a single person run into it, and I can't imagine why anyone would (or at least if they did, why they couldn't fix it by tweaking their 1st pattern to be more strict/precise). We know that our token extraction process is flawed, and I see this issue as a manifestation of that. But this feels like we're working around that problem (again) rather than fixing it, while at the same time potentially breaking the audit behaviour for existing installs. I'm not saying No, I'm just saying Why make this trade-off right now?. |
Actually, I just realised that the BWC issue could be worse than that, although it is unlikely to be a problem in practice. The proposed behaviour would cause the PKI realm to create a token, but then fail to authenticate because the principal cannot be extracted from the DN. One solution would be to continue to parse the We clearly need to fix the |
The
There are other scenarios. For example, both realms could have the same trust certificates, but different principal parsing rules, where patterns could be for different
A "proper" fix must go in a major release. But this should not preclude a fix in the 7.x releases. As detailed above, in my opinion, we have to weigh the breaking of the authn-failed audit entries (which are not correlat-able to other events) against the broken state of multiple PKIRealms with different principal parsing rules. As another example, to accentuate the severity of the issue, suppose you have two PKIRealms with different truststores and different CN parsing rules. There are circumstances in which a given certificate that SHOULD NOT be allowed access IS authenticated because of the disconnection of the DN parsing to chain validation (if you wish, add to that role mapping rules by realm name). If someone where to report this, they would be using secure@ for sure. Of course this can all be discounted, by saying This came up, during the implementation of the PKI delegation, because there the first pass of the authentication process of first building the |
Good catch! Though this implies that the client uses multiple authn methods for the same request which is not supported so we should not worry about breaking anything there. |
Why is that not supported? |
Yes, we support client certificates alongside other authentication schemes. I was talking generally, that we don't support two authentication schemes such that if one fails try the other one, apart from the client certificates, which I assumed that it was a coincidence. Judging from your response, it might not have been a coincidence, but it's certainly not a feature we document. |
e1eac50 to
6f4f11f
Compare
|
Me and Tim discussed on another channel about the BWC implications, and we concurred that there was an easy way to avoid unnecessary breaking changes.
The PR as a whole fixes the bug where the principal could be parsed by a different realm than the one completing the authentication (doing cert chain validation) leading to a score of bugs in complicated setups. Given that the changes effectively reparse and override the principal, AFTER the PKI authentication completed successfully, any "breaking" behavior, in any realm configuration, experienced by users is a fix for a bug, therefore this is not a breaking change but a bug fix. @tvernum May you please keep me honest on this and re-review the PR? |
tvernum
left a comment
There was a problem hiding this comment.
Thanks @albertzaharovits.
LGTM, but I had a couple of small suggestions.
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/pki/PkiRealm.java
Outdated
Show resolved
Hide resolved
| final String principal = getPrincipalFromSubjectDN(principalPattern, token, logger); | ||
| if (principal == null) { | ||
| listener.onResponse(AuthenticationResult.unsuccessful("Could not parse principal from Subject DN " + token.dn(), null)); | ||
| } else { |
There was a problem hiding this comment.
I wonder if we want some sort of logging if user.principal() and token.principal() are different.
It might get to noisy to have it as INFO/WARN every time we do a full-authenticate (potentially every 20 minutes, per user) but maybe a DEBUG would help resolve any unexpected behaviours.
There was a problem hiding this comment.
I have pushed b16f889 which adds debug loggers for when the extracted principal after cert chain validation differs (or is null) from before. These will be useful for us when we need to explain some unexpected behavior, but it is difficult to put in a log line what exactly it's happening so the admin can take actions on its own; so I don't even try, the log lines only state the facts.
…ecurity/authc/pki/PkiRealm.java Co-Authored-By: Tim Vernum <tim@adjective.org>
|
@elasticmachine run elasticsearch-ci/default-distro |
|
@elasticmachine run elasticsearch-ci/bwc |
|
@elasticmachine run elasticsearch-ci/2 |
Fixes a bug in the PKI authentication. This manifests when there are multiple PKI realms configured in the chain, with different principal parse patterns. There are a few configuration scenarios where one PKI realm might parse the principal from the Subject DN (according to the `username_pattern` realm setting) but another one might do the truststore validation (according to the truststore.* realm settings). This is caused by the two passes through the realm chain, first to build the authentication token and secondly to authenticate it, and that the X509AuthenticationToken sets the principal during construction.
Fixes a bug in the PKI authentication. This manifests when there are multiple PKI realms configured in the chain, with different principal parse patterns. There are a few configuration scenarios where one PKI realm might parse the principal from the Subject DN (according to the `username_pattern` realm setting) but another one might do the truststore validation (according to the truststore.* realm settings). This is caused by the two passes through the realm chain, first to build the authentication token and secondly to authenticate it, and that the X509AuthenticationToken sets the principal during construction.
Fixes a bug in the PKI authentication where, when multiple PKI realms are configured in the chain, one realm might parse the principal from the subject DN (according to the
username_patternrealm setting) and another one might pass the truststore validation (according totruststore.*settings).This is due to the two passes through the realm chain, first to build the authentication token and second to authenticate it, and that the
X509AuthenticationTokensets the principal during construction.This fix shifts parsing the principal from the token construction to the authorization process.
Relates #43796 #34396