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 createApiKey support to security plugin #42146

Merged
merged 10 commits into from
Jul 31, 2019

Conversation

mikecote
Copy link
Contributor

@mikecote mikecote commented Jul 29, 2019

In this PR, I'm adding a function to the security plugin that allows to create API Keys in Elasticsearch.

Creating API keys is required for alerting in order to execute requests on behalf of the user at a future time.

Resolves #39412

@mikecote mikecote added Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.4.0 labels Jul 29, 2019
@mikecote mikecote self-assigned this Jul 29, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security

@mikecote
Copy link
Contributor Author

Will re-writing this code in new platform

@elasticmachine

This comment has been minimized.

@mikecote mikecote marked this pull request as ready for review July 30, 2019 12:49
@mikecote mikecote requested a review from a team as a code owner July 30, 2019 12:49
@elasticmachine

This comment has been minimized.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@kobelb kobelb left a comment

Choose a reason for hiding this comment

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

Since @azasypkin was the one who migrated authentication to the NP and added the test coverage I'd like to get his opinion on this as well. This is a pedantic nitpick, but the way the tests are written right now we end up "duplicating" certain tests in x-pack/plugins/security/server/authentication/api_key.test.ts and x-pack/plugins/security/server/authentication/index.test.ts. I'm torn on what, if anything, we should change.

@kobelb kobelb requested a review from azasypkin July 30, 2019 20:41
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

Looks good! Just left a few questions/notes/nits

if (isSecurityFeatureDisabled()) {
return null;
}
return await callCluster('shield.createApiKey', { body });
Copy link
Member

Choose a reason for hiding this comment

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

nit: it'd be great if we can at least debug-log here whenever new API key is requested. Later, it feels, we'll need to issue an audit log event here as well.... (ping @kobelb).

All in all it seems we'll end up with a APIKeys.create/invalidate/retrieve/* class here that can accept logger/auditLogger/clusterClient/isSecurityFeatureDisabled at the initialization (constructor) stage :) Having said that I'm totally fine to keep it as is right now if you're not up to this kind of generalization at this stage.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the time being, I think we can ignore the audit logging here... We only have to write entries to the Kibana audit log when we're performing authentication/authorization ourselves in Kibana and can't defer to the Elasticsearch audit log. At least, that's been the current thinking, which is entirely up for debate once we start to focus more on audit logging.

Copy link
Member

Choose a reason for hiding this comment

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

We only have to write entries to the Kibana audit log when we're performing authentication/authorization ourselves in Kibana and can't defer to the Elasticsearch audit log.

Right, good point, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should the comment stay for now or be removed?

@kobelb
Copy link
Contributor

kobelb commented Jul 31, 2019

nit: can you please leave a comment here explaining that user needs manage_api_key cluster privilege to use this API? Just for future reference.

This is just a temporary restriction, right? Otherwise, aren't we going to end up restricting which users are able to create alerts?

@elasticmachine

This comment has been minimized.

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

LGTM, just a few more super-minor nits, thanks!

@mikecote
Copy link
Contributor Author

retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mikecote mikecote merged commit 011c04f into elastic:master Jul 31, 2019
mikecote added a commit to mikecote/kibana that referenced this pull request Jul 31, 2019
* Add createApiKey support to security plugin

* Expiration is optional

* Start moving code to new platform

* Add unit tests

* Fix jest test

* Apply PR feedback

* Apply PR feedback

* Apply PR feedback pt2
mikecote added a commit that referenced this pull request Jul 31, 2019
* Add createApiKey support to security plugin

* Expiration is optional

* Start moving code to new platform

* Add unit tests

* Fix jest test

* Apply PR feedback

* Apply PR feedback

* Apply PR feedback pt2
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes review Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.4.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Keys for background tasks
4 participants