Skip to content

Allow kibana_system to create and invalidate API keys on behalf of other users#53824

Merged
peterschretlen merged 2 commits intoelastic:masterfrom
peterschretlen:kibana-system-api-keys
Mar 23, 2020
Merged

Allow kibana_system to create and invalidate API keys on behalf of other users#53824
peterschretlen merged 2 commits intoelastic:masterfrom
peterschretlen:kibana-system-api-keys

Conversation

@peterschretlen
Copy link
Copy Markdown

This change adds the following privileges to the kibana_system role:

This is to support alerting on Kibana, which uses API keys to run scheduled background alert checks on a user's behalf as described in #48716 (comment)

Related: elastic/kibana#49398

@elasticmachine
Copy link
Copy Markdown
Collaborator

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

@peterschretlen
Copy link
Copy Markdown
Author

Related PR on Kibana side: elastic/kibana#60423

@peterschretlen
Copy link
Copy Markdown
Author

peterschretlen commented Mar 19, 2020

Tested locally to confirm the roles are added and working as expected.

kibana_system role includes grant_api_key and api_key/invalidate

$ curl -k -s -u elastic:changeme https://localhost:9200/_security/role/kibana_system | jq .kibana_system.cluster
[
  "monitor",
  "manage_index_templates",
  "cluster:admin/xpack/monitoring/bulk",
  "manage_saml",
  "manage_token",
  "manage_oidc",
  "cluster:admin/xpack/security/api_key/invalidate",   <---- added
  "grant_api_key",                                     <---- added
  "cluster:admin/xpack/security/privilege/builtin/get",
  "delegate_pki",
  "cluster:admin/ilm/get",
  "cluster:admin/ilm/put",
  "cluster:admin/analyze"
]

kibana user has kibana_system role:

 $ curl -k -s -u elastic:changeme  https://localhost:9200/_security/user/kibana | jq -c .kibana.roles
["kibana_system"]

kibana user can invalidate API key:

# create key for elastic user
$ curl -k -s -u elastic:changeme -H content-type:application/json -d '{ "name":"my-key" }'  https://localhost:9200/_security/api_key | jq .
{
  "id": "IEFY9HABM4_s1PGvY_DW",
  "name": "my-key",
  "api_key": "2VVEhxpRSwqq3PV3clHGZg"
}
# kibana user invalidates key
$ curl -k -s -u kibana:changeme -H content-type:application/json -XDELETE -d '{ "name":"my-key" }' https://localhost:9200/_security/api_key | jq .
{
  "invalidated_api_keys": [
    "IEFY9HABM4_s1PGvY_DW"
  ],
  "previously_invalidated_api_keys": [],
  "error_count": 0
}

kibana user can grant key:

# kibana grants key for elastic user
$ curl -k -s -u kibana:changeme -H content-type:application/json -d '{ "grant_type":"password", "username":"elastic", "password":"changeme" }' https://localhost:9200/_security/api_key/grant | jq .
{
  "id": "HEFi9HABM4_s1PGvv_GA",
  "name": null,
  "api_key": "1XI-g2IWRseli9E3G3yazg"
}

# list keys for elastic user
$ curl -k -s -u elastic:changeme https://localhost:9200/_security/api_key?username=elastic | jq .
{
  "api_keys": [
    {
      "id": "HEFi9HABM4_s1PGvv_GA",
      "name": null,
      "creation": 1584648077171,
      "invalidated": false,
      "username": "elastic",
      "realm": "reserved"
    }
  ]
}

@peterschretlen peterschretlen marked this pull request as ready for review March 19, 2020 20:09
@peterschretlen peterschretlen requested a review from a team March 19, 2020 20:10
@peterschretlen peterschretlen requested a review from legrego March 20, 2020 19:37
Copy link
Copy Markdown
Member

@legrego legrego left a comment

Choose a reason for hiding this comment

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

Thanks Peter! The additional privileges look good to me. Can we also update the existing test to ensure the kibana_system role can perform these actions?

@peterschretlen peterschretlen requested review from albertzaharovits, legrego and tvernum and removed request for a team March 21, 2020 15:56
@tvernum
Copy link
Copy Markdown
Contributor

tvernum commented Mar 23, 2020

Thanks @peterschretlen I was off sick at the end of last week, and was just about to pick this up when I saw you had done it.

Copy link
Copy Markdown
Contributor

@tvernum tvernum left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants