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

Fix sub-feature privilege "minimumLicense" bug #106008

Merged

Conversation

jportner
Copy link
Contributor

Resolves #105835.

Not labeling this as a bugfix release note, as a bugged version hasn't actually shipped.

jportner added 2 commits July 16, 2021 14:13
We were accidentally comparing license level strings, and we happened to
write unit tests that passed. Changed to compare license level enum
values instead.
Also removes it from the Security plugin's public contracts. This is not
needed anymore, it was only used for the sub-feature privilege iterator.
@jportner jportner added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.15.0 7.14.0 labels Jul 16, 2021
Copy link
Contributor Author

@jportner jportner left a comment

Choose a reason for hiding this comment

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

Author's notes for reviewers

Comment on lines 86 to +90
new KibanaFeature(featureConfig),
{
augmentWithSubFeaturePrivileges: true,
licenseType,
licenseHasAtLeast: (licenseTypeToCheck: LicenseType) =>
LICENSE_TYPE[licenseTypeToCheck] <= LICENSE_TYPE[licenseType],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't love importing LICENSE_TYPE directly from the licensing server for this unit test, but it seemed to be the least-bad option here.

Comment on lines 17 to 33
export const licenseMock = {
create: (features?: Partial<SecurityLicenseFeatures>): jest.Mocked<SecurityLicense> => ({
create: (
features: Partial<SecurityLicenseFeatures> = {},
licenseType: LicenseType = 'basic' // default to basic if this is not specified
): jest.Mocked<SecurityLicense> => ({
isLicenseAvailable: jest.fn().mockReturnValue(true),
isEnabled: jest.fn().mockReturnValue(true),
getType: jest.fn().mockReturnValue('basic'),
getFeatures: jest.fn(),
getFeatures: jest.fn().mockReturnValue(features),
hasAtLeast: jest
.fn()
.mockImplementation(
(licenseTypeToCheck: LicenseType) =>
LICENSE_TYPE[licenseTypeToCheck] <= LICENSE_TYPE[licenseType]
),
features$: features ? of(features as SecurityLicenseFeatures) : of(),
}),
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't love importing LICENSE_TYPE directly from the licensing server for this securityLicenseService mock, but it seemed to be the least-bad option here.

getFeatures(): SecurityLicenseFeatures;
hasAtLeast(licenseType: LicenseType): boolean | undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could coerce this to a boolean but this seemed like a better idea.

Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why you think this is a better idea? The one place we are using this implicitly coerces undefined to false, so it seems that we do want coercion, it's just a matter of where it takes place.

IMO it makes more sense to explicitly coerce here, unless/until we have a need for this return type to be an optional boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getType(), which this supersedes, also returned undefined if the license service wasn't available. Not sure if any other consumers may need to differentiate in the future between "license unavailable" or "minimum license not met". Happy to change it though if you feel explicit coercion is better here, I was a bit on the fence about it anyway.

Copy link
Member

Choose a reason for hiding this comment

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

I don't feel strongly enough to have you change it, I mostly wanted to understand your reasoning. I'm good either way 👍

@legrego legrego marked this pull request as ready for review July 16, 2021 21:26
@legrego legrego requested review from a team as code owners July 16, 2021 21:26
@jportner jportner enabled auto-merge (squash) July 16, 2021 21:32
@jportner jportner added the auto-backport Deprecated - use backport:version if exact versions are needed label Jul 16, 2021
Copy link
Member

@legrego legrego left a comment

Choose a reason for hiding this comment

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

Thanks for the fix - security changes LGTM!

@legrego
Copy link
Member

legrego commented Jul 19, 2021

@elasticmachine merge upstream

Copy link
Contributor

@joshdover joshdover left a comment

Choose a reason for hiding this comment

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

Feature plugin changes LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
security 49 51 +2

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
security 84.8KB 84.8KB +31.0B
Unknown metric groups

API count

id before after diff
security 110 112 +2

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jportner jportner merged commit ea06239 into elastic:master Jul 19, 2021
@jportner jportner deleted the issue-105835-fix-sub-feature-privilege-bug branch July 19, 2021 14:48
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 19, 2021
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Jul 19, 2021
jportner added a commit that referenced this pull request Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes v7.14.0 v7.15.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Role Kibana privileges generate PDF report button is not clickable and API settings not taking effect
5 participants