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

Encrypted blob store repository #50846

Closed
Show file tree
Hide file tree
Changes from 155 commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
92a3b34
Polished main
albertzaharovits Nov 30, 2019
d07c05f
First successful tests
albertzaharovits Dec 1, 2019
de603a7
More tests
albertzaharovits Dec 1, 2019
7cc62e0
More tests
albertzaharovits Dec 1, 2019
cbd3c50
BufferOnMarkInputStreamBug
albertzaharovits Dec 1, 2019
9eb9bcf
A few bugs...
albertzaharovits Dec 2, 2019
5919a11
BufferOnMark bug
albertzaharovits Dec 2, 2019
47f6aea
More more more bugs!
albertzaharovits Dec 2, 2019
8263062
Mad tests
albertzaharovits Dec 3, 2019
cf97ba2
Manic testing
albertzaharovits Dec 3, 2019
3c82ba9
BufferOnMarkInputStreamTests completed
albertzaharovits Dec 4, 2019
76d8271
Checkstyle
albertzaharovits Dec 4, 2019
6b30902
Merge branch 'repository-encrypted-client-side' into packet-based-cip…
albertzaharovits Dec 4, 2019
4e9778e
BufferOnMarkInputStream javadocs
albertzaharovits Dec 5, 2019
24d6d27
merge fallout
albertzaharovits Dec 5, 2019
3cd79bd
PrefixInputStream tests
albertzaharovits Dec 5, 2019
c610fe8
WIP
albertzaharovits Dec 5, 2019
e4f8564
CountingInputStreamTests
albertzaharovits Dec 5, 2019
c816c45
Renaming and more javadocs
albertzaharovits Dec 5, 2019
29c484b
Refactor ChainingInputStream
albertzaharovits Dec 5, 2019
db5f58e
Scarce EncryptionPacketsInputStream javadocs
albertzaharovits Dec 6, 2019
d6dc875
ChainingInputStream polishing and tests
albertzaharovits Dec 8, 2019
7cb48f6
ChainingInputStreamTests
albertzaharovits Dec 8, 2019
83e028b
ChainingInputStreamTests without mark/reset
albertzaharovits Dec 9, 2019
26a624f
ChainingInputStreamTests mark/reset
albertzaharovits Dec 9, 2019
aeb6698
More tests
albertzaharovits Dec 9, 2019
2939289
WIP
albertzaharovits Dec 10, 2019
76678a6
DecryptionPacketsInputStream tests
albertzaharovits Dec 10, 2019
f44b97c
Tests done!
albertzaharovits Dec 10, 2019
016164a
More javadocs
albertzaharovits Dec 10, 2019
5b26ff6
Merge branch 'repository-encrypted-client-side' into packet-based-cip…
albertzaharovits Dec 18, 2019
bae9a8d
Repository and plugin, WIP
albertzaharovits Dec 19, 2019
80a079b
Mhm, needs bc-jar
albertzaharovits Dec 19, 2019
0a4cc77
WIP how to prevent multiple repositories with different passwords
albertzaharovits Dec 20, 2019
a0751c6
Update x-pack/plugin/repository-encrypted/src/main/java/org/elasticse…
albertzaharovits Dec 23, 2019
92e177f
Update x-pack/plugin/repository-encrypted/src/main/java/org/elasticse…
albertzaharovits Dec 23, 2019
5d9321a
Update x-pack/plugin/repository-encrypted/src/main/java/org/elasticse…
albertzaharovits Dec 23, 2019
c231486
Tim's review WIP
albertzaharovits Dec 25, 2019
bda96b6
ChainingInputStream javadocs
albertzaharovits Dec 25, 2019
cb6006d
Logging on component close
albertzaharovits Dec 25, 2019
fad9eb4
Merge branch 'repository-encrypted-client-side' into packet-based-cip…
albertzaharovits Dec 25, 2019
65f0adb
Nit
albertzaharovits Dec 25, 2019
b40d999
No Randomness in ChainingInputStreamTests
albertzaharovits Dec 26, 2019
cb7bc1c
Update x-pack/plugin/repository-encrypted/src/test/java/org/elasticse…
albertzaharovits Dec 26, 2019
7acaf54
Tim's review WIP before mark/reset review
albertzaharovits Dec 27, 2019
dfeea83
Almost WIP
albertzaharovits Dec 27, 2019
da29e2f
Review complete
albertzaharovits Dec 28, 2019
8c465be
Merge branch 'packet-based-cipherstream-2' into encrypted-blob-store
albertzaharovits Dec 29, 2019
bed1e51
Merge fallout
albertzaharovits Dec 29, 2019
5e7269b
Update x-pack/plugin/repository-encrypted/src/main/java/org/elasticse…
albertzaharovits Dec 30, 2019
14ee4aa
IV position
albertzaharovits Dec 30, 2019
7ee63c0
Update x-pack/plugin/repository-encrypted/src/main/java/org/elasticse…
albertzaharovits Dec 30, 2019
74f38b2
move mark supported before mark/reset implementations
albertzaharovits Dec 30, 2019
fee2d79
Package-protected instead of protected for final classes
albertzaharovits Dec 30, 2019
eda1fe0
RemainingPrefixByteCount
albertzaharovits Dec 30, 2019
e85aefe
Update x-pack/plugin/repository-encrypted/src/main/java/org/elasticse…
albertzaharovits Dec 30, 2019
8a0773a
no iv instance variable
albertzaharovits Dec 30, 2019
07d7ac8
Nit
albertzaharovits Dec 30, 2019
fd10914
Exception messages
albertzaharovits Dec 30, 2019
2e41d4f
Fix tests with exception names
albertzaharovits Dec 30, 2019
97f5917
Test for reader of fewer bytes
albertzaharovits Dec 30, 2019
4fd6dcc
Adjust counting input stream docs
albertzaharovits Dec 30, 2019
3d1daf4
RingBuffer
albertzaharovits Dec 31, 2019
4fcd49d
WIP
albertzaharovits Dec 31, 2019
9ef136e
WIP
albertzaharovits Dec 31, 2019
cb966b2
More javadoc to the ring buffer inner
albertzaharovits Jan 1, 2020
0f9f77c
Small test polishing
albertzaharovits Jan 1, 2020
5924356
Merge branch 'packet-based-cipherstream-2' into encrypted-blob-store
albertzaharovits Jan 1, 2020
3cf85b4
Encryption without CMS
albertzaharovits Jan 5, 2020
151b248
Javadoc
albertzaharovits Jan 5, 2020
7d1b3cc
Snapshot works
albertzaharovits Jan 5, 2020
31a2b30
Remove bouncy castle dependency
albertzaharovits Jan 6, 2020
591e48c
Password based metadata encryptor
albertzaharovits Jan 7, 2020
1ee490a
Proper reordering of the two writes
albertzaharovits Jan 7, 2020
5a1eee5
License check
albertzaharovits Jan 7, 2020
e51a304
Ooops metadata decrypt logic flaw
albertzaharovits Jan 7, 2020
1087294
License and consistent
albertzaharovits Jan 8, 2020
b788e98
Consistent Secure Settings reshuffle
albertzaharovits Jan 8, 2020
4e204a3
Consistency check
albertzaharovits Jan 8, 2020
3248163
Cleanup WIP
albertzaharovits Jan 9, 2020
f1406ff
Renames and nits
albertzaharovits Jan 10, 2020
78c1984
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Jan 10, 2020
2565d6e
Checkstyle
albertzaharovits Jan 10, 2020
2c40aad
Consistency check on create snapshot
albertzaharovits Jan 13, 2020
db374fb
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Jan 14, 2020
f73b54c
More javadocs for PasswordBasedEncryptor
albertzaharovits Jan 14, 2020
36062db
EncryptedRepository#restoreShard logging
albertzaharovits Jan 15, 2020
677bbb7
Verify check
albertzaharovits Jan 15, 2020
d2133e0
Err msg nits
albertzaharovits Jan 20, 2020
6353f7a
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Jan 20, 2020
a26b2b9
Revert SnapshotsService
albertzaharovits Jan 20, 2020
948b3c6
PasswordBasedEncryptor javadoc
albertzaharovits Jan 20, 2020
83c0e44
Revert Consistent Settings check changes
albertzaharovits Jan 22, 2020
da10d0a
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Jan 28, 2020
0a14765
Rename xpack license test method to reflect that only encr snapshot are
albertzaharovits Jan 29, 2020
6d562fc
Nits
albertzaharovits Jan 29, 2020
bceda55
Authenticated metadata
albertzaharovits Jan 30, 2020
eeac0b5
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Jan 30, 2020
29fa2aa
Fix all compilation errors
albertzaharovits Jan 31, 2020
bb33045
Prepend name of the metadata to the encrypted blob
albertzaharovits Feb 2, 2020
0308140
Nits
albertzaharovits Feb 3, 2020
d7e400c
Before rewriting cleanup
albertzaharovits Feb 3, 2020
8751c7d
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Feb 3, 2020
90bcaab
Refactor delete + cleanup
albertzaharovits Feb 4, 2020
57ab5ad
BlobEncryptionMetadata getInt bug
albertzaharovits Feb 4, 2020
5d9d4c1
Fix delete and cleanup for unknown metadata
albertzaharovits Feb 4, 2020
03a58ed
Try make custom metadata not display to user
albertzaharovits Feb 4, 2020
3ee957d
Fix children
albertzaharovits Feb 4, 2020
82e8a89
missing encryption metadata handling
albertzaharovits Feb 5, 2020
b994d28
Checkstyle
albertzaharovits Feb 6, 2020
2e14453
Checkstyle
albertzaharovits Feb 6, 2020
19fe147
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Feb 11, 2020
4aaf895
writeSnapshotIndexLatestBlob
albertzaharovits Feb 11, 2020
8a9fe5d
Write index.latest un-encrypted
albertzaharovits Feb 11, 2020
80e536c
Keep all metadata blobs until the data blob is deleted
albertzaharovits Feb 11, 2020
60c4ad9
IntegTests in progress
albertzaharovits Feb 12, 2020
7953174
Yey! EncryptedFS tests!!!
albertzaharovits Feb 13, 2020
9f7f4b4
Trimmings
albertzaharovits Feb 14, 2020
19a7828
checkstyle
albertzaharovits Feb 14, 2020
63c6855
invert stale-surviving semantics
albertzaharovits Feb 15, 2020
b593d66
Cleanup WIP
albertzaharovits Feb 16, 2020
30d4f58
Revert "invert stale-surviving semantics"
albertzaharovits Feb 16, 2020
1745345
BlobStoreRepository reshuffle stale root blobs and indices
albertzaharovits Feb 16, 2020
68b9235
Revert "BlobStoreRepository reshuffle stale root blobs and indices"
albertzaharovits Feb 17, 2020
74c3d58
Revert "Cleanup WIP"
albertzaharovits Feb 17, 2020
1889aba
Append repository generation to metadata blob name
albertzaharovits Feb 17, 2020
3d82aa4
deleteBlobsIgnoringIfNotExists refactor for new metadata blob name
albertzaharovits Feb 18, 2020
b085c12
nothing
albertzaharovits Feb 18, 2020
901b04a
cleanUnreferencedEncryptionMetadata
albertzaharovits Feb 18, 2020
0ba402a
Refactor cleanup for the new metadata name
albertzaharovits Feb 18, 2020
0d7077d
Cleanup verify readonly
albertzaharovits Feb 19, 2020
1b0d732
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Feb 19, 2020
6cf5812
RepositoryMetaVersion from merge
albertzaharovits Feb 19, 2020
9e8001b
checkstyle
albertzaharovits Feb 19, 2020
7ffaefb
Test nit
albertzaharovits Feb 20, 2020
950686f
Encrypted GCS
albertzaharovits Feb 20, 2020
710ef33
Encrypted Azure WIP
albertzaharovits Feb 20, 2020
b88ec6d
Prepending meta id is WRONG!
albertzaharovits Feb 20, 2020
426bd05
ChainingInputStream#chain fixes EncryptedAzureBlobStoreRepository
albertzaharovits Feb 21, 2020
6936339
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Feb 21, 2020
10e84d3
License code after refactor
albertzaharovits Feb 21, 2020
94b3847
EncryptedS3BlobStoreRepositoryIntegTests and MockHttpServer
albertzaharovits Feb 23, 2020
6708354
Nit
albertzaharovits Feb 23, 2020
12a074b
bad logger
albertzaharovits Feb 23, 2020
a8c931c
ESMockAPIBasedRepositoryIntegTestCase Executor Service
albertzaharovits Feb 24, 2020
ffe0b63
Explain that readBlob requires two concurrent connections
albertzaharovits Feb 24, 2020
28dd9e1
Add EncryptedRepository#getEncryptedBlobByteLength
albertzaharovits Feb 25, 2020
b9ba309
Log unrecognized blobs during cleanup
albertzaharovits Feb 25, 2020
ef4c860
Fix EncryptedRepository#cleanup bug
albertzaharovits Feb 25, 2020
40fa0eb
Add EncryptedGoogleCloudStorageThirdPartyTests
albertzaharovits Feb 25, 2020
b7e140c
use ThreadPool#terminate in ESMockAPIBasedRepository...
albertzaharovits Feb 25, 2020
fe505e5
Revert to wrapping the HTTP IO executor executor in
albertzaharovits Feb 25, 2020
8e036f0
Use IOUtils.close
albertzaharovits Feb 25, 2020
262b3e9
Refactor validateRepositoryPasswordHash
albertzaharovits Feb 25, 2020
a7e2dac
Log password validation exceptions
albertzaharovits Feb 25, 2020
62c1566
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Mar 5, 2020
83031ae
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Mar 5, 2020
d81d20a
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Mar 5, 2020
856cfe3
BlobPathTests
albertzaharovits Mar 5, 2020
bcc42df
Merge branch 'repository-encrypted-client-side' into encrypted-blob-s…
albertzaharovits Mar 10, 2020
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
2 changes: 2 additions & 0 deletions plugins/repository-azure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ dependencies {
compile 'com.google.guava:guava:20.0'
compile 'org.apache.commons:commons-lang3:3.4'
testCompile project(':test:fixtures:azure-fixture')
// required by the test for the encrypted Azure repository
testCompile project(path: ':x-pack:plugin:repository-encrypted', configuration: 'testArtifacts')
}

