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 security chromeless views to Kibana Platform plugin #54021

Merged
merged 11 commits into from
Mar 4, 2020

Conversation

azasypkin
Copy link
Member

@azasypkin azasypkin commented Jan 6, 2020

In this PR I migrate everything that's currently possible from the legacy to the platform Kibana Security plugin:

  • Login, Logout, Logged Out, Overwritten Session and Account Management views are migrated
  • All remaining legacy interceptors are moved into a single hack/legacy.ts file
  • Platform plugin config is complete and doesn't allow unknown keys anymore

Note to reviewers: it may be a bit easier to review commit by commit since there is a lot of moves that were done in a separate commit.

Note to myself: be careful when backporting config changes to 7.x (xpack.security.authProviders|public are still there 🙈 )

Blocked by: #53880, #54470, #54472, #58327, #58627

@azasypkin azasypkin added chore blocked Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! release_note:skip Skip the PR/issue when compiling release notes Feature:NP Migration v7.7.0 labels Jan 6, 2020
@elasticmachine
Copy link
Contributor

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

@azasypkin azasypkin removed the blocked label Jan 21, 2020
@azasypkin azasypkin force-pushed the issue-xxx-np-views branch 2 times, most recently from 06b5fab to eb7f32f Compare February 24, 2020 18:08
@azasypkin
Copy link
Member Author

retest

@azasypkin azasypkin marked this pull request as ready for review February 26, 2020 16:08
@azasypkin azasypkin requested review from a team as code owners February 26, 2020 16:08
@@ -0,0 +1,65 @@
/*

This comment was marked as resolved.


const securityPluginSetup = (npSetup.plugins as any).security as SecurityPluginSetup;
if (securityPluginSetup) {
routes.when('/account', {

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.


function interceptorFactory(responseHandler: (response: ng.IHttpResponse<unknown>) => any) {
return function interceptor(response: ng.IHttpResponse<unknown>) {
// TODO: SHOULD WE CHECK THAT IT'S NOT ERROR RESPONSE (&& response.status !== 401)?

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

securityPluginSetup.sessionTimeout.extend(response.config.url);
}

if (response.status !== 401 || isAnonymous) {

This comment was marked as resolved.

import 'plugins/security/services/auto_logout';

function isUnauthorizedResponseAllowed(response) {
const API_WHITELIST = ['/internal/security/login', '/internal/security/users/.*/password'];

This comment was marked as resolved.

@@ -1,33 +0,0 @@
/*

This comment was marked as resolved.

@@ -1,31 +0,0 @@
/*

This comment was marked as resolved.

@@ -1,38 +0,0 @@
/*

This comment was marked as resolved.

title: i18n.translate('xpack.security.account.breadcrumb', {
defaultMessage: 'Account Management',
}),
// TODO: switch to proper enum once https://github.com/elastic/kibana/issues/58327 is resolved.
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: just in case this issue isn't resolved before this PR is reviewed - Jest test tests that our magic number 3 corresponds to the AppNavLinkStatus.hidden

state = { loginState: null };

public async componentDidMount() {
const loadingCount$ = new BehaviorSubject(1);

This comment was marked as resolved.

Uses a single test for the entire page, and more focused tests for
each permutation of BasicLoginForm/DisabledLoginForm. This greatly
reduces the snapshot size.
Also adds tests for API calls.
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.

Finished reviewing code (and added updated LoginPage tests as discussed offline).
I'll try out the functionality now.


// Authentication flow isn't triggered automatically for this route, so we should explicitly
// check whether user has an active session already.
const isUserAlreadyLoggedIn = (await authc.getSessionInfo(request)) != null;

This comment was marked as resolved.

Comment on lines 146 to 151
public stop() {
this.sessionTimeout.stop();
if (this.sessionTimeout) {
this.sessionTimeout.stop();
}

this.navControlService.stop();

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

Comment on lines 7 to 19
import { Observable } from 'rxjs';
import { CoreSetup } from 'src/core/public';
import { DataPublicPluginStart } from '../../../../src/plugins/data/public';
import { SessionTimeout } from './session';
import { PluginStartDependencies, SecurityPlugin } from './plugin';

import { coreMock } from '../../../../src/core/public/mocks';
import { managementPluginMock } from '../../../../src/plugins/management/public/mocks';
import { licensingMock } from '../../licensing/public/mocks';
import { ManagementService } from './management';

describe('Security Plugin', () => {
describe('#setup', () => {

This comment was marked as resolved.

This comment was marked as resolved.

Comment on lines +35 to +40
beforeAll(() => {
Object.defineProperty(window, 'location', {
value: { href: 'http://some-host/bar', protocol: 'http' },
writable: true,
});
});

This comment was marked as resolved.

@jportner jportner self-requested a review March 2, 2020 04:12
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.

Tested changed pages locally, all works well.

LGTM on green CI / after comments are addressed!

@@ -92,10 +92,6 @@ export default async function({ readConfigFile }) {
pathname: '/app/kibana',
hash: '/dev_tools/console',
},
account: {
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 haven't found any place that would use this, so just removed instead of updating.

@@ -192,7 +192,6 @@ export class Authenticator {
client: this.options.clusterClient,
logger: this.options.loggers.get('tokens'),
}),
isProviderEnabled: this.isProviderEnabled.bind(this),
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: leftover from my recent PR, couldn't resist to fix that 🙈

@@ -366,7 +366,7 @@ export class SAMLAuthenticationProvider extends BaseAuthenticationProvider {
'Login initiated by Identity Provider is for a different user than currently authenticated.'
);
return AuthenticationResult.redirectTo(
`${this.options.basePath.get(request)}/overwritten_session`,
`${this.options.basePath.serverBasePath}/app/security/overwritten_session`,
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: it should really be serverBasePath since view is Space agnostic.

true,
schema.maybe(schema.string({ minLength: 32 })),
schema.string({ minLength: 32, defaultValue: 'a'.repeat(32) })
export const ConfigSchema = schema.object({
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: just reformatted to make eslint happy

… prefix for view route (with `appRoute`) that are rendered by dedicated server routes.
import { AuthenticationStatePage } from '../components/authentication_state_page';

describe('OverwrittenSessionPage', () => {
it('renders as expected', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: doesn't include test case for username === null

@jportner
Copy link
Contributor

jportner commented Mar 3, 2020

Tested again locally and it's all working as expected 👏

… for empty username in OverwrittenSession view.
@azasypkin
Copy link
Member Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

merge conflict between base and head

@azasypkin
Copy link
Member Author

retest

@azasypkin
Copy link
Member Author

@elasticmachine merge upstream

@azasypkin
Copy link
Member Author

7.x/7.7.0: 91babc7

@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

Yeah, thank you for the heads up @kibanamachine, it's always better later than never.

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:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants