-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Add setting to restrict license types #49418
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0d178d8
Add setting to restrict license types
tvernum c7bebd9
Merge branch 'master' into restrict-license-type
tvernum b08cde5
Fix resolution of v1 style licenses
tvernum c42b309
Merge branch 'master' into restrict-license-type
tvernum 0098f8e
Address feedback
tvernum 3f76e49
Merge branch 'master' into restrict-license-type
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,9 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste | |
return SelfGeneratedLicense.validateSelfGeneratedType(type); | ||
}, Setting.Property.NodeScope); | ||
|
||
public static final Setting<List<License.LicenseType>> ALLOWED_LICENSE_TYPES = Setting.listSetting("xpack.license.upload.types", | ||
License.LicenseType.ALL_TYPE_NAMES, License.LicenseType::parse, Setting.Property.NodeScope); | ||
|
||
// pkg private for tests | ||
static final TimeValue NON_BASIC_SELF_GENERATED_LICENSE_DURATION = TimeValue.timeValueHours(30 * 24); | ||
|
||
|
@@ -104,6 +107,12 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste | |
*/ | ||
private List<ExpirationCallback> expirationCallbacks = new ArrayList<>(); | ||
|
||
/** | ||
* Which license types are permitted to be uploaded to the cluster | ||
* @see #ALLOWED_LICENSE_TYPES | ||
*/ | ||
private final List<License.LicenseType> allowedLicenseTypes; | ||
|
||
/** | ||
* Max number of nodes licensed by generated trial license | ||
*/ | ||
|
@@ -123,6 +132,7 @@ public LicenseService(Settings settings, ClusterService clusterService, Clock cl | |
this.clock = clock; | ||
this.scheduler = new SchedulerEngine(settings, clock); | ||
this.licenseState = licenseState; | ||
this.allowedLicenseTypes = ALLOWED_LICENSE_TYPES.get(settings); | ||
this.operationModeFileWatcher = new OperationModeFileWatcher(resourceWatcherService, | ||
XPackPlugin.resolveConfigFile(env, "license_mode"), logger, | ||
() -> updateLicenseState(getLicensesMetaData())); | ||
|
@@ -193,11 +203,21 @@ public void on(License license) { | |
*/ | ||
public void registerLicense(final PutLicenseRequest request, final ActionListener<PutLicenseResponse> listener) { | ||
final License newLicense = request.license(); | ||
final License.LicenseType licenseType; | ||
try { | ||
licenseType = License.LicenseType.resolve(newLicense); | ||
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. We should not consume any part of the license before we validate its signature first |
||
} catch (Exception e) { | ||
listener.onFailure(e); | ||
return; | ||
} | ||
final long now = clock.millis(); | ||
if (!LicenseVerifier.verifyLicense(newLicense) || newLicense.issueDate() > now || newLicense.startDate() > now) { | ||
listener.onResponse(new PutLicenseResponse(true, LicensesStatus.INVALID)); | ||
} else if (newLicense.type().equals(License.LicenseType.BASIC.getTypeName())) { | ||
} else if (licenseType == License.LicenseType.BASIC) { | ||
listener.onFailure(new IllegalArgumentException("Registering basic licenses is not allowed.")); | ||
} else if (isAllowedLicenseType(licenseType) == false) { | ||
listener.onFailure(new IllegalArgumentException( | ||
"Registering [" + licenseType.getTypeName() + "] licenses is not allowed on this cluster")); | ||
} else if (newLicense.expiryDate() < now) { | ||
listener.onResponse(new PutLicenseResponse(true, LicensesStatus.EXPIRED)); | ||
} else { | ||
|
@@ -272,6 +292,11 @@ private static boolean licenseIsCompatible(License license, Version version) { | |
} | ||
} | ||
|
||
private boolean isAllowedLicenseType(License.LicenseType type) { | ||
logger.debug("Checking license [{}] against allowed license types: {}", type, allowedLicenseTypes); | ||
return allowedLicenseTypes.contains(type); | ||
} | ||
|
||
public static Map<String, String[]> getAckMessages(License newLicense, License currentLicense) { | ||
Map<String, String[]> acknowledgeMessages = new HashMap<>(); | ||
if (!License.isAutoGeneratedLicense(currentLicense.signature()) // current license is not auto-generated | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We do handle basic explicitly in all places, but should we exclude it from the default value of
xpack.license.upload.types
too ?