Skip to content

Conversation

BigPandaToo
Copy link
Contributor

This change adding an abstract RestHandler class and extends it by
enrollment API classes (node and Kibana enrollment). It will handle the
cases when enrollment.enabled is not set to true. It will return an
appropriate exception in this case.

Resolves: #76097

This change adding an abstract RestHandler class and extends it by
enrollment API classes (node and Kibana enrollment). It will handle the
cases when `enrollment.enabled` is not set to `true`. It will return an
appropriate exception in this case.
@BigPandaToo BigPandaToo added >enhancement :Security/Security Security issues without another label v8.0.0 Team:Security Meta label for security team labels Aug 16, 2021
@BigPandaToo BigPandaToo requested a review from jkakavas August 16, 2021 14:40
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

Comment on lines 60 to 64
License.OperationMode licenseMode = randomFrom(License.OperationMode.BASIC, License.OperationMode.TRIAL,
License.OperationMode.PLATINUM, License.OperationMode.ENTERPRISE);
final TestUtils.UpdatableLicenseState licenseState = new TestUtils.UpdatableLicenseState(settings);
licenseState.update(licenseMode, true, Long.MAX_VALUE, null);

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We don't check the licenseState ever in this tests, so you don't necessarily need this, you can use new XPackLicenseState(() -> 0) in your constructor below

if (failedFeature != null) {
return failedFeature;
} else if (XPackSettings.ENROLLMENT_ENABLED.get(settings) == false) {
return new ElasticsearchSecurityException("Enrollment mode is not enabled", RestStatus.FORBIDDEN);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a more actionable message here? Something like "Enrollment mode [" + XPackSettings.ENROLLMENT_ENABLED.getKey() + "] is not enabled" ? WDYT ?

} else if (XPackSettings.ENROLLMENT_ENABLED.get(settings) == false) {
return new ElasticsearchSecurityException("Enrollment mode is not enabled", RestStatus.FORBIDDEN);
return new ElasticsearchSecurityException("Enrollment mode [" + XPackSettings.ENROLLMENT_ENABLED.getKey() + "] is not " +
"configured",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit again: I find "not enabled" to be less confusing than "not configured" but I'll leave this up to you. ( It can "be configured" ==> explicitly set to false and we'd need to throw here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think "Enrollment mode [xpack.security.enrollment.enabled] is not enabled" is a bit repetitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

May be "Enrollment mode [xpack.security.enrollment.enabled] is not true"? Or not set?

Copy link
Contributor

Choose a reason for hiding this comment

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

"not set" has the same problem with "not configured" , it can be set, to false and we'd still throw. The confusion comes from having a single sentence that has

  • The "Enrollment mode" , which can be enabled or disabled
  • The xpack.security.enrollment.enabled which can be set to true or false.

We can either

  • revert to a more generic message like you had it originally "Enrollment mode is not enabled" or
  • expand a bit to "Enrollment mode is not enabled. Set [" + XPackSettings.ENROLLMENT_ENABLED.getKey() + "] to true, in order to use this API."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the last one!

@BigPandaToo
Copy link
Contributor Author

@elasticmachine update branch

@BigPandaToo
Copy link
Contributor Author

@elasticmachine update branch

@BigPandaToo
Copy link
Contributor Author

@elasticmachine update branch

@BigPandaToo
Copy link
Contributor Author

@elasticmachine update branch

@BigPandaToo BigPandaToo merged commit 207f783 into elastic:master Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Security/Security Security issues without another label Team:Security Meta label for security team v8.0.0-alpha2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an abstract RestHandler class for Enrollment APIs
4 participants