-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Security - Role Mappings UI #53620
Security - Role Mappings UI #53620
Changes from 9 commits
17d77c9
cf89a36
04309cf
333bfe6
ed90d8f
3c75347
459a0c3
2319f0d
8899b1c
f0145af
6272cec
55b0041
31596d3
db85d63
5efd7ab
e55b99d
357ceee
8e3e795
dc50382
85fe0e3
1f9cbeb
3ed9321
47c95ef
8abfda4
36fb2cb
c8d21b6
c4bb9d3
041099e
c8c0ecc
a6918e3
ab20b17
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import axios, { AxiosInstance } from 'axios'; | ||
import util from 'util'; | ||
import { ToolingLog } from '@kbn/dev-utils'; | ||
|
||
export class RoleMappings { | ||
private log: ToolingLog; | ||
private axios: AxiosInstance; | ||
|
||
constructor(url: string, log: ToolingLog) { | ||
this.log = log; | ||
this.axios = axios.create({ | ||
headers: { 'kbn-xsrf': 'x-pack/ftr/services/security/role_mappings' }, | ||
baseURL: url, | ||
maxRedirects: 0, | ||
validateStatus: () => true, // we do our own validation below and throw better error messages | ||
}); | ||
} | ||
|
||
public async create(name: string, roleMapping: Record<string, any>) { | ||
this.log.debug(`creating role mapping ${name}`); | ||
const { data, status, statusText } = await this.axios.post( | ||
`/internal/security/role_mapping/${name}`, | ||
roleMapping | ||
); | ||
if (status !== 200) { | ||
throw new Error( | ||
`Expected status code of 200, received ${status} ${statusText}: ${util.inspect(data)}` | ||
); | ||
} | ||
this.log.debug(`created role mapping ${name}`); | ||
} | ||
|
||
public async delete(name: string) { | ||
this.log.debug(`deleting role mapping ${name}`); | ||
const { data, status, statusText } = await this.axios.delete( | ||
`/internal/security/role_mapping/${name}` | ||
); | ||
if (status !== 200 && status !== 404) { | ||
throw new Error( | ||
`Expected status code of 200 or 404, received ${status} ${statusText}: ${util.inspect( | ||
data | ||
)}` | ||
); | ||
} | ||
this.log.debug(`deleted role mapping ${name}`); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,5 @@ export { | |
canUserChangePassword, | ||
getUserDisplayName, | ||
} from '../../../../plugins/security/common/model'; | ||
|
||
export * from './role_mapping'; | ||
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. question: All of the other models have been moved to the NP, any reason to keep this one in the LP? 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. Nope, Iβll move these to the NP. I started this so long ago that this wasnβt originally the case |
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. | ||
*/ | ||
|
||
interface RoleMappingAnyRule { | ||
any: RoleMappingRule[]; | ||
} | ||
|
||
interface RoleMappingAllRule { | ||
all: RoleMappingRule[]; | ||
} | ||
|
||
interface RoleMappingFieldRule { | ||
field: Record<string, any>; | ||
} | ||
|
||
interface RoleMappingExceptRule { | ||
except: RoleMappingRule; | ||
} | ||
|
||
type RoleMappingRule = | ||
| RoleMappingAnyRule | ||
| RoleMappingAllRule | ||
| RoleMappingFieldRule | ||
| RoleMappingExceptRule; | ||
|
||
type RoleTemplateFormat = 'string' | 'json'; | ||
|
||
export interface InlineRoleTemplate { | ||
template: { source: string }; | ||
format?: RoleTemplateFormat; | ||
} | ||
|
||
export interface StoredRoleTemplate { | ||
template: { id: string }; | ||
format?: RoleTemplateFormat; | ||
} | ||
|
||
export interface InvalidRoleTemplate { | ||
template: string; | ||
format?: RoleTemplateFormat; | ||
} | ||
|
||
export type RoleTemplate = InlineRoleTemplate | StoredRoleTemplate | InvalidRoleTemplate; | ||
|
||
export interface RoleMapping { | ||
name: string; | ||
enabled: boolean; | ||
roles?: string[]; | ||
role_templates?: RoleTemplate[]; | ||
rules: RoleMappingRule | {}; | ||
metadata: Record<string, any>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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 { CoreSetup } from 'src/core/public'; | ||
import { RoleMapping } from '../../common/model'; | ||
|
||
interface CheckPrivilegesResponse { | ||
canManageRoleMappings: boolean; | ||
canUseInlineScripts: boolean; | ||
canUseStoredScripts: boolean; | ||
hasCompatibleRealms: boolean; | ||
} | ||
|
||
type DeleteRoleMappingsResponse = Array<{ | ||
name: string; | ||
success: boolean; | ||
error?: Error; | ||
}>; | ||
|
||
export class RoleMappingsAPI { | ||
constructor(private readonly http: CoreSetup['http']) {} | ||
|
||
public async getRoleMappingFeatures(): Promise<CheckPrivilegesResponse> { | ||
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 have three rather different namings going on here: 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. Resolved in f0145af |
||
return this.http.get(`/internal/security/role_mapping_feature_check`); | ||
} | ||
|
||
public async getRoleMappings(): Promise<RoleMapping[]> { | ||
return this.http.get(`/internal/security/role_mapping`); | ||
} | ||
|
||
public async getRoleMapping(name: string): Promise<RoleMapping> { | ||
return this.http.get(`/internal/security/role_mapping/${encodeURIComponent(name)}`); | ||
} | ||
|
||
public async saveRoleMapping(roleMapping: RoleMapping) { | ||
const payload = { ...roleMapping }; | ||
delete payload.name; | ||
|
||
return this.http.post( | ||
`/internal/security/role_mapping/${encodeURIComponent(roleMapping.name)}`, | ||
{ body: JSON.stringify(payload) } | ||
); | ||
} | ||
|
||
public async deleteRoleMappings(names: string[]): Promise<DeleteRoleMappingsResponse> { | ||
return Promise.all( | ||
names.map(name => | ||
this.http | ||
.delete(`/internal/security/role_mapping/${encodeURIComponent(name)}`) | ||
.then(() => ({ success: true, name })) | ||
.catch(error => ({ success: false, name, error })) | ||
) | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@import './change_password_form/index'; | ||
@import './edit_role/index'; | ||
@import './edit_user/index'; | ||
@import './edit_user/index'; | ||
@import './role_mappings/edit_role_mapping/index'; |
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.
@spalger moving the functional testing security service to OSS now requires us to put the
RoleMappings
service here as well, or introduce a new service... π’