Skip to content

Commit b76f8c0

Browse files
authored
[7.x] Improve session idle timeout, add session lifespan (#49855) (#51740)
This adds an absolute session timeout (lifespan) to user sessions. It also improves the existing session timeout toast and the overall user experience in several ways.
1 parent c1870ad commit b76f8c0

File tree

43 files changed

+1491
-390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1491
-390
lines changed

docs/settings/security-settings.asciidoc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@ is set to `true` if `server.ssl.certificate` and `server.ssl.key` are set. Set
4949
this to `true` if SSL is configured outside of {kib} (for example, you are
5050
routing requests through a load balancer or proxy).
5151

52-
`xpack.security.sessionTimeout`::
52+
`xpack.security.session.idleTimeout`::
5353
Sets the session duration (in milliseconds). By default, sessions stay active
54-
until the browser is closed. When this is set to an explicit timeout, closing the
55-
browser still requires the user to log back in to {kib}.
54+
until the browser is closed. When this is set to an explicit idle timeout, closing
55+
the browser still requires the user to log back in to {kib}.
56+
57+
`xpack.security.session.lifespan`::
58+
Sets the maximum duration (in milliseconds), also known as "absolute timeout". By
59+
default, a session can be renewed indefinitely. When this value is set, a session
60+
will end once its lifespan is exceeded, even if the user is not idle. NOTE: if
61+
`idleTimeout` is not set, this setting will still cause sessions to expire.
5662

5763
`xpack.security.loginAssistanceMessage`::
5864
Adds a message to the login screen. Useful for displaying information about maintenance windows, links to corporate sign up pages etc.

docs/user/security/authentication/index.asciidoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,10 @@ The following sections apply both to <<saml>> and <<oidc>>
188188

189189
Once the user logs in to {kib} Single Sign-On, either using SAML or OpenID Connect, {es} issues access and refresh tokens
190190
that {kib} encrypts and stores them in its own session cookie. This way, the user isn't redirected to the Identity Provider
191-
for every request that requires authentication. It also means that the {kib} session depends on the `xpack.security.sessionTimeout`
192-
setting and the user is automatically logged out if the session expires. An access token that is stored in the session cookie
193-
can expire, in which case {kib} will automatically renew it with a one-time-use refresh token and store it in the same cookie.
191+
for every request that requires authentication. It also means that the {kib} session depends on the <<security-ui-settings,
192+
`xpack.security.session.idleTimeout` and `xpack.security.session.lifespan`>> settings, and the user is automatically logged
193+
out if the session expires. An access token that is stored in the session cookie can expire, in which case {kib} will
194+
automatically renew it with a one-time-use refresh token and store it in the same cookie.
194195

195196
{kib} can only determine if an access token has expired if it receives a request that requires authentication. If both access
196197
and refresh tokens have already expired (for example, after 24 hours of inactivity), {kib} initiates a new "handshake" and

docs/user/security/securing-kibana.asciidoc

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,31 @@ xpack.security.encryptionKey: "something_at_least_32_characters"
5656
For more information, see <<security-settings-kb,Security Settings in {kib}>>.
5757
--
5858

59-
. Optional: Change the default session duration. By default, sessions stay
60-
active until the browser is closed. To change the duration, set the
61-
`xpack.security.sessionTimeout` property in the `kibana.yml` configuration file.
62-
The timeout is specified in milliseconds. For example, set the timeout to 600000
63-
to expire sessions after 10 minutes:
59+
. Optional: Set a timeout to expire idle sessions. By default, a session stays
60+
active until the browser is closed. To define a sliding session expiration, set
61+
the `xpack.security.session.idleTimeout` property in the `kibana.yml`
62+
configuration file. The idle timeout is specified in milliseconds. For example,
63+
set the idle timeout to 600000 to expire idle sessions after 10 minutes:
6464
+
6565
--
6666
[source,yaml]
6767
--------------------------------------------------------------------------------
68-
xpack.security.sessionTimeout: 600000
68+
xpack.security.session.idleTimeout: 600000
69+
--------------------------------------------------------------------------------
70+
--
71+
72+
. Optional: Change the maximum session duration or "lifespan" -- also known as
73+
the "absolute timeout". By default, a session stays active until the browser is
74+
closed. If an idle timeout is defined, a session can still be extended
75+
indefinitely. To define a maximum session lifespan, set the
76+
`xpack.security.session.lifespan` property in the `kibana.yml` configuration
77+
file. The lifespan is specified in milliseconds. For example, set the lifespan
78+
to 28800000 to expire sessions after 8 hours:
79+
+
80+
--
81+
[source,yaml]
82+
--------------------------------------------------------------------------------
83+
xpack.security.session.lifespan: 28800000
6984
--------------------------------------------------------------------------------
7085
--
7186

src/dev/build/tasks/os_packages/docker_generator/resources/bin/kibana-docker

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ kibana_vars=(
182182
xpack.security.loginAssistanceMessage
183183
xpack.security.secureCookies
184184
xpack.security.sessionTimeout
185+
xpack.security.session.idleTimeout
186+
xpack.security.session.lifespan
187+
xpack.security.loginAssistanceMessage
185188
xpack.security.public.protocol
186189
xpack.security.public.hostname
187190
xpack.security.public.port

src/legacy/core_plugins/status_page/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export default function (kibana) {
2626
hidden: true,
2727
url: '/status',
2828
},
29+
injectDefaultVars(server) {
30+
return {
31+
isStatusPageAnonymous: server.config().get('status.allowAnonymous'),
32+
};
33+
}
2934
}
3035
});
3136
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": "status_page",
3+
"version": "kibana",
4+
"server": false,
5+
"ui": true
6+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { PluginInitializer } from 'kibana/public';
21+
import { StatusPagePlugin, StatusPagePluginSetup, StatusPagePluginStart } from './plugin';
22+
23+
export const plugin: PluginInitializer<StatusPagePluginSetup, StatusPagePluginStart> = () =>
24+
new StatusPagePlugin();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { Plugin, CoreSetup } from 'kibana/public';
21+
22+
export class StatusPagePlugin implements Plugin<StatusPagePluginSetup, StatusPagePluginStart> {
23+
public setup(core: CoreSetup) {
24+
const isStatusPageAnonymous = core.injectedMetadata.getInjectedVar(
25+
'isStatusPageAnonymous'
26+
) as boolean;
27+
28+
if (isStatusPageAnonymous) {
29+
core.http.anonymousPaths.register('/status');
30+
}
31+
}
32+
33+
public start() {}
34+
35+
public stop() {}
36+
}
37+
38+
export type StatusPagePluginSetup = ReturnType<StatusPagePlugin['setup']>;
39+
export type StatusPagePluginStart = ReturnType<StatusPagePlugin['start']>;

x-pack/legacy/plugins/security/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export const security = (kibana) => new kibana.Plugin({
3030
enabled: Joi.boolean().default(true),
3131
cookieName: Joi.any().description('This key is handled in the new platform security plugin ONLY'),
3232
encryptionKey: Joi.any().description('This key is handled in the new platform security plugin ONLY'),
33-
sessionTimeout: Joi.any().description('This key is handled in the new platform security plugin ONLY'),
33+
session: Joi.object({
34+
idleTimeout: Joi.any().description('This key is handled in the new platform security plugin ONLY'),
35+
lifespan: Joi.any().description('This key is handled in the new platform security plugin ONLY'),
36+
}).default(),
3437
secureCookies: Joi.any().description('This key is handled in the new platform security plugin ONLY'),
3538
public: Joi.any().description('This key is handled in the new platform security plugin ONLY'),
3639
loginAssistanceMessage: Joi.string().default(),
@@ -46,9 +49,10 @@ export const security = (kibana) => new kibana.Plugin({
4649
}).default();
4750
},
4851

49-
deprecations: function ({ unused, rename }) {
52+
deprecations: function ({ rename, unused }) {
5053
return [
5154
unused('authorization.legacyFallback.enabled'),
55+
rename('sessionTimeout', 'session.idleTimeout'),
5256
rename('authProviders', 'authc.providers'),
5357
(settings, log) => {
5458
const hasSAMLProvider = get(settings, 'authc.providers', []).includes('saml');
@@ -103,7 +107,11 @@ export const security = (kibana) => new kibana.Plugin({
103107

104108
return {
105109
secureCookies: securityPlugin.__legacyCompat.config.secureCookies,
106-
sessionTimeout: securityPlugin.__legacyCompat.config.sessionTimeout,
110+
session: {
111+
tenant: server.newPlatform.setup.core.http.basePath.serverBasePath,
112+
idleTimeout: securityPlugin.__legacyCompat.config.session.idleTimeout,
113+
lifespan: securityPlugin.__legacyCompat.config.session.lifespan,
114+
},
107115
enableSpaceAwarePrivileges: server.config().get('xpack.spaces.enabled'),
108116
};
109117
},

x-pack/legacy/plugins/security/public/hacks/on_session_timeout.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,20 @@
77
import _ from 'lodash';
88
import { uiModules } from 'ui/modules';
99
import { isSystemApiRequest } from 'ui/system_api';
10-
import { Path } from 'plugins/xpack_main/services/path';
1110
import { npSetup } from 'ui/new_platform';
1211

13-
/**
14-
* Client session timeout is decreased by this number so that Kibana server
15-
* can still access session content during logout request to properly clean
16-
* user session up (invalidate access tokens, redirect to logout portal etc.).
17-
* @type {number}
18-
*/
19-
2012
const module = uiModules.get('security', []);
2113
module.config(($httpProvider) => {
2214
$httpProvider.interceptors.push((
2315
$q,
2416
) => {
2517

26-
const isUnauthenticated = Path.isUnauthenticated();
18+
const isAnonymous = npSetup.core.http.anonymousPaths.isAnonymous(window.location.pathname);
2719

2820
function interceptorFactory(responseHandler) {
2921
return function interceptor(response) {
30-
if (!isUnauthenticated && !isSystemApiRequest(response.config)) {
31-
npSetup.plugins.security.sessionTimeout.extend();
22+
if (!isAnonymous && !isSystemApiRequest(response.config)) {
23+
npSetup.plugins.security.sessionTimeout.extend(response.config.url);
3224
}
3325
return responseHandler(response);
3426
};

0 commit comments

Comments
 (0)