-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[SR] Add permissions UI and Cloud-specific repository type UI branch #35833
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
Merged
jen-huang
merged 3 commits into
elastic:feature/snapshots
from
jen-huang:feature/snapshots-permissions
May 1, 2019
Merged
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/snapshot_restore/public/app/services/http/app_requests.ts
This file contains hidden or 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,15 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| import { API_BASE_PATH } from '../../../../common/constants'; | ||
| import { httpService } from './http'; | ||
| import { useRequest } from './use_request'; | ||
|
|
||
| export const loadPermissions = () => { | ||
| return useRequest({ | ||
| path: httpService.addBasePath(`${API_BASE_PATH}permissions`), | ||
| method: 'get', | ||
| }); | ||
| }; |
This file contains hidden or 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 hidden or 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,61 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| import { Router, RouterRouteHandler } from '../../../../../server/lib/create_router'; | ||
| import { wrapCustomError } from '../../../../../server/lib/create_router/error_wrappers'; | ||
| import { APP_PERMISSIONS } from '../../../common/constants'; | ||
| import { Plugins } from '../../../shim'; | ||
|
|
||
| let xpackMainPlugin: any; | ||
|
|
||
| export function registerAppRoutes(router: Router, plugins: Plugins) { | ||
| xpackMainPlugin = plugins.xpack_main; | ||
| router.get('permissions', getPermissionsHandler); | ||
| } | ||
|
|
||
| export function getXpackMainPlugin() { | ||
| return xpackMainPlugin; | ||
| } | ||
|
|
||
| export const getPermissionsHandler: RouterRouteHandler = async (req, callWithRequest) => { | ||
| const xpackInfo = getXpackMainPlugin() && getXpackMainPlugin().info; | ||
| if (!xpackInfo) { | ||
| // xpackInfo is updated via poll, so it may not be available until polling has begun. | ||
| // In this rare situation, tell the client the service is temporarily unavailable. | ||
| throw wrapCustomError(new Error('Security info unavailable'), 503); | ||
| } | ||
|
|
||
| const securityInfo = xpackInfo && xpackInfo.isAvailable() && xpackInfo.feature('security'); | ||
| if (!securityInfo || !securityInfo.isAvailable() || !securityInfo.isEnabled()) { | ||
| // If security isn't enabled, let the user use app. | ||
| return { | ||
| hasPermission: true, | ||
| missingClusterPrivileges: [], | ||
| }; | ||
| } | ||
|
|
||
| const { has_all_requested: hasPermission, cluster } = await callWithRequest('transport.request', { | ||
| path: '/_security/user/_has_privileges', | ||
| method: 'POST', | ||
| body: { | ||
| cluster: APP_PERMISSIONS, | ||
| }, | ||
| }); | ||
|
|
||
| const missingClusterPrivileges = Object.keys(cluster).reduce( | ||
| (permissions: string[], permissionName: string): string[] => { | ||
| if (!cluster[permissionName]) { | ||
| permissions.push(permissionName); | ||
| } | ||
| return permissions; | ||
| }, | ||
| [] | ||
| ); | ||
|
|
||
| return { | ||
| hasPermission, | ||
| missingClusterPrivileges, | ||
| }; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
@cjcenizal I discovered that this branch isn't entered if security is enabled, but not available. This can happen if user has a license with security enabled, and reverts back to Basic. Basic doesn't have security available, but security is still "enabled".
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.
Great catch! And thanks for adding the comment. I'm sure I'll completely forget about this and that comment will save the day for me.