-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Beats/security #22500
Merged
mattapperson
merged 3 commits into
elastic:feature/x-pack/management/beats
from
mattapperson:beats/security
Aug 30, 2018
Merged
Beats/security #22500
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -4,6 +4,10 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import Boom from 'boom'; | ||
// @ts-ignore | ||
import { mirrorPluginStatus } from '../../../../../../server/lib/mirror_plugin_status'; | ||
import { PLUGIN } from '../../../../common/constants/plugin'; | ||
import { wrapRequest } from '../../../utils/wrap_request'; | ||
import { | ||
BackendFrameworkAdapter, | ||
|
@@ -29,6 +33,18 @@ export class KibanaBackendFrameworkAdapter implements BackendFrameworkAdapter { | |
} | ||
this.cryptoHash = null; | ||
this.validateConfig(); | ||
|
||
const xpackMainPlugin = hapiServer.plugins.xpack_main; | ||
const thisPlugin = hapiServer.plugins.beats_management; | ||
|
||
mirrorPluginStatus(xpackMainPlugin, thisPlugin); | ||
xpackMainPlugin.status.once('green', () => { | ||
// Register a function that is called whenever the xpack info changes, | ||
// to re-compute the license check results for this plugin | ||
xpackMainPlugin.info | ||
.feature(PLUGIN.ID) | ||
.registerLicenseCheckResultsGenerator(this.checkLicense); | ||
}); | ||
} | ||
|
||
public getSetting(settingPath: string) { | ||
|
@@ -56,10 +72,17 @@ export class KibanaBackendFrameworkAdapter implements BackendFrameworkAdapter { | |
public registerRoute<RouteRequest extends FrameworkWrappableRequest, RouteResponse>( | ||
route: FrameworkRouteOptions<RouteRequest, RouteResponse> | ||
) { | ||
const wrappedHandler = (request: any, reply: any) => route.handler(wrapRequest(request), reply); | ||
const wrappedHandler = (licenseRequired: boolean) => (request: any, reply: any) => { | ||
const xpackMainPlugin = this.server.plugins.xpack_main; | ||
const licenseCheckResults = xpackMainPlugin.info.feature(PLUGIN.ID).getLicenseCheckResults(); | ||
if (licenseRequired && !licenseCheckResults.licenseValid) { | ||
reply(Boom.forbidden(licenseCheckResults.message)); | ||
} | ||
return route.handler(wrapRequest(request), reply); | ||
}; | ||
|
||
this.server.route({ | ||
handler: wrappedHandler, | ||
handler: wrappedHandler(route.licenseRequired), | ||
method: route.method, | ||
path: route.path, | ||
config: route.config, | ||
|
@@ -78,4 +101,60 @@ export class KibanaBackendFrameworkAdapter implements BackendFrameworkAdapter { | |
this.cryptoHash = 'xpack_beats_default_encryptionKey'; | ||
} | ||
} | ||
|
||
private checkLicense(xPackInfo: any) { | ||
// If, for some reason, we cannot get the license information | ||
// from Elasticsearch, assume worst case and disable the Logstash pipeline UI | ||
if (!xPackInfo || !xPackInfo.isAvailable()) { | ||
return { | ||
securityEnabled: false, | ||
licenseValid: false, | ||
message: | ||
'You cannot manage Beats centeral management because license information is not available at this time.', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we update this language to say
|
||
}; | ||
} | ||
|
||
const VALID_LICENSE_MODES = ['trial', 'gold', 'platinum']; | ||
|
||
const isLicenseValid = xPackInfo.license.isOneOf(VALID_LICENSE_MODES); | ||
const isLicenseActive = xPackInfo.license.isActive(); | ||
const licenseType = xPackInfo.license.getType(); | ||
const isSecurityEnabled = xPackInfo.feature('security').isEnabled(); | ||
|
||
// Security is not enabled in ES | ||
if (!isSecurityEnabled) { | ||
const message = | ||
'Security must be enabled in order to use Beats centeral management features.' + | ||
' Please set xpack.security.enabled: true in your elasticsearch.yml.'; | ||
return { | ||
securityEnabled: false, | ||
licenseValid: true, | ||
message, | ||
}; | ||
} | ||
|
||
// License is not valid | ||
if (!isLicenseValid) { | ||
return { | ||
securityEnabled: true, | ||
licenseValid: false, | ||
message: `Your ${licenseType} license does not support Beats centeral management features. Please upgrade your license.`, | ||
}; | ||
} | ||
|
||
// License is valid but not active, we go into a read-only mode. | ||
if (!isLicenseActive) { | ||
return { | ||
securityEnabled: true, | ||
licenseValid: false, | ||
message: `You cannot edit, create, or delete your Beats centeral management configurations because your ${licenseType} license has expired.`, | ||
}; | ||
} | ||
|
||
// License is valid and active | ||
return { | ||
securityEnabled: true, | ||
licenseValid: true, | ||
}; | ||
} | ||
} |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logstash pipeline UI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh, yup