Security: add create api key transport action#34572
Security: add create api key transport action#34572jaymode merged 29 commits intoelastic:security_api_keysfrom
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
tvernum
left a comment
There was a problem hiding this comment.
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.
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?
...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.
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.
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
| private static final Logger logger = LogManager.getLogger(ApiKeyService.class); | ||
| 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.
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
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: |
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