-
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
Deriving application from Kibana index #20614
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ import { checkPrivilegesWithRequestFactory, CHECK_PRIVILEGES_RESULT } from './ch | |
|
||
import { ALL_RESOURCE } from '../../../common/constants'; | ||
|
||
const application = 'kibana-our_application'; | ||
const defaultVersion = 'default-version'; | ||
const defaultApplication = 'default-application'; | ||
const defaultKibanaIndex = 'default-index'; | ||
const savedObjectTypes = ['foo-type', 'bar-type']; | ||
|
||
|
@@ -26,7 +26,6 @@ const createMockConfig = ({ settings = {} } = {}) => { | |
|
||
const defaultSettings = { | ||
'pkg.version': defaultVersion, | ||
'xpack.security.rbac.application': defaultApplication, | ||
'kibana.index': defaultKibanaIndex, | ||
}; | ||
|
||
|
@@ -63,7 +62,7 @@ const checkPrivilegesTest = ( | |
const mockShieldClient = createMockShieldClient({ | ||
username, | ||
application: { | ||
[defaultApplication]: { | ||
[application]: { | ||
[ALL_RESOURCE]: applicationPrivilegesResponse | ||
} | ||
}, | ||
|
@@ -72,7 +71,7 @@ const checkPrivilegesTest = ( | |
}, | ||
}); | ||
|
||
const checkPrivilegesWithRequest = checkPrivilegesWithRequestFactory(mockShieldClient, mockConfig, mockActions); | ||
const checkPrivilegesWithRequest = checkPrivilegesWithRequestFactory(mockShieldClient, mockConfig, mockActions, application); | ||
const request = Symbol(); | ||
const checkPrivileges = checkPrivilegesWithRequest(request); | ||
|
||
|
@@ -88,7 +87,7 @@ const checkPrivilegesTest = ( | |
expect(mockShieldClient.callWithRequest).toHaveBeenCalledWith(request, 'shield.hasPrivileges', { | ||
body: { | ||
applications: [{ | ||
application: defaultApplication, | ||
application: application, | ||
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. uber nit: can simplify to just |
||
resources: [ALL_RESOURCE], | ||
privileges: uniq([ | ||
mockActions.version, mockActions.login, ...privileges | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,11 @@ export function initAuthorizationService(server) { | |
const config = server.config(); | ||
|
||
const actions = actionsFactory(config); | ||
const application = `kibana-${config.get('kibana.index')}`; | ||
|
||
server.expose('authorization', deepFreeze({ | ||
checkPrivilegesWithRequest: checkPrivilegesWithRequestFactory(shieldClient, config, actions), | ||
actions | ||
actions, | ||
application, | ||
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. it's the little things in life, but I like this abstraction 😎 |
||
checkPrivilegesWithRequest: checkPrivilegesWithRequestFactory(shieldClient, config, actions, application), | ||
})); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,12 @@ | |
import { difference, isEmpty, isEqual } from 'lodash'; | ||
import { buildPrivilegeMap } from './privileges'; | ||
import { getClient } from '../../../../../server/lib/get_client_shield'; | ||
import { actionsFactory } from './actions'; | ||
|
||
|
||
|
||
export async function registerPrivilegesWithCluster(server) { | ||
const config = server.config(); | ||
|
||
const actions = actionsFactory(config); | ||
const application = config.get('xpack.security.rbac.application'); | ||
const savedObjectTypes = server.savedObjects.types; | ||
const { authorization } = server.plugins.security; | ||
const { types: savedObjectTypes } = server.savedObjects; | ||
const { actions, application } = authorization; | ||
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. nit: we could simplify the destructuring here by passing 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. I'm gonna leave this alone for now... I really dislike having this dependent on the whole |
||
|
||
const shouldRemovePrivileges = (existingPrivileges, expectedPrivileges) => { | ||
if (isEmpty(existingPrivileges)) { | ||
|
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.
I moved this because the
registerPrivilegesWithCluster
function is now dependent on theserver.plugins.authorization
thatinitAuthorizationService
exposes.