dependencyLicenses {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,20 @@ protected HttpHandler createErroneousHttpHandler(final HttpHandler delegate) {

@Override
protected Settings nodeSettings(int nodeOrdinal) {
final String endpoint = "ignored;DefaultEndpointsProtocol=http;BlobEndpoint=" + httpServerUrl();
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(AzureStorageSettings.ENDPOINT_SUFFIX_SETTING.getConcreteSettingForNamespace("test").getKey(), endpoint)
.setSecureSettings(nodeSecureSettings(nodeOrdinal))
.build();
}

protected MockSecureSettings nodeSecureSettings(int nodeOrdinal) {
MockSecureSettings secureSettings = new MockSecureSettings();
final String key = Base64.getEncoder().encodeToString(randomAlphaOfLength(10).getBytes(StandardCharsets.UTF_8));
final MockSecureSettings secureSettings = new MockSecureSettings();
secureSettings.setString(AzureStorageSettings.ACCOUNT_SETTING.getConcreteSettingForNamespace("test").getKey(), "account");
secureSettings.setString(AzureStorageSettings.KEY_SETTING.getConcreteSettingForNamespace("test").getKey(), key);

final String endpoint = "ignored;DefaultEndpointsProtocol=http;BlobEndpoint=" + httpServerUrl();
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(AzureStorageSettings.ENDPOINT_SUFFIX_SETTING.getConcreteSettingForNamespace("test").getKey(), endpoint)
.setSecureSettings(secureSettings)
.build();
return secureSettings;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.repositories.azure;

import org.elasticsearch.common.blobstore.BlobMetaData;
import org.elasticsearch.common.settings.MockSecureSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.license.License;
import org.elasticsearch.license.LicenseService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.repositories.blobstore.BlobStoreRepository;
import org.elasticsearch.repositories.encrypted.DecryptionPacketsInputStream;
import org.elasticsearch.repositories.encrypted.EncryptedRepository;
import org.elasticsearch.repositories.encrypted.EncryptedRepositoryPlugin;
import org.elasticsearch.repositories.encrypted.LocalStateEncryptedRepositoryPlugin;
import org.elasticsearch.test.ESTestCase;
import org.junit.BeforeClass;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class EncryptedAzureBlobStoreRepositoryIntegTests extends AzureBlobStoreRepositoryTests {

private static List<String> repositoryNames;

@BeforeClass
private static void preGenerateRepositoryNames() {
List<String> names = new ArrayList<>();
for (int i = 0; i < 32; i++) {
names.add("test-repo-" + i);
}
repositoryNames = Collections.synchronizedList(names);
Copy link
Member

Choose a reason for hiding this comment

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

Doe this list have to be synchronized? No right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does, because the test methods in the class can run in parallel and there should not be two tests that use the same repository.

Copy link
Member

Choose a reason for hiding this comment

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

Nah I don't think we can have two test methods from the same class run concurrently in the same JVM. How would that work with the single static reference to the internal node/cluster and its cleanup after every test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, I don't know what made me believe otherwise.

}

@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), License.LicenseType.TRIAL.getTypeName())
.build();
}

@Override
protected MockSecureSettings nodeSecureSettings(int nodeOrdinal) {
MockSecureSettings secureSettings = super.nodeSecureSettings(nodeOrdinal);
for (String repositoryName : repositoryNames) {
secureSettings.setString(EncryptedRepositoryPlugin.ENCRYPTION_PASSWORD_SETTING.
getConcreteSettingForNamespace(repositoryName).getKey(), "password" + repositoryName);
}
return secureSettings;
}

@Override
protected String randomRepositoryName() {
return repositoryNames.remove(randomIntBetween(0, repositoryNames.size() - 1));
}

protected long blobLengthFromDiskLength(BlobMetaData blobMetaData) {
if (BlobStoreRepository.INDEX_LATEST_BLOB.equals(blobMetaData.name())) {
// index.latest is not encrypted, hence the size on disk is equal to the content
return blobMetaData.length();
} else {
return DecryptionPacketsInputStream.getDecryptionLength(blobMetaData.length() -
EncryptedRepository.MetadataIdentifier.byteLength(), EncryptedRepository.PACKET_LENGTH_IN_BYTES);
}
}

@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Arrays.asList(LocalStateEncryptedRepositoryPlugin.class, TestAzureRepositoryPlugin.class);
}

