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

Migrate config deprecations and ShieldUser functionality to the New Platform #53768

Merged
merged 5 commits into from
Jan 6, 2020

Conversation

azasypkin
Copy link
Member

@azasypkin azasypkin commented Dec 23, 2019

There are two changes in this PR (better to review commit by commit):

  • Config deprecation transformations moved to the New Platform plugin
  • ShieldUser is removed and replaced with getCurrentUser exposed by the New Platform plugin setup contract (unified with the same API on server side).

Dev Docs [Security Plugin]

Legacy ShieldUser angular service has been removed and replaced with the dedicated method on the Kibana platform plugin setup contract:

Before:

const currentUser = await $injector.get('ShieldUser').getCurrent().$promise;

Now:

Legacy plugin:

import { npSetup } from 'ui/new_platform';
const currentUser = await npSetup.plugins.security.authc.getCurrentUser();

Kibana platform plugin:

// manifest.json
....
[optional]requiredPlugins: ["security"],
....
// my_plugin/public/plugin.ts
public setup(core: CoreSetup, { security }: PluginSetupDependencies) {
    const currentUser = await security.authc.getCurrentUser();
}

@azasypkin azasypkin added chore Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! Feature:NP Migration labels Dec 23, 2019
@azasypkin azasypkin requested a review from a team as a code owner December 23, 2019 14:46
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

@azasypkin azasypkin added release_note:skip Skip the PR/issue when compiling release notes v7.6.0 release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. and removed release_note:skip Skip the PR/issue when compiling release notes labels Dec 23, 2019
});

