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

[Security] Add message to login page #51557

Merged
merged 7 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/settings/security-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ are enabled.
Do not set this to `false`; it disables the login form, user and role management
screens, and authorization using <<kibana-privileges>>. To disable
{security-features} entirely, see
{ref}/security-settings.html[{es} security settings].
{ref}/security-settings.html[{es} security settings].

`xpack.security.audit.enabled`::
Set to `true` to enable audit logging for security events. By default, it is set
Expand All @@ -40,7 +40,7 @@ An arbitrary string of 32 characters or more that is used to encrypt credentials
in a cookie. It is crucial that this key is not exposed to users of {kib}. By
default, a value is automatically generated in memory. If you use that default
behavior, all sessions are invalidated when {kib} restarts.
In addition, high-availability deployments of {kib} will behave unexpectedly
In addition, high-availability deployments of {kib} will behave unexpectedly
if this setting isn't the same for all instances of {kib}.

`xpack.security.secureCookies`::
Expand All @@ -53,3 +53,6 @@ routing requests through a load balancer or proxy).
Sets the session duration (in milliseconds). By default, sessions stay active
until the browser is closed. When this is set to an explicit timeout, closing the
browser still requires the user to log back in to {kib}.

`xpack.security.loginAssistanceMessage`::
Adds a message to the login screen. Useful for displaying information about maintenance windows, links to corporate sign up pages etc.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ kibana_vars=(
xpack.security.encryptionKey
xpack.security.secureCookies
xpack.security.sessionTimeout
xpack.security.loginAssistanceMessage
telemetry.enabled
telemetry.sendUsageFrom
)
Expand Down
3 changes: 3 additions & 0 deletions x-pack/legacy/plugins/security/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const security = (kibana) => new kibana.Plugin({
encryptionKey: Joi.any().description('This key is handled in the new platform security plugin ONLY'),
sessionTimeout: Joi.any().description('This key is handled in the new platform security plugin ONLY'),
secureCookies: Joi.any().description('This key is handled in the new platform security plugin ONLY'),
loginAssistanceMessage: Joi.string().default(),
authorization: Joi.object({
legacyFallback: Joi.object({
enabled: Joi.boolean().default(true) // deprecated
Expand Down Expand Up @@ -147,7 +148,9 @@ export const security = (kibana) => new kibana.Plugin({

server.injectUiAppVars('login', () => {
const { showLogin, allowLogin, layout = 'form' } = securityPlugin.__legacyCompat.license.getFeatures();
const { loginAssistanceMessage } = securityPlugin.__legacyCompat.config;
return {
loginAssistanceMessage,
loginState: {
showLogin,
allowLogin,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('BasicLoginForm', () => {
loginState={loginState}
next={''}
intl={null as any}
loginAssistanceMessage=""
/>
)
).toMatchSnapshot();
Expand All @@ -68,6 +69,7 @@ describe('BasicLoginForm', () => {
next={''}
infoMessage={'Hey this is an info message'}
intl={null as any}
loginAssistanceMessage=""
/>
);

Expand All @@ -86,6 +88,7 @@ describe('BasicLoginForm', () => {
loginState={loginState}
next={''}
intl={null as any}
loginAssistanceMessage=""
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import { EuiButton, EuiCallOut, EuiFieldText, EuiFormRow, EuiPanel, EuiSpacer } from '@elastic/eui';
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import React, { ChangeEvent, Component, FormEvent, Fragment, MouseEvent } from 'react';
import ReactMarkdown from 'react-markdown';
import { EuiText } from '@elastic/eui';
import { LoginState } from '../../../../../common/login_state';

interface Props {
Expand All @@ -16,6 +18,7 @@ interface Props {
loginState: LoginState;
next: string;
intl: InjectedIntl;
loginAssistanceMessage: string;
}

interface State {
Expand All @@ -38,6 +41,7 @@ class BasicLoginFormUI extends Component<Props, State> {
public render() {
return (
<Fragment>
{this.renderLoginAssistanceMessage()}
{this.renderMessage()}
<EuiPanel>
<form onSubmit={this.submit}>
Expand Down Expand Up @@ -102,6 +106,16 @@ class BasicLoginFormUI extends Component<Props, State> {
);
}

private renderLoginAssistanceMessage = () => {
return (
<Fragment>
<EuiText size="s">
<ReactMarkdown>{this.props.loginAssistanceMessage}</ReactMarkdown>
</EuiText>
</Fragment>
);
};

private renderMessage = () => {
if (this.state.message) {
return (
Expand Down Expand Up @@ -132,6 +146,7 @@ class BasicLoginFormUI extends Component<Props, State> {
</Fragment>
);
}

return null;
};

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('LoginPage', () => {
loginState: createLoginState(),
isSecureConnection: false,
requiresSecureConnection: true,
loginAssistanceMessage: '',
};

expect(shallow(<LoginPage {...props} />)).toMatchSnapshot();
Expand All @@ -61,6 +62,7 @@ describe('LoginPage', () => {
}),
isSecureConnection: false,
requiresSecureConnection: false,
loginAssistanceMessage: '',
};

expect(shallow(<LoginPage {...props} />)).toMatchSnapshot();
Expand All @@ -76,6 +78,7 @@ describe('LoginPage', () => {
}),
isSecureConnection: false,
requiresSecureConnection: false,
loginAssistanceMessage: '',
};

expect(shallow(<LoginPage {...props} />)).toMatchSnapshot();
Expand All @@ -91,6 +94,21 @@ describe('LoginPage', () => {
}),
isSecureConnection: false,
requiresSecureConnection: false,
loginAssistanceMessage: '',
};

expect(shallow(<LoginPage {...props} />)).toMatchSnapshot();
});

it('renders as expected when loginAssistanceMessage is set', () => {
const props = {
http: createMockHttp(),
window: {},
next: '',
loginState: createLoginState(),
isSecureConnection: false,
requiresSecureConnection: false,
loginAssistanceMessage: 'This is an *important* message',
};

expect(shallow(<LoginPage {...props} />)).toMatchSnapshot();
Expand All @@ -106,6 +124,7 @@ describe('LoginPage', () => {
loginState: createLoginState(),
isSecureConnection: false,
requiresSecureConnection: false,
loginAssistanceMessage: '',
};

expect(shallow(<LoginPage {...props} />)).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface Props {
loginState: LoginState;
isSecureConnection: boolean;
requiresSecureConnection: boolean;
loginAssistanceMessage: string;
}

export class LoginPage extends Component<Props, {}> {
Expand Down
4 changes: 3 additions & 1 deletion x-pack/legacy/plugins/security/public/views/login/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ interface AnyObject {
$http: AnyObject,
$window: AnyObject,
secureCookies: boolean,
loginState: LoginState
loginState: LoginState,
loginAssistanceMessage: string
) => {
const basePath = chrome.getBasePath();
const next = parseNext($window.location.href, basePath);
Expand All @@ -59,6 +60,7 @@ interface AnyObject {
loginState={loginState}
isSecureConnection={isSecure}
requiresSecureConnection={secureCookies}
loginAssistanceMessage={loginAssistanceMessage}
next={next}
/>
</I18nContext>,
Expand Down
Loading