@Override
protected String repositoryType() {
return EncryptedRepositoryPlugin.REPOSITORY_TYPE_NAME;
}

@Override
protected Settings repositorySettings() {
final Settings.Builder settings = Settings.builder();
settings.put(super.repositorySettings());
settings.put(EncryptedRepositoryPlugin.DELEGATE_TYPE.getKey(), AzureRepository.TYPE);
if (ESTestCase.randomBoolean()) {
long size = 1 << ESTestCase.randomInt(10);
settings.put("chunk_size", new ByteSizeValue(size, ByteSizeUnit.KB));
}
return settings.build();
}
}
2 changes: 2 additions & 0 deletions plugins/repository-gcs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ dependencies {
compile 'com.google.apis:google-api-services-storage:v1-rev20190426-1.28.0'

testCompile project(':test:fixtures:gcs-fixture')
// required by the test for the encrypted GCS repository
testCompile project(path: ':x-pack:plugin:repository-encrypted', configuration: 'testArtifacts')
Copy link
Member

Choose a reason for hiding this comment

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

I'm not the right person to judge this but this pattern in the build seems troubling to me. We are using non-Apache licensed code in the tests of Apache licensed code now. Is that ok? Maybe it's better to run these tests in a separate module downstream?
You are definitely using this dependency in Apache licensed files, this seems wrong.

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 discussed this synchronously, and also the tests requiring this might not be relevant anymore, but I'm presenting my counter for posterity

I see your point, and I didn't look at it like this. I had minor qualms about having tests for non-Apache licensed code as Apache licensed. The fact that we pull non-Apache test artifacts is a slightly different point.
But, I tend to dismiss the Apache purists that get offended if the tests require an artifact dependency which is not Apache licensed. It feels squarely like a mean-intending exaggeration; If we don't publish the tests jar, they should not even notice.

When I went on this path, I worried that the reverse alternative (having the encrypted repo depend in tests on the cloud repository) would entail more project setup boilerplate code. I'm not so sure about it right now, and I think it is beneficial if we keep these tests inside the encrypted-repo module, for subjective reasons of code organization.

}

