-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Security: add create api key transport action #34572
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
Conversation
In order to support api keys for access to elasticsearch, we need the ability to generate these api keys. A transport action has been added along with the request and response objects that allow for the generation of api keys. The api keys require a name and optionally allow a role to be specified which defines the amount of access the key has. Additionally an expiration may also be provided. This change does not include the restriction that the role needs to be a subset of the user's permissions, which will be added seperately. As it exists in this change, the api key is currently not usable which is another aspect that will come later. Relates elastic#34383
Pinging @elastic/es-security |
...gin/core/src/main/java/org/elasticsearch/xpack/core/security/action/CreateApiKeyRequest.java
Outdated
Show resolved
Hide resolved
...in/core/src/main/java/org/elasticsearch/xpack/core/security/action/CreateApiKeyResponse.java
Show resolved
Hide resolved
...e/src/test/java/org/elasticsearch/xpack/core/security/action/CreateApiKeyRespoonseTests.java
Outdated
Show resolved
Hide resolved
...urity/src/main/java/org/elasticsearch/xpack/security/action/TransportCreateApiKeyAction.java
Show resolved
Hide resolved
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/TokenService.java
Outdated
Show resolved
Hide resolved
...security/src/main/java/org/elasticsearch/xpack/security/authz/store/CompositeRolesStore.java
Outdated
Show resolved
Hide resolved
...gin/core/src/main/java/org/elasticsearch/xpack/core/security/action/CreateApiKeyRequest.java
Outdated
Show resolved
Hide resolved
...in/core/src/main/java/org/elasticsearch/xpack/core/security/action/CreateApiKeyResponse.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java
Outdated
Show resolved
Hide resolved
...urity/src/main/java/org/elasticsearch/xpack/security/rest/action/RestCreateApiKeyAction.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's 1 issue about still indexing the api key.
The other comments are suggestions that you can take or leave as you wish.
validationException = addValidationError("name is required", validationException); | ||
} else if (name.length() > 256) { | ||
validationException = addValidationError("name may not be more than 256 characters long", validationException); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have any other restrictions on names?
I feel like starting or ending in whitespace is likely to cause confusion, and perhaps we should reserve names start with _
just in case we need them in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added those restrictions
...in/core/src/main/java/org/elasticsearch/xpack/core/security/action/CreateApiKeyResponse.java
Outdated
Show resolved
Hide resolved
...urity/src/main/java/org/elasticsearch/xpack/security/action/TransportCreateApiKeyAction.java
Show resolved
Hide resolved
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java
Outdated
Show resolved
Hide resolved
.field("principal", authentication.getUser().principal()) | ||
.field("metadata", authentication.getUser().metadata()) | ||
.field("realm", authentication.getLookedUpBy() == null ? | ||
authentication.getAuthenticatedBy().getName() : authentication.getLookedUpBy().getName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it depends on how this gets used in the future, but we may need to think about how we deal with realm names, and their potential to change over time.
In particular, out-of-the-box we have "default_file" and "default_native", but once someone adds another realm (e.g. LDAP), they tend to not use "default_native" as the name of their native realm (because we don't tell them to).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason behind storing the realm is based on the invalidation api and being able to invalidate by realm. It really stinks that we don't have a way to enforce realm name consistency between nodes
...k/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ApiKeyIntegTests.java
Show resolved
Hide resolved
...gin/core/src/main/java/org/elasticsearch/xpack/core/security/action/CreateApiKeyRequest.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the iterations !
private static final String TYPE = "doc"; | ||
public static final Setting<String> PASSWORD_HASHING_ALGORITHM = new Setting<>( | ||
"xpack.security.authc.api_key.hashing.algorithm", "pbkdf2", Function.identity(), (v, s) -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit but maybe xpack.security.authc.api_key_hashing.algorithm
makes more sense ( consistent with xpack.security.authc.password_hashing.algorithm
) ? Naming is hard and I don't have strong opinions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I'll be consistent
This is tricky. Maybe we provide an API for an administrator to validate permissions against a set of role names for a given user? We don't keep a record of what a users roles are, so I do not think we can do this automatically unless we have shadow users. Maybe something like:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
In order to support api keys for access to elasticsearch, we need the
ability to generate these api keys. A transport action has been added
along with the request and response objects that allow for the
generation of api keys. The api keys require a name and optionally
allow a role to be specified which defines the amount of access the key
has. Additionally an expiration may also be provided.
This change does not include the restriction that the role needs to be
a subset of the user's permissions, which will be added seperately. As
it exists in this change, the api key is currently not usable which is
another aspect that will come later.
Relates #34383