return {
anonymousPaths,
Copy link
Member Author

Choose a reason for hiding this comment

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

note: I can't think of any reason why we'd want to re-expose part of the core's own contract.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also took a look and I agree, seems unnecessary

@@ -11,6 +11,8 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { UIRoutes } from 'ui/routes';
import { isLeft } from 'fp-ts/lib/Either';
import { npSetup } from 'ui/new_platform';
Copy link
Member Author

Choose a reason for hiding this comment

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

@mattapperson, I'm not sure why Beats team wasn't pinged by the GitHub automatically, but I see you were editing this file before, would you mind reviewing this single change in beats_management plugin?

Copy link
Contributor

Choose a reason for hiding this comment

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

Pulling and checking now

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey @mattapperson, did you have chance to take a look at this change?

@kibanamachine
Copy link
Contributor

💔 Build Failed

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jportner
Copy link
Contributor

jportner commented Jan 2, 2020

Reviewing now!

Copy link
Contributor

@jportner jportner left a comment

Choose a reason for hiding this comment

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

Good stuff. Found one problem, and had one nit.

session: Joi.object({
idleTimeout: HANDLED_IN_NEW_PLATFORM,
lifespan: HANDLED_IN_NEW_PLATFORM,
}).default(),
session: HANDLED_IN_NEW_PLATFORM,
Copy link
Contributor

Choose a reason for hiding this comment

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

👏

legacyFallback: Joi.object({
enabled: Joi.boolean().default(true), // deprecated
}).default(),
}).default(),
audit: Joi.object({
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
audit: Joi.object({
authorization: HANDLED_IN_NEW_PLATFORM,
audit: Joi.object({

Need to specify this in the legacy plugin config, otherwise Kibana will crash if you have specified xpack.security.authorization.legacyFallback.enabled:

server    log   [12:52:10.787] [fatal][root] { ValidationError: child "xpack" fails because [child "security" fails because ["authorization" is not allowed]]
    at Object.exports.process (/Users/joe/GitHub/kibana/node_modules/joi/lib/errors.js:196:19)
    at internals.Object._validateWithOptions (/Users/joe/GitHub/kibana/node_modules/joi/lib/types/any/index.js:675:31)
    at module.exports.internals.Any.validate (/Users/joe/GitHub/kibana/node_modules/joi/lib/index.js:146:23)
    at Config._commit (/Users/joe/GitHub/kibana/src/legacy/server/config/config.js:124:25)
    at Config.set (/Users/joe/GitHub/kibana/src/legacy/server/config/config.js:89:10)
    at Config.extendSchema (/Users/joe/GitHub/kibana/src/legacy/server/config/config.js:62:10)
    at extendConfigService (/Users/joe/GitHub/kibana/src/legacy/plugin_discovery/plugin_config/extend_config_service.js:36:10) name: 'ValidationError' }

 FATAL  ValidationError: child "xpack" fails because [child "security" fails because ["authorization" is not allowed]]

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, good catch, I could swear it worked when I tested it at the early stages of this PR 🙈 There is a chance I'm making this up though, let me check.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to check if it's indented behavior (that NP passes non-transformed config to the LP), but Platform team is out this week. Will just use your suggestion to not be blocked!

Comment on lines -134 to -137
await Promise.resolve();
await Promise.resolve();
await Promise.resolve();
await Promise.resolve();
Copy link
Contributor

Choose a reason for hiding this comment

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

😱

});

return {
anonymousPaths,
Copy link
Contributor

Choose a reason for hiding this comment

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

I also took a look and I agree, seems unnecessary

Comment on lines 15 to 18
interface SetupDeps {
securityLicense: SecurityLicense;
getCurrentUser: AuthenticationServiceSetup['getCurrentUser'];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just curious, is there any particular reason you decided to use such a specific contract?

My 2 cents is that it would have sufficed to just use AuthenticationServiceSetup as a parameter -- less verbose that way, and less TypeScript jargon / easier to understand for new developers.
I noticed that SecurityLicense is also more generic (e.g., we don't specify SecurityLicense['feature$'] here, even though we could).

Copy link
Member Author

@azasypkin azasypkin Jan 3, 2020

Choose a reason for hiding this comment

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

I'm asking myself the same question in my next PR that is based on this one - and I totally agree that it looks weird and unnecessary. Can't recall why I did this, must be I'll think about it later, but never get back to it.... kind of thing 🙈 I'll fix it, thanks!

export class SessionTimeout {
export class SessionTimeout implements ISessionTimeout {
Copy link
Contributor

Choose a reason for hiding this comment

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

🤦‍♂

Copy link
Member Author

Choose a reason for hiding this comment

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

Haha, not a big deal though - I've heard platform will be abandoning I{interface_name} convention soon (with TS 3.8 upgrade) since we used it mostly to workaround the absence of proper "private fields" support and with TS 3.8 it'd not make too much sense to create a dedicated interface if it completely replicates public part of the class definition.

@azasypkin
Copy link
Member Author

@jportner thanks for review, PR is ready for another pass!

Copy link
Contributor

@jportner jportner left a comment

Choose a reason for hiding this comment

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

LGTM!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@azasypkin
Copy link
Member Author

@mattapperson I'm going to move forward and merge this PR now to unblock other migration work we have. I've tested affected pieces in Beats CM and Logstash Pipelines and everything seems to be in order, but feel free to reach out to me if you have any concerns!

@azasypkin azasypkin merged commit aa38fb6 into elastic:master Jan 6, 2020
@azasypkin azasypkin deleted the issue-xxx-np-security branch January 6, 2020 10:43
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jan 6, 2020
* master:
  adds strict types to Alerting Client (elastic#53821)
  [Dashboard] Empty screen redesign (elastic#53681)
  Migrate config deprecations and `ShieldUser` functionality to the New Platform (elastic#53768)
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jan 6, 2020
…nsole-dependencies

* 'master' of github.com:elastic/kibana: (33 commits)
  adds strict types to Alerting Client (elastic#53821)
  [Dashboard] Empty screen redesign (elastic#53681)
  Migrate config deprecations and `ShieldUser` functionality to the New Platform (elastic#53768)
  increase delay to make sure license refetched (elastic#53882)
  Allow custom NP plugin paths in production (elastic#53562)
  [Maps] show custom color ramps in legend (elastic#53780)
  [Lens] Expression type on document can be null (elastic#53883)
  [SIEM] [Detection engine] Add user permission to detection engine (elastic#53778)
  Update dependency @elastic/charts to v16.0.2 (elastic#52619)
  Set consistent EOL symbol in core API docs (elastic#53815)
  [Logs UI] Refactor query bar state to hooks (elastic#52656)
  [Maps] pass getFieldFormatter to DynamicTextProperty (elastic#53937)
  Invalidate alert API Key when generating a new one (elastic#53732)
  [Logs UI] HTTP API for log entries (elastic#53798)
  [kbn/pm] add caching to bootstrap (elastic#53622)
  adds createdAt and updatedAt fields to alerting (elastic#53793)
  [SR] Enable component integration tests (elastic#53893)
  Move index patterns: src/legacy/core_plugins/data 👉 src/plugins/data (elastic#53794)
  moved Task Manager server code under "server" directory (elastic#53777)
  Rename `/api/security/oidc` to `/api/security/oidc/callback`. (elastic#53886)
  ...

# Conflicts:
#	yarn.lock
@azasypkin
Copy link
Member Author

7.x/7.6.0: 12f4761

gmmorris added a commit to gmmorris/kibana that referenced this pull request Jan 6, 2020
* master:
  allows Alerts to recover gracefully from Executor errors (elastic#53688)
  [Console] Fix OSS build (elastic#53885)
  migrate xsrf / version-check / custom-headers handlers to NP (elastic#53684)
  use NP deprecations in uiSettings (elastic#53755)
  adds strict types to Alerting Client (elastic#53821)
  [Dashboard] Empty screen redesign (elastic#53681)
  Migrate config deprecations and `ShieldUser` functionality to the New Platform (elastic#53768)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported chore Feature:NP Migration release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants