Skip to content
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 Solution] split endpoint rbac feature flags #143991

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ describe('Endpoint Authz service', () => {
});

describe('and endpoint rbac is enabled', () => {
beforeEach(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the outer describe has superuser so we're ensuring this test block doesn't.

userRoles = [];
});

it.each<[EndpointAuthzKeyList[number], string]>([
['canWriteEndpointList', 'writeEndpointList'],
['canReadEndpointList', 'readEndpointList'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ function hasPermission(
hasEndpointManagementAccess: boolean,
privilege: typeof ENDPOINT_PRIVILEGES[number]
): boolean {
return isEndpointRbacEnabled
? fleetAuthz.packagePrivileges?.endpoint?.actions[privilege].executePackageAction ?? false
: hasEndpointManagementAccess;
// user is superuser, always return true
if (hasEndpointManagementAccess) {
return true;
}

// not superuser and FF not enabled, no access
if (!isEndpointRbacEnabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I wrote below, I think we should check here the specific FF depending on the feature.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false;
}

// FF enabled, access based on privileges
return fleetAuthz.packagePrivileges?.endpoint?.actions[privilege].executePackageAction ?? false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export const allowedExperimentalValues = Object.freeze({
*/
endpointRbacEnabled: false,

/**
* Enables endpoint package level rbac for response actions only.
* if endpointRbacEnabled is enabled, it will take precedence.
*/
endpointRbacV1Enabled: false,

/**
* Enables the Guided Onboarding tour in security
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const useEndpointPrivileges = (): Immutable<EndpointPrivileges> => {

const fleetServices = fleetServicesFromUseKibana ?? fleetServicesFromPluginStart;
const isEndpointRbacEnabled = useIsExperimentalFeatureEnabled('endpointRbacEnabled');
const isEndpointRbacV1Enabled = useIsExperimentalFeatureEnabled('endpointRbacV1Enabled');

const endpointPermissions = calculatePermissionsFromCapabilities(
useKibana().services.application.capabilities
Expand All @@ -57,7 +58,7 @@ export const useEndpointPrivileges = (): Immutable<EndpointPrivileges> => {
licenseService,
fleetAuthz,
userRoles,
isEndpointRbacEnabled,
isEndpointRbacEnabled || isEndpointRbacV1Enabled,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add another param here instead of using an OR in the existing one. Doing that, we can check if one or the other is enabled in authz and then use one or the other depending on the feature. For example, I don't want to use privileges for Trusted Apps if only the isEndpointRbacV1Enabled is enabled. Does that make sense?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a use case for this? I purposely didn't want to over engineer it since we have pretty known use cases. since we added FF for the sake of privileges, it feels a bit odd to account for using the FF without privileges. this approach (in conjunction with the changes in authz.ts) controls privileges through the availability of subfeatures. since isEndpointRbacV1Enabled doesn't contain trusted apps subfeature, for example, trusted apps privilege would be false if only isEndpointRbacV1Enabled is enabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think from the change here it will be evaluated if one of both is enabled. So for a user having isEndpointRbacV1Enabled set to true, we will evaluate privileges for Trusted Apps, Event Filters or others. And we should return false as it is not supported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke offline, the control is handled by the change made in features.ts. So we are ok with this! Thanks for the clarification @joeypoon

endpointPermissions
)
: getEndpointAuthzInitialState()),
Expand All @@ -72,6 +73,7 @@ export const useEndpointPrivileges = (): Immutable<EndpointPrivileges> => {
licenseService,
userRoles,
isEndpointRbacEnabled,
isEndpointRbacV1Enabled,
endpointPermissions,
]);

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/security_solution/public/management/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export const getManagementFilteredLinks = async (
plugins: StartPlugins
): Promise<LinkItem> => {
const fleetAuthz = plugins.fleet?.authz;
const isEndpointRbacEnabled = ExperimentalFeaturesService.get().endpointRbacEnabled;
const { endpointRbacEnabled, endpointRbacV1Enabled } = ExperimentalFeaturesService.get();
const endpointPermissions = calculatePermissionsFromCapabilities(core.application.capabilities);
const linksToExclude: SecurityPageName[] = [];

Expand All @@ -255,7 +255,7 @@ export const getManagementFilteredLinks = async (
licenseService,
fleetAuthz,
currentUserResponse.roles,
isEndpointRbacEnabled,
endpointRbacEnabled || endpointRbacV1Enabled,
endpointPermissions
)
: getEndpointAuthzInitialState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class EndpointAppContextService {
public async getEndpointAuthz(request: KibanaRequest): Promise<EndpointAuthz> {
const fleetAuthz = await this.getFleetAuthzService().fromRequest(request);
const userRoles = this.security?.authc.getCurrentUser(request)?.roles ?? [];
const isEndpointRbacEnabled = this.experimentalFeatures.endpointRbacEnabled;
const { endpointRbacEnabled, endpointRbacV1Enabled } = this.experimentalFeatures;

let endpointPermissions = defaultEndpointPermissions();
if (this.security) {
Expand All @@ -185,7 +185,7 @@ export class EndpointAppContextService {
this.getLicenseService(),
fleetAuthz,
userRoles,
isEndpointRbacEnabled,
endpointRbacEnabled || endpointRbacV1Enabled,
endpointPermissions
);
}
Expand Down
Loading