-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Beginning to use the ES APIs to insert/check privileges (#18645)
* Beginning to use the ES APIs to insert/check privileges * Removing todo comment, I think we're good with the current check * Adding ability to edit kibana application privileges * Introducing DEFAULT_RESOURCE constant * Removing unused arguments when performing saved objects auth check * Performing bulkCreate auth more efficiently * Throwing error in SavedObjectClient.find if type isn't provided * Fixing Reporting and removing errant console.log * Introducing a separate hasPrivileges "service" * Adding tests and fleshing out the has privileges "service" * Fixing error message * You can now edit whatever roles you want * We're gonna throw the find error in another PR * Changing conflicting version detection to work when user has no application privileges * Throwing correct error when user is forbidden * Removing unused interceptor * Adding warning if they're editing a role with application privileges we can't edit * Fixing filter... * Beginning to only update privileges when they need to be * More tests * One more test... * Restricting the rbac application name that can be chosen * Removing DEFAULT_RESOURCE check * Supporting 1024 characters for the role name * Renaming some variables, fixing issue with role w/ no kibana privileges * Throwing decorated general error when appropriate * Fixing test description * Dedent does nothing... * Renaming some functions
- Loading branch information
Showing
22 changed files
with
709 additions
and
240 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* 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 DEFAULT_RESOURCE = 'default'; |
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
3 changes: 3 additions & 0 deletions
3
x-pack/plugins/security/server/lib/authorization/__snapshots__/has_privileges.test.js.snap
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`throws error if missing version privilege and has login privilege 1`] = `"Multiple versions of Kibana are running against the same Elasticsearch cluster, unable to authorize user."`; |
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
55 changes: 55 additions & 0 deletions
55
x-pack/plugins/security/server/lib/authorization/has_privileges.js
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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 { getClient } from '../../../../../server/lib/get_client_shield'; | ||
import { DEFAULT_RESOURCE } from '../../../common/constants'; | ||
import { getVersionPrivilege, getLoginPrivilege } from '../privileges'; | ||
|
||
const getMissingPrivileges = (resource, application, privilegeCheck) => { | ||
const privileges = privilegeCheck.application[application][resource]; | ||
return Object.keys(privileges).filter(key => privileges[key] === false); | ||
}; | ||
|
||
export function hasPrivilegesWithServer(server) { | ||
const callWithRequest = getClient(server).callWithRequest; | ||
|
||
const config = server.config(); | ||
const kibanaVersion = config.get('pkg.version'); | ||
const application = config.get('xpack.security.rbac.application'); | ||
|
||
return function hasPrivilegesWithRequest(request) { | ||
return async function hasPrivileges(privileges) { | ||
|
||
const versionPrivilege = getVersionPrivilege(kibanaVersion); | ||
const loginPrivilege = getLoginPrivilege(); | ||
|
||
const privilegeCheck = await callWithRequest(request, 'shield.hasPrivileges', { | ||
body: { | ||
applications: [{ | ||
application, | ||
resources: [DEFAULT_RESOURCE], | ||
privileges: [versionPrivilege, loginPrivilege, ...privileges] | ||
}] | ||
} | ||
}); | ||
|
||
const success = privilegeCheck.has_all_requested; | ||
const missingPrivileges = getMissingPrivileges(DEFAULT_RESOURCE, application, privilegeCheck); | ||
|
||
// We include the login privilege on all privileges, so the existence of it and not the version privilege | ||
// lets us know that we're running in an incorrect configuration. Without the login privilege check, we wouldn't | ||
// know whether the user just wasn't authorized for this instance of Kibana in general | ||
if (missingPrivileges.includes(versionPrivilege) && !missingPrivileges.includes(loginPrivilege)) { | ||
throw new Error('Multiple versions of Kibana are running against the same Elasticsearch cluster, unable to authorize user.'); | ||
} | ||
|
||
return { | ||
success, | ||
missing: missingPrivileges | ||
}; | ||
}; | ||
}; | ||
} |
Oops, something went wrong.