dependencyLicenses {
Expand Down
8 changes: 8 additions & 0 deletions plugins/repository-gcs/qa/google-cloud-storage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ apply plugin: 'elasticsearch.test.fixtures'
// TODO think about flattening qa:google-cloud-storage project into parent
dependencies {
testCompile project(path: ':plugins:repository-gcs')
// required by the third-party test for the encrypted GCS repository
testCompile project(path: ':x-pack:plugin:repository-encrypted')
testCompile project(path: ':x-pack:plugin:core')
}

testFixtures.useFixture(':test:fixtures:gcs-fixture')
Expand Down Expand Up @@ -101,6 +104,7 @@ task thirdPartyTest(type: Test) {
}

include '**/GoogleCloudStorageThirdPartyTests.class'
include '**/EncryptedGoogleCloudStorageThirdPartyTests.class'
systemProperty 'tests.security.manager', false
systemProperty 'test.google.bucket', gcsBucket
systemProperty 'test.google.base', gcsBasePath + "_third_party_tests_" + BuildParams.testSeed
Expand All @@ -126,10 +130,14 @@ processTestResources {

integTest {
dependsOn project(':plugins:repository-gcs').bundlePlugin
dependsOn project(':x-pack:plugin:core').bundlePlugin
dependsOn project(':x-pack:plugin:repository-encrypted').bundlePlugin
}

testClusters.integTest {
plugin file(project(':plugins:repository-gcs').bundlePlugin.archiveFile)
plugin file(project(':x-pack:plugin:core').bundlePlugin.archiveFile)
plugin file(project(':x-pack:plugin:repository-encrypted').bundlePlugin.archiveFile)

keystore 'gcs.client.integration_test.credentials_file', serviceAccountFile, IGNORE_VALUE

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.repositories.gcs;

import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.common.blobstore.BlobMetaData;
import org.elasticsearch.common.blobstore.BlobPath;
import org.elasticsearch.common.settings.MockSecureSettings;
import org.elasticsearch.common.settings.SecureSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.repositories.encrypted.EncryptedRepository;
import org.elasticsearch.repositories.encrypted.EncryptedRepositoryPlugin;
import org.elasticsearch.xpack.core.XPackPlugin;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.Matchers.equalTo;

public class EncryptedGoogleCloudStorageThirdPartyTests extends GoogleCloudStorageThirdPartyTests {

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return pluginList(XPackPlugin.class, EncryptedRepositoryPlugin.class, GoogleCloudStoragePlugin.class);
}

@Override
protected Settings nodeSettings() {
return Settings.builder()
.put(super.nodeSettings())
.put("xpack.license.self_generated.type", "trial")
.build();
}

@Override
protected SecureSettings credentials() {
MockSecureSettings secureSettings = (MockSecureSettings) super.credentials();
secureSettings.setString(EncryptedRepositoryPlugin.ENCRYPTION_PASSWORD_SETTING.
getConcreteSettingForNamespace("test-encrypted-repo").getKey(), "password-test-repo");
return secureSettings;
}

@Override
protected void createRepository(final String repoName) {
AcknowledgedResponse putRepositoryResponse = client().admin().cluster()
.preparePutRepository("test-encrypted-repo")
.setType("encrypted")
.setSettings(Settings.builder()
.put("delegate_type", "gcs")
.put("bucket", System.getProperty("test.google.bucket"))
.put("base_path", System.getProperty("test.google.base", "")
+ "/" + EncryptedGoogleCloudStorageThirdPartyTests.class.getName() )
).get();
assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
}

@Override
protected void assertCleanupResponse(CleanupRepositoryResponse response, long bytes, long blobs) {
// TODO cleanup of root blobs does not count the encryption metadata blobs, but the cleanup of blob containers ("indices" folder)
// does count them; ideally there should be consistency, one way or the other
assertThat(response.result().blobs(), equalTo(1L + 2L + 1L /* one metadata blob */));
// the cleanup stats of the encrypted repository currently includes only some of the metadata blobs (as per above), which are
// themselves cumbersome to size; but the bytes count is stable
assertThat(response.result().bytes(), equalTo(244L));
}

@Override
protected void assertBlobsByPrefix(BlobPath path, String prefix, Map<String, BlobMetaData> blobs) throws Exception {
// blobs are larger after encryption
Map<String, BlobMetaData> blobsWithSizeAfterEncryption = new HashMap<>();
blobs.forEach((name, meta) -> {
blobsWithSizeAfterEncryption.put(name, new BlobMetaData() {
Copy link
Member

Choose a reason for hiding this comment

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

NIT: Probably shorter to just do:

new PlainBlobMetaData(meta.name(), EncryptedRepository.getEncryptedBlobByteLength(meta.length());

here :)

@Override
public String name() {
return meta.name();
}

@Override
public long length() {
return EncryptedRepository.getEncryptedBlobByteLength(meta.length());
}
});
});
super.assertBlobsByPrefix(path, prefix, blobsWithSizeAfterEncryption);
}

@Override
protected String getTestRepoName() {
return "test-encrypted-repo";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ protected SecureSettings credentials() {

@Override
protected void createRepository(final String repoName) {
AcknowledgedResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo")
AcknowledgedResponse putRepositoryResponse = client().admin().cluster().preparePutRepository(repoName)
.setType("gcs")
.setSettings(Settings.builder()
.put("bucket", System.getProperty("test.google.bucket"))
.put("base_path", System.getProperty("test.google.base", "/"))
.put("base_path", System.getProperty("test.google.base", "") + "/" + GoogleCloudStorageThirdPartyTests.class.getName() )
).get();
assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
}
Expand Down
Loading