Skip to content

Commit 656e8cf

Browse files
authored
Support GKE Workload Identity for Searchable Snapshots (#82974) (#83126)
Searchable snapshots perform naked calls of `GoogleCloudStorageBlobContainer#readBlob` without the Security Manager. The client fails to get Compute Engine credentials because of that. It works for normal snapshot/restore because they do a privileged call of `GoogleCloudStorageBlobStore.writeBlob` during the verification of the repo. The simplest fix is just to make sure `ServiceOptions.getDefaultProjectId` and `GoogleCredentials::getApplicationDefault` are get called under the SecurityManager (which they should because they perform network calls). Unfortunately, we can't write an integration test for the issue, because the test framework does the repo verification automatically, which works around the bug. Writing a unit test also seems not possible, because `ComputeEngineCredentials#getMetadataServerUrl` relies on the `GCE_METADATA_HOST` environment variable. See elastic/cloud-on-k8s#5230 Resolves #82702
1 parent 5a008e0 commit 656e8cf

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

docs/changelog/82974.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 82974
2+
summary: Support GKE Workload Identity for Searchable Snapshots
3+
area: Snapshot/Restore
4+
type: bug
5+
issues:
6+
- 82702

modules/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ StorageOptions createStorageOptions(
195195
} else {
196196
String defaultProjectId = null;
197197
try {
198-
defaultProjectId = ServiceOptions.getDefaultProjectId();
198+
defaultProjectId = SocketAccess.doPrivilegedIOException(ServiceOptions::getDefaultProjectId);
199199
if (defaultProjectId != null) {
200200
storageOptionsBuilder.setProjectId(defaultProjectId);
201201
}
@@ -219,7 +219,7 @@ StorageOptions createStorageOptions(
219219
}
220220
if (gcsClientSettings.getCredential() == null) {
221221
try {
222-
storageOptionsBuilder.setCredentials(GoogleCredentials.getApplicationDefault());
222+
storageOptionsBuilder.setCredentials(SocketAccess.doPrivilegedIOException(GoogleCredentials::getApplicationDefault));
223223
} catch (Exception e) {
224224
logger.warn("failed to load Application Default Credentials", e);
225225
}

0 commit comments

Comments
 (0)