From 9443a0a41be14eb1783f69291397e527a18b1417 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Tue, 18 Feb 2020 09:21:53 -0600 Subject: [PATCH 1/8] Move kibana-keystore from data/ to config/ This is a breaking change to move the location of kibana-keystore. Keystores in other stack products live in the config directory, so this updates our current path to be consistent. Closes #25746 --- src/cli_keystore/cli_keystore.js | 4 ++-- src/core/server/path/index.test.ts | 7 ++++++- src/core/server/path/index.ts | 11 +++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/cli_keystore/cli_keystore.js b/src/cli_keystore/cli_keystore.js index 7c90d88f7b0cde..a47cac832aecea 100644 --- a/src/cli_keystore/cli_keystore.js +++ b/src/cli_keystore/cli_keystore.js @@ -22,10 +22,10 @@ import { join } from 'path'; import { pkg } from '../core/server/utils'; import Command from '../cli/command'; -import { getDataPath } from '../core/server/path'; +import { getConfigDirectory } from '../core/server/path'; import { Keystore } from '../legacy/server/keystore'; -const path = join(getDataPath(), 'kibana.keystore'); +const path = join(getConfigDirectory(), 'kibana.keystore'); const keystore = new Keystore(path); import { createCli } from './create'; diff --git a/src/core/server/path/index.test.ts b/src/core/server/path/index.test.ts index 048622e1f7eabd..522e100d85e5d8 100644 --- a/src/core/server/path/index.test.ts +++ b/src/core/server/path/index.test.ts @@ -18,7 +18,7 @@ */ import { accessSync, constants } from 'fs'; -import { getConfigPath, getDataPath } from './'; +import { getConfigPath, getDataPath, getConfigDirectory } from './'; describe('Default path finder', () => { it('should find a kibana.yml', () => { @@ -30,4 +30,9 @@ describe('Default path finder', () => { const dataPath = getDataPath(); expect(() => accessSync(dataPath, constants.R_OK)).not.toThrow(); }); + + it('should find a config directory', () => { + const configDirectory = getConfigDirectory(); + expect(() => accessSync(configDirectory, constants.R_OK)).not.toThrow(); + }); }); diff --git a/src/core/server/path/index.ts b/src/core/server/path/index.ts index ef8a3caeefa2cd..5763813dc63656 100644 --- a/src/core/server/path/index.ts +++ b/src/core/server/path/index.ts @@ -31,6 +31,10 @@ const CONFIG_PATHS = [ '/etc/kibana/kibana.yml', ].filter(isString); +const CONFIG_DIRECTORIES = [process.env.KIBANA_PATH_CONF, fromRoot('config'), '/etc/kibana'].filter( + isString +); + const DATA_PATHS = [ process.env.DATA_PATH, // deprecated fromRoot('data'), @@ -54,6 +58,13 @@ function findFile(paths: string[]) { * @internal */ export const getConfigPath = () => findFile(CONFIG_PATHS); + +/** + * Get the path where the config directories are stored + * @internal + */ +export const getConfigDirectory = () => findFile(CONFIG_DIRECTORIES); + /** * Get the path where the data can be stored * @internal From 909eaa5864cf0cf9a0214dbea197afc44281f691 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Thu, 19 Mar 2020 10:33:56 -0500 Subject: [PATCH 2/8] add breaking changes --- docs/migration/migrate_8_0.asciidoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/migration/migrate_8_0.asciidoc b/docs/migration/migrate_8_0.asciidoc index ce4c97391f1b57..ab00ba2a3f0775 100644 --- a/docs/migration/migrate_8_0.asciidoc +++ b/docs/migration/migrate_8_0.asciidoc @@ -112,4 +112,8 @@ access level. been deprecated with warnings that have been logged throughout 7.x. Please use Kibana UI to re-generate the POST URL snippets if you depend on these for automated PDF reports. +[float] +==== bin/kibana-keystore has moved from the `data` folder to `config` +*Details:* The Kibana keystore is used to add configuration changes. It has been moved to Kibana's confugration directory. + // end::notable-breaking-changes[] From f6c543995f2d525fc5de836960b66782aa7bbf6b Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Mon, 30 Mar 2020 10:17:47 -0500 Subject: [PATCH 3/8] update comment --- src/core/server/path/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/server/path/index.ts b/src/core/server/path/index.ts index 5763813dc63656..759349cb47ad4c 100644 --- a/src/core/server/path/index.ts +++ b/src/core/server/path/index.ts @@ -60,7 +60,7 @@ function findFile(paths: string[]) { export const getConfigPath = () => findFile(CONFIG_PATHS); /** - * Get the path where the config directories are stored + * Get the config directory path * @internal */ export const getConfigDirectory = () => findFile(CONFIG_DIRECTORIES); From ba87e36cf63b89d43c86706344f11b503b9cd2f1 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Tue, 26 May 2020 11:03:00 -0500 Subject: [PATCH 4/8] wip --- src/cli_keystore/cli_keystore.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/cli_keystore/cli_keystore.js b/src/cli_keystore/cli_keystore.js index 4ace480fdafd4b..817d36908e09bc 100644 --- a/src/cli_keystore/cli_keystore.js +++ b/src/cli_keystore/cli_keystore.js @@ -19,14 +19,31 @@ import _ from 'lodash'; import { join } from 'path'; +import { existsSync } from 'fs'; import { pkg } from '../core/server/utils'; import Command from '../cli/command'; -import { getConfigDirectory } from '../core/server/path'; +import { getConfigDirectory, getDataPath } from '../core/server/path'; import { Keystore } from '../legacy/server/keystore'; -const path = join(getConfigDirectory(), 'kibana.keystore'); -const keystore = new Keystore(path); + + +function getPath() { + return [join(getConfigDirectory(), 'kibana.keystore'), join(getDataPath(), 'kibana.keystore')] + .filter(p => existsSync(p)) + .shift(); +} + +function isDeprecated(path) { + +} + +const yml = getPath(); +if (isDeprecated(yml)) { + console.log(`Keystore in ${getConfigDirectory()} is deprecated. Future versions will read from ${getDataPath}`) +} +const keystore = new Keystore(); + import { createCli } from './create'; import { listCli } from './list'; From bb887e9b0c23ccbe5303691286dcf637dff2d7e2 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Mon, 8 Jun 2020 09:41:15 -0500 Subject: [PATCH 5/8] fix docs --- docs/migration/migrate_8_0.asciidoc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/migration/migrate_8_0.asciidoc b/docs/migration/migrate_8_0.asciidoc index 2dc146828b5529..92bf12911a3430 100644 --- a/docs/migration/migrate_8_0.asciidoc +++ b/docs/migration/migrate_8_0.asciidoc @@ -116,8 +116,9 @@ URL that it derived from the actual server address and `xpack.security.public` s *Impact:* Any workflow that involved manually clearing generated bundles will have to be updated with the new path. [float]] -=== bin/kibana-keystore has moved from the `data` folder to `config` -*Details:* The Kibana keystore is used to add configuration changes. It has been moved to Kibana's confugration directory. +=== kibana.keystore has moved from the `data` folder to the `config` folder +*Details:* By default, kibana.keystore has moved from the confgured `path.data` folder to `/config` for archive distributions +and `/etc/kibana` for package distributions. [float] [[breaking_80_user_role_changes]] From dd27fab474a5713096764127d5cba303b8778691 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Mon, 8 Jun 2020 10:08:50 -0500 Subject: [PATCH 6/8] read from both keystore locations, write priority to non-deprecated --- docs/migration/migrate_8_0.asciidoc | 2 +- src/cli_keystore/cli_keystore.js | 35 +++++++++++++---------------- src/core/server/path/index.ts | 6 ++--- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/docs/migration/migrate_8_0.asciidoc b/docs/migration/migrate_8_0.asciidoc index 92bf12911a3430..7f6352aa8110d2 100644 --- a/docs/migration/migrate_8_0.asciidoc +++ b/docs/migration/migrate_8_0.asciidoc @@ -117,7 +117,7 @@ URL that it derived from the actual server address and `xpack.security.public` s [float]] === kibana.keystore has moved from the `data` folder to the `config` folder -*Details:* By default, kibana.keystore has moved from the confgured `path.data` folder to `/config` for archive distributions +*Details:* By default, kibana.keystore has moved from the configured `path.data` folder to `/config` for archive distributions and `/etc/kibana` for package distributions. [float] diff --git a/src/cli_keystore/cli_keystore.js b/src/cli_keystore/cli_keystore.js index 817d36908e09bc..0631fe2eb1c367 100644 --- a/src/cli_keystore/cli_keystore.js +++ b/src/cli_keystore/cli_keystore.js @@ -21,30 +21,12 @@ import _ from 'lodash'; import { join } from 'path'; import { existsSync } from 'fs'; +import Logger from '../cli_plugin/lib/logger'; import { pkg } from '../core/server/utils'; import Command from '../cli/command'; import { getConfigDirectory, getDataPath } from '../core/server/path'; import { Keystore } from '../legacy/server/keystore'; - - -function getPath() { - return [join(getConfigDirectory(), 'kibana.keystore'), join(getDataPath(), 'kibana.keystore')] - .filter(p => existsSync(p)) - .shift(); -} - -function isDeprecated(path) { - -} - -const yml = getPath(); -if (isDeprecated(yml)) { - console.log(`Keystore in ${getConfigDirectory()} is deprecated. Future versions will read from ${getDataPath}`) -} -const keystore = new Keystore(); - - import { createCli } from './create'; import { listCli } from './list'; import { addCli } from './add'; @@ -59,6 +41,21 @@ program .version(pkg.version) .description('A tool for managing settings stored in the Kibana keystore'); +function getKeystore() { + const configKeystore = join(getConfigDirectory(), 'kibana.keystore'); + const dataKeystore = join(getDataPath(), 'kibana.keystore'); + + if (existsSync(dataKeystore)) { + const logger = new Logger(); + logger.log( + `kibana.keystore path at ${dataKeystore} is deprecated. Future versions will read from ${configKeystore}.` + ); + } + return [configKeystore, dataKeystore].filter((p) => existsSync(p)).shift(); +} + +const keystore = new Keystore(getKeystore()); + createCli(program, keystore); listCli(program, keystore); addCli(program, keystore); diff --git a/src/core/server/path/index.ts b/src/core/server/path/index.ts index fe8041e3d1c229..1bb650518c47aa 100644 --- a/src/core/server/path/index.ts +++ b/src/core/server/path/index.ts @@ -53,19 +53,19 @@ function findFile(paths: string[]) { } /** - * Get the path where the config files are stored + * Get the path of kibana.yml * @internal */ export const getConfigPath = () => findFile(CONFIG_PATHS); /** - * Get the config directory path + * Get the directory containing configuration files * @internal */ export const getConfigDirectory = () => findFile(CONFIG_DIRECTORIES); /** - * Get the path where the data can be stored + * Get the directory containing runtime data * @internal */ export const getDataPath = () => findFile(DATA_PATHS); From e6fb8e1871eff582ba9ded75604d848e66bca9c7 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Tue, 7 Jul 2020 10:27:04 -0500 Subject: [PATCH 7/8] note data directory fallback --- docs/migration/migrate_8_0.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/migration/migrate_8_0.asciidoc b/docs/migration/migrate_8_0.asciidoc index ac6b32bd55c3e6..b80503750a26e9 100644 --- a/docs/migration/migrate_8_0.asciidoc +++ b/docs/migration/migrate_8_0.asciidoc @@ -118,7 +118,7 @@ URL that it derived from the actual server address and `xpack.security.public` s [float]] === kibana.keystore has moved from the `data` folder to the `config` folder *Details:* By default, kibana.keystore has moved from the configured `path.data` folder to `/config` for archive distributions -and `/etc/kibana` for package distributions. +and `/etc/kibana` for package distributions. If a pre-existing keystore exists in the data directory that path will continue to be used. [float] [[breaking_80_user_role_changes]] From 3c36f551fca89ad625d239f05e3eb74eac84bb16 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Tue, 7 Jul 2020 12:15:05 -0500 Subject: [PATCH 8/8] add tests for get_keystore --- src/cli_keystore/cli_keystore.js | 18 +-------- src/cli_keystore/get_keystore.js | 40 +++++++++++++++++++ src/cli_keystore/get_keystore.test.js | 57 +++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 src/cli_keystore/get_keystore.js create mode 100644 src/cli_keystore/get_keystore.test.js diff --git a/src/cli_keystore/cli_keystore.js b/src/cli_keystore/cli_keystore.js index 0631fe2eb1c367..d12c80b361c92d 100644 --- a/src/cli_keystore/cli_keystore.js +++ b/src/cli_keystore/cli_keystore.js @@ -18,19 +18,16 @@ */ import _ from 'lodash'; -import { join } from 'path'; -import { existsSync } from 'fs'; -import Logger from '../cli_plugin/lib/logger'; import { pkg } from '../core/server/utils'; import Command from '../cli/command'; -import { getConfigDirectory, getDataPath } from '../core/server/path'; import { Keystore } from '../legacy/server/keystore'; import { createCli } from './create'; import { listCli } from './list'; import { addCli } from './add'; import { removeCli } from './remove'; +import { getKeystore } from './get_keystore'; const argv = process.env.kbnWorkerArgv ? JSON.parse(process.env.kbnWorkerArgv) @@ -41,19 +38,6 @@ program .version(pkg.version) .description('A tool for managing settings stored in the Kibana keystore'); -function getKeystore() { - const configKeystore = join(getConfigDirectory(), 'kibana.keystore'); - const dataKeystore = join(getDataPath(), 'kibana.keystore'); - - if (existsSync(dataKeystore)) { - const logger = new Logger(); - logger.log( - `kibana.keystore path at ${dataKeystore} is deprecated. Future versions will read from ${configKeystore}.` - ); - } - return [configKeystore, dataKeystore].filter((p) => existsSync(p)).shift(); -} - const keystore = new Keystore(getKeystore()); createCli(program, keystore); diff --git a/src/cli_keystore/get_keystore.js b/src/cli_keystore/get_keystore.js new file mode 100644 index 00000000000000..c8ff2555563ad2 --- /dev/null +++ b/src/cli_keystore/get_keystore.js @@ -0,0 +1,40 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { existsSync } from 'fs'; +import { join } from 'path'; + +import Logger from '../cli_plugin/lib/logger'; +import { getConfigDirectory, getDataPath } from '../core/server/path'; + +export function getKeystore() { + const configKeystore = join(getConfigDirectory(), 'kibana.keystore'); + const dataKeystore = join(getDataPath(), 'kibana.keystore'); + let keystorePath = null; + if (existsSync(dataKeystore)) { + const logger = new Logger(); + logger.log( + `kibana.keystore located in the data folder is deprecated. Future versions will use the config folder.` + ); + keystorePath = dataKeystore; + } else { + keystorePath = configKeystore; + } + return keystorePath; +} diff --git a/src/cli_keystore/get_keystore.test.js b/src/cli_keystore/get_keystore.test.js new file mode 100644 index 00000000000000..88102b8f51d572 --- /dev/null +++ b/src/cli_keystore/get_keystore.test.js @@ -0,0 +1,57 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { getKeystore } from './get_keystore'; +import Logger from '../cli_plugin/lib/logger'; +import fs from 'fs'; +import sinon from 'sinon'; + +describe('get_keystore', () => { + const sandbox = sinon.createSandbox(); + + beforeEach(() => { + sandbox.stub(Logger.prototype, 'log'); + }); + + afterEach(() => { + sandbox.restore(); + }); + + it('uses the config directory if there is no pre-existing keystore', () => { + sandbox.stub(fs, 'existsSync').returns(false); + expect(getKeystore()).toContain('config'); + expect(getKeystore()).not.toContain('data'); + }); + + it('uses the data directory if there is a pre-existing keystore in the data directory', () => { + sandbox.stub(fs, 'existsSync').returns(true); + expect(getKeystore()).toContain('data'); + expect(getKeystore()).not.toContain('config'); + }); + + it('logs a deprecation warning if the data directory is used', () => { + sandbox.stub(fs, 'existsSync').returns(true); + getKeystore(); + sandbox.assert.calledOnce(Logger.prototype.log); + sandbox.assert.calledWith( + Logger.prototype.log, + 'kibana.keystore located in the data folder is deprecated. Future versions will use the config folder.' + ); + }); +});