Skip to content

Long lived api keys/tokens #34383

Closed
@jaymode

Description

@jaymode

The security codebase already supports the use of access tokens for
interactive access. These tokens are based on the OAuth2 spec; there is
a short-lived access token and a refresh token with a lifetime of 24 hours.
These tokens are not suitable for Hadoop jobs or recurring scheduled tasks.

Hadoop jobs typically require a token that may need to be refreshed but
the token needs to remain the same after refresh; our current tokens
always generate a new access and refresh token upon refresh. Another
pattern of Hadoop jobs is that once they are complete the tokens are
not invalidated but instead rely on a expiration time of something like
a week.

The security tokens are not a fit for recurring/scheduled jobs as they
can only be refreshed for 24 hours. If the system that would refresh the
token is down for greater than 24 hours, which could be possible over a
weekend or holiday, the jobs would require updating to function again.

After discussion, we've settled upon adding long lived tokens that would
be akin to API tokens. The properties of these tokens are as follows:

  • Tokens will store the authentication information of the user that
    created them
  • By default, tokens have no expiration. A cluster level setting will
    be available to specify a maximum lifetime
  • When creating a token, a maximum lifetime can be specified for cases
    where the token is expected to stop working after a certain amount of
    time

In terms of APIs, we will be adding:

Create a token with optional expiration, which is a TimeValue.

POST /_security/token
{
  "expiration": "7d"
}

List security tokens. Optionally restrict by username and/or realm.

GET /_security/token
{
  "username": "john.doe",
  "realm": "ldap1"
}

List specific token

GET /_security/token/<token>

Remove a token.

DELETE /_security/token/<token>

In order to use these tokens, they will be passed over HTTP using the
Authorization header. The value must be prefixed with Bearer .

In order to use this token, security must take the value and find the
document with this id. If the document does not exist or the search fails,
the token may not be used. Once security has retrieved a document with
this ID, it must make sure to verify the token has not expired.

Invalidation or a removal of a token should remove the token document
from the security index.

Tokens must store enough information to re-build authentication and
support determining if the token has expired.

Future considerations:

  • The ability to limit the scope of a token
  • keep track of last used time

Metadata

Metadata

Labels

:Security/AuthenticationLogging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc)>feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions