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 config options for changing storage and preferences cookie names #273

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export default function (kibana) {
cookie: Joi.object().keys({
secure: Joi.boolean().default(false),
name: Joi.string().default('security_authentication'),
storage_cookie_name: Joi.string().default('security_storage'),
preferences_cookie_name: Joi.string().default('security_preferences'),
password: Joi.string().min(32).default('security_cookie_default_password'),
ttl: Joi.number().integer().min(0).default(60 * 60 * 1000),
domain: Joi.string(),
Expand Down Expand Up @@ -348,7 +350,7 @@ export default function (kibana) {
storageCookieConf["domain"] = config.get('opendistro_security.cookie.domain');
}

server.state('security_storage', storageCookieConf);
server.state(config.get('opendistro_security.cookie.storage_cookie_name'), storageCookieConf);


if (authType && authType !== '' && ['basicauth', 'jwt', 'openid', 'saml', 'proxycache'].indexOf(authType) > -1) {
Expand Down Expand Up @@ -446,7 +448,7 @@ export default function (kibana) {
preferenceCookieConf["domain"] = config.get('opendistro_security.cookie.domain');
}

server.state('security_preferences', preferenceCookieConf);
server.state(config.get("opendistro_security.cookie.preferences_cookie_name"), preferenceCookieConf);


this.status.yellow("Security multitenancy registered.");
Expand Down
6 changes: 4 additions & 2 deletions lib/backend/opendistro_security.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export default class SecurityBackend {

// the es config for later use
this._esconfig = esConfig;

this._preferencesCookieName = server.config().get("opendistro_security.cookie.preferences_cookie_name");
}

/**
Expand Down Expand Up @@ -304,7 +306,7 @@ export default class SecurityBackend {

updateAndGetTenantPreferences(request, user, tenant) {

var prefs = request.state.security_preferences;
var prefs = request.state[this._preferencesCookieName];
// no prefs cookie present
if (!prefs) {
var newPrefs = {};
Expand All @@ -327,7 +329,7 @@ export default class SecurityBackend {
return null;
}
// get users preferred tenant
var prefs = request.state.security_preferences;
var prefs = request.state[this._preferencesCookieName];

if (prefs) {
var preferredTenant = prefs[username];
Expand Down
2 changes: 1 addition & 1 deletion lib/multitenancy/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default function (pluginRoot, server, kbnServer, APP_ROOT, API_ROOT, auth
request.auth.securitySessionStorage.putStorage('tenant', {
selected: selectedTenant
});
h.state('security_preferences', prefcookie);
h.state(config.get('opendistro_security.cookie.preferences_cookie_name'), prefcookie);
}

if (debugEnabled) {
Expand Down
3 changes: 2 additions & 1 deletion lib/multitenancy/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { migrateTenant } from './migrate_tenants';

module.exports = function (pluginRoot, server, kbnServer, APP_ROOT, API_ROOT) {

const config = server.config();
const backend = server.plugins.opendistro_security.getSecurityBackend();
const { setupIndexTemplate } = indexTemplate(this, server);
const debugEnabled = server.config().get("opendistro_security.multitenancy.debug");
Expand All @@ -56,7 +57,7 @@ module.exports = function (pluginRoot, server, kbnServer, APP_ROOT, API_ROOT) {
request.log(['info', 'security', 'tenant_POST'], selectedTenant);
}

return h.response(request.payload.tenant).state('security_preferences', prefs);
return h.response(request.payload.tenant).state(config.get('opendistro_security.cookie.preferences_cookie_name'), prefs);
}
});

Expand Down
12 changes: 6 additions & 6 deletions lib/session/sessionPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import filterAuthHeaders from '../auth/filter_auth_headers';
const Hoek = require('hoek');
const Joi = require('joi');

/**
* Name of the cookie where we store additional session information, such as authInfo
* @type {string}
*/
const storageCookieName = 'security_storage';

let internals = {};

internals.config = Joi.object({
Expand All @@ -30,6 +24,12 @@ const register = function (server, options) {

let settings = results.value;

/**
* Name of the cookie where we store additional session information, such as authInfo
* @type {string}
*/
const storageCookieName = server.config().get("opendistro_security.cookie.storage_cookie_name");


// @todo Don't register e.g. authenticate() when we have Kerberos or Proxy-Auth?
server.ext('onPreAuth', function (request, h) {
Expand Down