mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[env] exit if starting as root (#21563)
* [env] exit if starting as root * fix windows * s/--allow-root
This commit is contained in:
parent
e247609e8b
commit
369f0f2922
6 changed files with 147 additions and 0 deletions
|
@ -17,5 +17,6 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
require('./root');
|
||||
require('./node_version_validator');
|
||||
require('./babel_register');
|
||||
|
|
25
src/setup_node_env/root/force.js
Normal file
25
src/setup_node_env/root/force.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
module.exports = function (argv) {
|
||||
var rootIndex = argv.indexOf('--allow-root');
|
||||
var force = rootIndex >= 0;
|
||||
if (force) argv.splice(rootIndex, 1);
|
||||
return force;
|
||||
};
|
39
src/setup_node_env/root/force.test.js
Normal file
39
src/setup_node_env/root/force.test.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var forceRoot = require('./force');
|
||||
|
||||
describe('forceRoot', function () {
|
||||
|
||||
it('with flag', function () {
|
||||
expect(forceRoot(['--allow-root'])).toBeTruthy();
|
||||
});
|
||||
|
||||
it('without flag', function () {
|
||||
expect(forceRoot(['--foo'])).toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
test('remove argument', function () {
|
||||
var args = ['--allow-root', 'foo'];
|
||||
forceRoot(args);
|
||||
expect(args.includes('--allow-root')).toBeFalsy();
|
||||
});
|
||||
|
||||
});
|
28
src/setup_node_env/root/index.js
Normal file
28
src/setup_node_env/root/index.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var force = require('./force')(process.argv);
|
||||
|
||||
var uid = process.getuid && process.getuid();
|
||||
var isRoot = require('./is_root')(uid);
|
||||
|
||||
if(isRoot && !force) {
|
||||
console.error('Kibana should not be run as root. Use --allow-root to continue.');
|
||||
process.exit(1);
|
||||
}
|
22
src/setup_node_env/root/is_root.js
Normal file
22
src/setup_node_env/root/is_root.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
module.exports = function (uid) {
|
||||
return uid === 0;
|
||||
};
|
32
src/setup_node_env/root/is_root.test.js
Normal file
32
src/setup_node_env/root/is_root.test.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var isRoot = require('./is_root');
|
||||
|
||||
|
||||
describe('isRoot', function () {
|
||||
|
||||
test('0 is root', function () {
|
||||
expect(isRoot(0)).toBeTruthy();
|
||||
});
|
||||
|
||||
test('not 0 is not root', function () {
|
||||
expect(isRoot(5)).toBeFalsy();
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue