Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion x-pack/plugins/canvas/server/lib/create_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import boom from 'boom';
import { isSecurityEnabled } from './feature_check';

export const createHandlers = (request, server) => {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('data');
Expand All @@ -19,7 +20,7 @@ export const createHandlers = (request, server) => {
httpHeaders: request.headers,
elasticsearchClient: async (...args) => {
// check if the session is valid because continuing to use it
if (server.plugins.security) {
if (isSecurityEnabled(server)) {
const authenticationResult = await server.plugins.security.authenticate(request);
if (!authenticationResult.succeeded()) throw boom.unauthorized(authenticationResult.error);
}
Expand Down
17 changes: 17 additions & 0 deletions x-pack/plugins/canvas/server/lib/feature_check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const isSecurityEnabled = server => {
const securityPlugin = server.plugins.security;
const xpackInfo = server.plugins.xpack_main.info;

return (
securityPlugin &&
xpackInfo.isAvailable() &&
xpackInfo.feature('security').isEnabled() &&
!xpackInfo.license.isOneOf('basic')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, is this really required? Won't xpackInfo.feature('security').isEnabled() be false if the license is wrong?

Copy link
Contributor Author

@cqliu1 cqliu1 Oct 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if you run elasticsearch with a basic license and xpack.security.enabled: true, server.xpack_main.feature('security').isEnabled() will be true, but server.xpack_main.feature('security').isAvailable() will be false. Instead of checking the license, I can check isAvailable(), but I do need both checks in case for the case I mentioned above and if you have a non-basic license but have security disabled.

);
};