From 8272438ecd1108ef18a1be13c0c227f32e4d5d9d Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 7 Oct 2021 16:00:34 -0700 Subject: [PATCH] Convert encrypted snapshot license object to LicensedFeature (#78731) This commit moves the encrypted snapshot license checks to use the new LicensedFeature class. --- .../org/elasticsearch/license/XPackLicenseState.java | 2 -- .../repositories/encrypted/EncryptedRepository.java | 4 +++- .../encrypted/EncryptedRepositoryPlugin.java | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java index 1649c2bc6db2a..6bb843110743e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java @@ -52,8 +52,6 @@ public enum Feature { MONITORING_CLUSTER_ALERTS(OperationMode.STANDARD, true), MONITORING_UPDATE_RETENTION(OperationMode.STANDARD, false), - ENCRYPTED_SNAPSHOT(OperationMode.PLATINUM, true), - CCR(OperationMode.PLATINUM, true), MACHINE_LEARNING(OperationMode.PLATINUM, true), diff --git a/x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/EncryptedRepository.java b/x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/EncryptedRepository.java index f7277f91b6572..22a544a1c02cd 100644 --- a/x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/EncryptedRepository.java +++ b/x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/EncryptedRepository.java @@ -59,6 +59,8 @@ import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; +import static org.elasticsearch.repositories.encrypted.EncryptedRepositoryPlugin.ENCRYPTED_SNAPSHOT_FEATURE; + public class EncryptedRepository extends BlobStoreRepository { static final Logger logger = LogManager.getLogger(EncryptedRepository.class); // the following constants are fixed by definition @@ -177,7 +179,7 @@ public RepositoryStats stats() { public Map adaptUserMetadata(Map userMetadata) { // because populating the snapshot metadata must be done before the actual snapshot is first initialized, // we take the opportunity to validate the license and abort if non-compliant - if (false == licenseStateSupplier.get().isAllowed(XPackLicenseState.Feature.ENCRYPTED_SNAPSHOT)) { + if (false == ENCRYPTED_SNAPSHOT_FEATURE.checkWithoutTracking(licenseStateSupplier.get())) { throw LicenseUtils.newComplianceException("encrypted snapshots"); } Map snapshotUserMetadata = new HashMap<>(); diff --git a/x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/EncryptedRepositoryPlugin.java b/x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/EncryptedRepositoryPlugin.java index cf370f2b16b79..0048158bf14a3 100644 --- a/x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/EncryptedRepositoryPlugin.java +++ b/x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/EncryptedRepositoryPlugin.java @@ -21,7 +21,9 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.env.Environment; import org.elasticsearch.indices.recovery.RecoverySettings; +import org.elasticsearch.license.License; import org.elasticsearch.license.LicenseUtils; +import org.elasticsearch.license.LicensedFeature; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.RepositoryPlugin; @@ -40,6 +42,12 @@ public class EncryptedRepositoryPlugin extends Plugin implements RepositoryPlugin { + static final LicensedFeature.Momentary ENCRYPTED_SNAPSHOT_FEATURE = LicensedFeature.momentary( + null, + "encrypted-snapshot", + License.OperationMode.PLATINUM + ); + private static final Boolean ENCRYPTED_REPOSITORY_FEATURE_FLAG_REGISTERED; static { final String property = System.getProperty("es.encrypted_repository_feature_flag_registered"); @@ -154,7 +162,7 @@ public Repository create(RepositoryMetadata metadata, Function