Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exception metadata for disabled features #52811

Merged
merged 5 commits into from
Mar 5, 2020

Conversation

tvernum
Copy link
Contributor

@tvernum tvernum commented Feb 26, 2020

This change adds a new exception with consistent metadata for when
security features are not enabled. This allows clients to be able to
tell that an API failed due to a configuration option, and respond
accordingly.

Relates: elastic/kibana#55255
Resolves: #52311, #47759


Sample REST output

{
  "error" : {
    "root_cause" : [
      {
        "type" : "feature_not_enabled_exception",
        "reason" : "security tokens are not enabled",
        "disabled.feature" : "security_tokens"
      }
    ],
    "type" : "feature_not_enabled_exception",
    "reason" : "security tokens are not enabled",
    "disabled.feature" : "security_tokens"
  },
  "status" : 400
}

For now, possible feature names are security_tokens and api_keys

This change adds a new exception with consistent metadata for when
security features are not enabled. This allows clients to be able to
tell that an API failed due to a configuration option, and respond
accordingly.

Relates: kibana#55255
Resolves: elastic#52311
@tvernum tvernum added >enhancement :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) v8.0.0 v7.7.0 labels Feb 26, 2020
@elasticmachine
Copy link
Collaborator

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

@tvernum
Copy link
Contributor Author

tvernum commented Feb 26, 2020

Ping @kobelb

@tvernum
Copy link
Contributor Author

tvernum commented Feb 26, 2020

Ping @cjcenizal

Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

I have some questions around the Feature concept. Please see above (below actually). Thanks.

Comment on lines +20 to +29
public enum Feature {
TOKEN_SERVICE("security_tokens"),
API_KEY_SERVICE("api_keys");

private final String featureName;

Feature(String featureName) {
this.featureName = featureName;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I wonder whether we should give Feature more attention to make it more formalized, because it seems to be an useful concept for other places as well. By formalization, I mean something like, have it in a separate class, place it in a shared package which is more accessible, name each feature more consistently (more on this below).

Including Feature, we now have three different but related concepts: Feature, Setting, Plugin. Plugin seems to be the highest level, in that it provides one or multiple Features and Settings. I am not sure whether Feature has an 1-to-1 relationship with a Setting. If so, I feel the associated Setting should be reflected in this class and this could be useful for users to act accordingly.

If the relationship between Feature and Setting is more complex, e.g. a feature corresponds to multiple Settings working together, it may need to be more carefully defined and promoted to be a first level concept. I am a bit surprised that Feature is not already an existing concept since both Setting and Plugin sound too technical when talking to users, while Feature seem to be a more accessible term.

I am aware that it is not something inherent to this PR so we don't need to solve it all with this PR. One possible actionable item is to move this class to a more common package for reuse by places other than security.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, no, maybe...

We do have "feature" concepts throughout the codebase. The obvious example being isXyzzyAllowed() on XPackLicenseState. Those are, roughly speaking, features.

I can imagine a world when we had strong model of "Feature" and the license checks where all isFeatureAllowed(Feature feature), and elsewhere isFeatureEnabled(Feature), but we don't and I don't think anyone wants to.

The reason I added an enum here is

  1. So that the feature names were static & defined in a single place, so that clients could rely on the names being a well defined set (at least, per version).
  2. I could have solved that with constant Strings, but then the exception constructor would have been (String, String, Object ...) and there would be ambiguity about which String was the feature name and which was the message.

I think there's something to your suggestion, but progress over perfection - to me, this is a straight forward solution to the problem at hand, and we can evolve it into something else in the future if we need.

Copy link
Member

Choose a reason for hiding this comment

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

Enum is good (at least for now). I agree that we don't wanna stall on something that is not in scope of the problem at hand. My actual question is whether we should move this file to a more common module, e.g. the xpack core module for dependency sake, since I can see it being useful for other xpack modules besides security (similar to how license related files are in core).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My personal view, is that it's a false sense of "reuse".
As it stands:

  1. we don't know if this would be useful elsewhere. We can imagine places, but we have no plans to change them
  2. because of (1), we also don't know which enum values would make sense in the future
  3. we do know that future uses of it would be constrained by not being able to change it significantly because they'd risk breaking clients.

Based on the above, I understand the temptation to put it in core, but there's no clear value, and 1 definite limitation, so it seems like something that feels good for reuse purposes, but actually isn't.

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking about using it in the "role template validation" if we chose to issue warning instead of error out. Since we have decided it's ok to error out, I currently have no other idea where it could be re-used. So the current form is ok with me.

Copy link
Contributor

@albertzaharovits albertzaharovits left a comment

Choose a reason for hiding this comment

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

LGTM, sorry for the delay, I missed the notification.

Maybe update the PR description with a sample listing of the exception, it might save clients folks some time:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "feature_not_enabled_exception",
        "reason" : "security tokens are not enabled",
        "disabled.feature" : "security_tokens"
      }
    ],
    "type" : "feature_not_enabled_exception",
    "reason" : "security tokens are not enabled",
    "disabled.feature" : "security_tokens"
  },
  "status" : 400
}

@tvernum tvernum requested a review from ywangd March 5, 2020 04:43
Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

LGTM

@tvernum tvernum merged commit f5ba0f6 into elastic:master Mar 5, 2020
tvernum added a commit to tvernum/elasticsearch that referenced this pull request Mar 23, 2020
This change adds a new exception with consistent metadata for when
security features are not enabled. This allows clients to be able to
tell that an API failed due to a configuration option, and respond
accordingly.

Relates: kibana#55255
Resolves: elastic#52311, elastic#47759

Backport of: elastic#52811
tvernum added a commit that referenced this pull request Mar 23, 2020
This change adds a new exception with consistent metadata for when
security features are not enabled. This allows clients to be able to
tell that an API failed due to a configuration option, and respond
accordingly.

Relates: kibana#55255
Resolves: #52311, #47759

Backport of: #52811
@jakelandis jakelandis removed the v8.0.0 label Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) v7.7.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add metadata to exception when ApiKey/Token services are not enabled
5 participants