-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:elastic/kibana into implement/kib…
…ana-index-template
- Loading branch information
Showing
128 changed files
with
3,394 additions
and
643 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
SCRIPT=$0 | ||
|
||
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. | ||
while [ -h "$SCRIPT" ] ; do | ||
ls=$(ls -ld "$SCRIPT") | ||
# Drop everything prior to -> | ||
link=$(expr "$ls" : '.*-> \(.*\)$') | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=$(dirname "$SCRIPT")/"$link" | ||
fi | ||
done | ||
|
||
DIR="$(dirname "${SCRIPT}")/.." | ||
NODE="${DIR}/node/bin/node" | ||
test -x "$NODE" || NODE=$(which node) | ||
if [ ! -x "$NODE" ]; then | ||
echo "unable to find usable node.js executable." | ||
exit 1 | ||
fi | ||
|
||
"${NODE}" "${DIR}/src/cli_keystore" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@echo off | ||
|
||
SETLOCAL | ||
|
||
set SCRIPT_DIR=%~dp0 | ||
for %%I in ("%SCRIPT_DIR%..") do set DIR=%%~dpfI | ||
|
||
set NODE=%DIR%\node\node.exe | ||
|
||
WHERE /Q node | ||
IF %ERRORLEVEL% EQU 0 ( | ||
for /f "delims=" %%i in ('WHERE node') do set SYS_NODE=%%i | ||
) | ||
|
||
If Not Exist "%NODE%" ( | ||
IF Exist "%SYS_NODE%" ( | ||
set "NODE=%SYS_NODE%" | ||
) else ( | ||
Echo unable to find usable node.js executable. | ||
Exit /B 1 | ||
) | ||
) | ||
|
||
TITLE Kibana Keystore | ||
"%NODE%" "%DIR%\src\cli_keystore" %* | ||
|
||
:finally | ||
|
||
ENDLOCAL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
[[secure-settings]] | ||
=== Secure Settings | ||
|
||
Some settings are sensitive, and relying on filesystem permissions to protect | ||
their values is not sufficient. For this use case, Kibana provides a | ||
keystore, and the `kibana-keystore` tool to manage the settings in the keystore. | ||
|
||
NOTE: All commands here should be run as the user which will run Kibana. | ||
|
||
[float] | ||
[[creating-keystore]] | ||
=== Creating the keystore | ||
|
||
To create the `kibana.keystore`, use the `create` command: | ||
|
||
[source,sh] | ||
---------------------------------------------------------------- | ||
bin/kibana-keystore create | ||
---------------------------------------------------------------- | ||
|
||
The file `kibana.keystore` will be created in the directory defined by the | ||
`path.data` configuration setting. | ||
|
||
[float] | ||
[[list-settings]] | ||
=== Listing settings in the keystore | ||
|
||
A list of the settings in the keystore is available with the `list` command: | ||
|
||
[source,sh] | ||
---------------------------------------------------------------- | ||
bin/kibana-keystore list | ||
---------------------------------------------------------------- | ||
|
||
[float] | ||
[[add-string-to-keystore]] | ||
=== Adding string settings | ||
|
||
Sensitive string settings, like authentication credentials for Elasticsearch | ||
can be added using the `add` command: | ||
|
||
[source,sh] | ||
---------------------------------------------------------------- | ||
bin/kibana-keystore add the.setting.name.to.set | ||
---------------------------------------------------------------- | ||
|
||
The tool will prompt for the value of the setting. To pass the value | ||
through stdin, use the `--stdin` flag: | ||
|
||
[source,sh] | ||
---------------------------------------------------------------- | ||
cat /file/containing/setting/value | bin/kibana-keystore add --stdin the.setting.name.to.set | ||
---------------------------------------------------------------- | ||
|
||
[float] | ||
[[remove-settings]] | ||
=== Removing settings | ||
|
||
To remove a setting from the keystore, use the `remove` command: | ||
|
||
[source,sh] | ||
---------------------------------------------------------------- | ||
bin/kibana-keystore remove the.setting.name.to.remove | ||
---------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('../src/babel-register'); | ||
require('../src/dev/run_eslint'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { join } from 'path'; | ||
import { set } from 'lodash'; | ||
|
||
import { Keystore } from '../../server/keystore'; | ||
import { getData } from '../../server/path'; | ||
|
||
export function loadKeystore() { | ||
const path = join(getData(), 'kibana.keystore'); | ||
|
||
const keystore = new Keystore(path); | ||
keystore.load(); | ||
|
||
return keystore; | ||
} | ||
|
||
export function readKeystore() { | ||
const keystore = loadKeystore(); | ||
const keys = Object.keys(keystore.data); | ||
|
||
const data = {}; | ||
keys.forEach(key => { | ||
set(data, key, keystore.data[key]); | ||
}); | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import expect from 'expect.js'; | ||
import sinon from 'sinon'; | ||
import mockFs from 'mock-fs'; | ||
import { PassThrough } from 'stream'; | ||
|
||
import { Keystore } from '../../server/keystore'; | ||
import { add } from '../add'; | ||
import Logger from '../../cli_plugin/lib/logger'; | ||
import * as prompt from '../../server/utils/prompt'; | ||
|
||
describe('Kibana keystore', () => { | ||
describe('add', () => { | ||
const sandbox = sinon.sandbox.create(); | ||
|
||
const keystoreData = '1:IxR0geiUTMJp8ueHDkqeUJ0I9eEw4NJPXIJi22UDyfGfJSy4mH' | ||
+ 'BBuGPkkAix/x/YFfIxo4tiKGdJ2oVTtU8LgKDkVoGdL+z7ylY4n3myatt6osqhI4lzJ9M' | ||
+ 'Ry21UcAJki2qFUTj4TYuvhta3LId+RM5UX/dJ2468hQ=='; | ||
|
||
beforeEach(() => { | ||
mockFs({ | ||
'/data': { | ||
'test.keystore': JSON.stringify(keystoreData), | ||
} | ||
}); | ||
|
||
sandbox.stub(prompt, 'confirm'); | ||
sandbox.stub(prompt, 'question'); | ||
|
||
sandbox.stub(Logger.prototype, 'log'); | ||
sandbox.stub(Logger.prototype, 'error'); | ||
}); | ||
|
||
afterEach(() => { | ||
mockFs.restore(); | ||
sandbox.restore(); | ||
}); | ||
|
||
it('returns an error for a nonexistent keystore', async () => { | ||
const keystore = new Keystore('/data/nonexistent.keystore'); | ||
const message = 'ERROR: Kibana keystore not found. Use \'create\' command to create one.'; | ||
|
||
await add(keystore, 'foo'); | ||
|
||
sinon.assert.calledOnce(Logger.prototype.error); | ||
sinon.assert.calledWith(Logger.prototype.error, message); | ||
}); | ||
|
||
it('does not attempt to create a keystore', async () => { | ||
const keystore = new Keystore('/data/nonexistent.keystore'); | ||
sandbox.stub(keystore, 'save'); | ||
|
||
await add(keystore, 'foo'); | ||
|
||
sinon.assert.notCalled(keystore.save); | ||
}); | ||
|
||
it('prompts for existing key', async () => { | ||
prompt.confirm.returns(Promise.resolve(true)); | ||
prompt.question.returns(Promise.resolve('bar')); | ||
|
||
const keystore = new Keystore('/data/test.keystore'); | ||
await add(keystore, 'a2'); | ||
|
||
sinon.assert.calledOnce(prompt.confirm); | ||
sinon.assert.calledOnce(prompt.question); | ||
|
||
const { args } = prompt.confirm.getCall(0); | ||
|
||
expect(args[0]).to.eql('Setting a2 already exists. Overwrite?'); | ||
}); | ||
|
||
it('aborts if overwrite is denied', async () => { | ||
prompt.confirm.returns(Promise.resolve(false)); | ||
|
||
const keystore = new Keystore('/data/test.keystore'); | ||
await add(keystore, 'a2'); | ||
|
||
sinon.assert.notCalled(prompt.question); | ||
|
||
sinon.assert.calledOnce(Logger.prototype.log); | ||
sinon.assert.calledWith(Logger.prototype.log, 'Exiting without modifying keystore.'); | ||
}); | ||
|
||
it('overwrites without prompt if force is supplied', async () => { | ||
prompt.question.returns(Promise.resolve('bar')); | ||
|
||
const keystore = new Keystore('/data/test.keystore'); | ||
sandbox.stub(keystore, 'save'); | ||
|
||
await add(keystore, 'a2', { force: true }); | ||
|
||
sinon.assert.notCalled(prompt.confirm); | ||
sinon.assert.calledOnce(keystore.save); | ||
}); | ||
|
||
it('trims value', async () => { | ||
prompt.question.returns(Promise.resolve('bar\n')); | ||
|
||
const keystore = new Keystore('/data/test.keystore'); | ||
sandbox.stub(keystore, 'save'); | ||
|
||
await add(keystore, 'foo'); | ||
|
||
expect(keystore.data.foo).to.eql('bar'); | ||
}); | ||
|
||
it('persists updated keystore', async () => { | ||
prompt.question.returns(Promise.resolve('bar\n')); | ||
|
||
|
||
const keystore = new Keystore('/data/test.keystore'); | ||
sandbox.stub(keystore, 'save'); | ||
|
||
await add(keystore, 'foo'); | ||
|
||
sinon.assert.calledOnce(keystore.save); | ||
}); | ||
|
||
it('accepts stdin', async () => { | ||
const keystore = new Keystore('/data/test.keystore'); | ||
sandbox.stub(keystore, 'save'); | ||
|
||
const stdin = new PassThrough(); | ||
process.nextTick(() => { | ||
stdin.write('kibana\n'); | ||
stdin.end(); | ||
}); | ||
|
||
await add(keystore, 'foo', { stdin }); | ||
|
||
expect(keystore.data.foo).to.eql('kibana'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.