Remove combo security and license helper from license state#55366
Remove combo security and license helper from license state#55366rjernst merged 5 commits intoelastic:masterfrom
Conversation
Security features in the license state currently do a dynamic check on whether security is enabled. This is because the license level can change the default security enabled state. This commit splits out the check on security being enabled, so that the combo method of security enabled plus license allowed is no longer necessary.
|
Pinging @elastic/es-security (:Security/License) |
|
Note that I have intentionally not added new uses of the "copy license state" method. I think that method is making the code more convoluted, and not actually fully protecting from race conditions because several different services within a request may check the license state, yet that method only copies within a single method. We should instead completely rework how the license state is frozen within a request once #53909 is complete. |
In the abstract, that concerns me (subject to how long #53909 will take). This behaviour was added to solve real race conditions that affected users. However, I think in most (maybe all) cases here it's fine. The only situation were need to worry about is moving between a license where security is enabled by default (Gold, Platinum, Enterprise) to one where it is not (Trial, Basic), so that the first condition occurs on the old license and the second condition checks the new license. If the security-enabled state doesn't change then there's no race condition between If you move from not-enabled to enabled (install a paid license), then this should be safe because the first condition fails, so the second check is never performed, so there is no issue. Moving from platinum/enterprise to trial should have no effect, because the set of features are identical. Moving from platinum/enterprise to basic could have an effect, because the second check would fail where it would have passed on the first license, but since the basic license would have failed the first check, the overall result is as if the check was performed on a basic license. So the only case that could matter is moving from Gold to Trial. In that case we could have a situation where we detected security-enabled && feature-allowed even though that didn't hold true for either license independently. |
| final AuditTrail auditTrail = auditTrailService.get(); | ||
| if (frozenLicenseState.isSecurityEnabled()) { | ||
| if (frozenLicenseState.isDocumentAndFieldLevelSecurityAllowed()) { | ||
| if (frozenLicenseState.isSecurityEnabled() && frozenLicenseState.isDocumentAndFieldLevelSecurityAllowed()) { |
There was a problem hiding this comment.
The isSecurityEnabled is covered in the enclosing if
| final AuditTrail auditTrail = auditTrailService.get(); | ||
| if (frozenLicenseState.isSecurityEnabled()) { | ||
| if (frozenLicenseState.isDocumentAndFieldLevelSecurityAllowed()) { | ||
| if (frozenLicenseState.isSecurityEnabled() && frozenLicenseState.isDocumentAndFieldLevelSecurityAllowed()) { |
There was a problem hiding this comment.
isSecurityEnabled is covered in the enclosing if
| } | ||
| final Set<RoleDescriptor> effectiveDescriptors; | ||
| if (licenseState.isDocumentAndFieldLevelSecurityAllowed()) { | ||
| if (licenseState.isSecurityEnabled() && licenseState.isDocumentAndFieldLevelSecurityAllowed()) { |
There was a problem hiding this comment.
I think in this context we should ignore isSecurityEnabled()
It's a check to disable roles with DLS/FLS is the license does not permit it. I think it confuses the code to explicitly include enabled in that check.
|
|
||
| private void loadRoleDescriptorsAsync(Set<String> roleNames, ActionListener<RolesRetrievalResult> listener) { | ||
| final RolesRetrievalResult rolesResult = new RolesRetrievalResult(); | ||
| boolean allAllowed = licenseState.isSecurityEnabled() && licenseState.isCustomRoleProvidersAllowed(); |
There was a problem hiding this comment.
As above, I'd skip the enabled check here. It's not clear why we'd prefer one behaviour over another if we ended up in deep in this method but security was disabled.
| try { | ||
| List<String> roleSegments = roleSegments(path); | ||
| final boolean flsDlsLicensed = licenseState.isDocumentAndFieldLevelSecurityAllowed(); | ||
| final boolean flsDlsLicensed = licenseState.isSecurityEnabled() && licenseState.isDocumentAndFieldLevelSecurityAllowed(); |
There was a problem hiding this comment.
As above, I'd skip enabled
|
|
||
| public void putRole(final PutRoleRequest request, final RoleDescriptor role, final ActionListener<Boolean> listener) { | ||
| if (licenseState.isDocumentAndFieldLevelSecurityAllowed()) { | ||
| if (licenseState.isSecurityEnabled() && licenseState.isDocumentAndFieldLevelSecurityAllowed()) { |
| // are given in 2.x syntax | ||
| RoleDescriptor roleDescriptor = RoleDescriptor.parse(name, sourceBytes, true, XContentType.JSON); | ||
| if (licenseState.isDocumentAndFieldLevelSecurityAllowed()) { | ||
| if (licenseState.isSecurityEnabled() && licenseState.isDocumentAndFieldLevelSecurityAllowed()) { |
|
Thanks for the thorough review @tvernum! |
…55366) Security features in the license state currently do a dynamic check on whether security is enabled. This is because the license level can change the default security enabled state. This commit splits out the check on security being enabled, so that the combo method of security enabled plus license allowed is no longer necessary.
…55417) Security features in the license state currently do a dynamic check on whether security is enabled. This is because the license level can change the default security enabled state. This commit splits out the check on security being enabled, so that the combo method of security enabled plus license allowed is no longer necessary.
Security features in the license state currently do a dynamic check on
whether security is enabled. This is because the license level can
change the default security enabled state. This commit splits out the
check on security being enabled, so that the combo method of security
enabled plus license allowed is no longer necessary.