Merge pull request #7085 from lukasolson/fix/public-status-page

[statusPage] Allow unauthenticated users to see status page
This commit is contained in:
Lukas Olson 2016-05-10 13:10:53 -07:00
commit 969c7822a1
5 changed files with 62 additions and 4 deletions

View file

@ -44,3 +44,5 @@ error messages.
information and all requests.
`ops.interval`:: *Default: 10000* Set the interval in milliseconds to sample system and process performance metrics.
The minimum value is 100.
`statusPage.allowAnonymous`:: *Default: false* If authentication is enabled, setting this to `true` allows
unauthenticated users to view the Kibana server status page.

View file

@ -121,6 +121,10 @@ module.exports = () => Joi.object({
)
.default(Joi.ref('$dev')),
profile: Joi.boolean().default(false)
}).default(),
statusPage: Joi.object({
allowAnonymous: Joi.boolean().default(false)
}).default()
}).default();

View file

@ -0,0 +1,42 @@
import expect from 'expect.js';
import wrapAuthConfig from '../wrap_auth_config';
describe('Status wrapAuthConfig', () => {
let options;
beforeEach(() => {
options = {
method: 'GET',
path: '/status',
handler: function (request, reply) {
return reply();
}
};
});
it('should return a function', () => {
expect(wrapAuthConfig()).to.be.a('function');
expect(wrapAuthConfig(true)).to.be.a('function');
expect(wrapAuthConfig(false)).to.be.a('function');
});
it('should not add auth config by default', () => {
const wrapAuth = wrapAuthConfig();
const wrapped = wrapAuth(options);
expect(wrapped).to.not.have.property('config');
});
it('should not add auth config if allowAnonymous is false', () => {
const wrapAuth = wrapAuthConfig(false);
const wrapped = wrapAuth(options);
expect(wrapped).to.not.have.property('config');
});
it('should add auth config if allowAnonymous is true', () => {
const wrapAuth = wrapAuthConfig(true);
const wrapped = wrapAuth(options);
expect(wrapped).to.have.property('config');
expect(wrapped.config).to.have.property('auth');
expect(wrapped.config.auth).to.be(false);
});
});

View file

@ -1,6 +1,8 @@
import _ from 'lodash';
import ServerStatus from './server_status';
import wrapAuthConfig from './wrap_auth_config';
import { join } from 'path';
module.exports = function (kbnServer, server, config) {
kbnServer.status = new ServerStatus(kbnServer.server);
@ -9,7 +11,9 @@ module.exports = function (kbnServer, server, config) {
kbnServer.mixin(require('./metrics'));
}
server.route({
const wrapAuth = wrapAuthConfig(config.get('statusPage.allowAnonymous'));
server.route(wrapAuth({
method: 'GET',
path: '/api/status',
handler: function (request, reply) {
@ -20,7 +24,7 @@ module.exports = function (kbnServer, server, config) {
metrics: kbnServer.metrics
});
}
});
}));
server.decorate('reply', 'renderStatusPage', function () {
let app = kbnServer.uiExports.getHiddenApp('status_page');
@ -29,11 +33,11 @@ module.exports = function (kbnServer, server, config) {
return resp;
});
server.route({
server.route(wrapAuth({
method: 'GET',
path: '/status',
handler: function (request, reply) {
return reply.renderStatusPage();
}
});
}));
};

View file

@ -0,0 +1,6 @@
import {assign, identity} from 'lodash';
export default (allowAnonymous) => {
if (allowAnonymous) return options => assign(options, {config: {auth: false}});
return identity;
};