-
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.
Merge branch 'main' into alerting/skip-writing-aad-on-timeout-2
- Loading branch information
Showing
84 changed files
with
1,233 additions
and
1,033 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
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
75 changes: 75 additions & 0 deletions
75
x-pack/plugins/security_solution/common/endpoint/service/authz/authz.test.ts
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,75 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { calculateEndpointAuthz, getEndpointAuthzInitialState } from './authz'; | ||
import { createFleetAuthzMock, FleetAuthz } from '../../../../../fleet/common'; | ||
import { createLicenseServiceMock } from '../../../license/mocks'; | ||
import type { EndpointAuthz } from '../../types/authz'; | ||
|
||
describe('Endpoint Authz service', () => { | ||
let licenseService: ReturnType<typeof createLicenseServiceMock>; | ||
let fleetAuthz: FleetAuthz; | ||
|
||
beforeEach(() => { | ||
licenseService = createLicenseServiceMock(); | ||
fleetAuthz = createFleetAuthzMock(); | ||
}); | ||
|
||
describe('calculateEndpointAuthz()', () => { | ||
describe('and `fleet.all` access is true', () => { | ||
it.each<Array<keyof EndpointAuthz>>([ | ||
['canAccessFleet'], | ||
['canAccessEndpointManagement'], | ||
['canIsolateHost'], | ||
])('should set `%s` to `true`', (authProperty) => { | ||
expect(calculateEndpointAuthz(licenseService, fleetAuthz)[authProperty]).toBe(true); | ||
}); | ||
|
||
it('should set `canIsolateHost` to false if not proper license', () => { | ||
licenseService.isPlatinumPlus.mockReturnValue(false); | ||
|
||
expect(calculateEndpointAuthz(licenseService, fleetAuthz).canIsolateHost).toBe(false); | ||
}); | ||
|
||
it('should set `canUnIsolateHost` to true even if not proper license', () => { | ||
licenseService.isPlatinumPlus.mockReturnValue(false); | ||
|
||
expect(calculateEndpointAuthz(licenseService, fleetAuthz).canUnIsolateHost).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('and `fleet.all` access is false', () => { | ||
beforeEach(() => (fleetAuthz.fleet.all = false)); | ||
|
||
it.each<Array<keyof EndpointAuthz>>([ | ||
['canAccessFleet'], | ||
['canAccessEndpointManagement'], | ||
['canIsolateHost'], | ||
])('should set `%s` to `false`', (authProperty) => { | ||
expect(calculateEndpointAuthz(licenseService, fleetAuthz)[authProperty]).toBe(false); | ||
}); | ||
|
||
it('should set `canUnIsolateHost` to true even if not proper license', () => { | ||
licenseService.isPlatinumPlus.mockReturnValue(false); | ||
|
||
expect(calculateEndpointAuthz(licenseService, fleetAuthz).canUnIsolateHost).toBe(true); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getEndpointAuthzInitialState()', () => { | ||
it('returns expected initial state', () => { | ||
expect(getEndpointAuthzInitialState()).toEqual({ | ||
canAccessFleet: false, | ||
canAccessEndpointManagement: false, | ||
canIsolateHost: false, | ||
canUnIsolateHost: true, | ||
canCreateArtifactsByPolicy: false, | ||
}); | ||
}); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
x-pack/plugins/security_solution/common/endpoint/service/authz/authz.ts
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,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { LicenseService } from '../../../license'; | ||
import { FleetAuthz } from '../../../../../fleet/common'; | ||
import { EndpointAuthz } from '../../types/authz'; | ||
|
||
/** | ||
* Used by both the server and the UI to generate the Authorization for access to Endpoint related | ||
* functionality | ||
* | ||
* @param licenseService | ||
* @param fleetAuthz | ||
*/ | ||
export const calculateEndpointAuthz = ( | ||
licenseService: LicenseService, | ||
fleetAuthz: FleetAuthz | ||
): EndpointAuthz => { | ||
const isPlatinumPlusLicense = licenseService.isPlatinumPlus(); | ||
const hasAllAccessToFleet = fleetAuthz.fleet.all; | ||
|
||
return { | ||
canAccessFleet: hasAllAccessToFleet, | ||
canAccessEndpointManagement: hasAllAccessToFleet, | ||
canCreateArtifactsByPolicy: isPlatinumPlusLicense, | ||
canIsolateHost: isPlatinumPlusLicense && hasAllAccessToFleet, | ||
canUnIsolateHost: true, | ||
}; | ||
}; | ||
|
||
export const getEndpointAuthzInitialState = (): EndpointAuthz => { | ||
return { | ||
canAccessFleet: false, | ||
canAccessEndpointManagement: false, | ||
canCreateArtifactsByPolicy: false, | ||
canIsolateHost: false, | ||
canUnIsolateHost: 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
29 changes: 29 additions & 0 deletions
29
x-pack/plugins/security_solution/common/endpoint/service/authz/mocks.ts
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,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EndpointAuthz } from '../../types/authz'; | ||
import { getEndpointAuthzInitialState } from './authz'; | ||
|
||
export const getEndpointAuthzInitialStateMock = ( | ||
overrides: Partial<EndpointAuthz> = {} | ||
): EndpointAuthz => { | ||
const authz: EndpointAuthz = { | ||
...( | ||
Object.entries(getEndpointAuthzInitialState()) as Array<[keyof EndpointAuthz, boolean]> | ||
).reduce((mockPrivileges, [key, value]) => { | ||
// Invert the initial values (from `false` to `true`) so that everything is authorized | ||
mockPrivileges[key] = !value; | ||
|
||
return mockPrivileges; | ||
}, {} as EndpointAuthz), | ||
// this one is currently treated special in that everyone can un-isolate | ||
canUnIsolateHost: true, | ||
...overrides, | ||
}; | ||
|
||
return authz; | ||
}; |
Oops, something went wrong.