Skip to content

Commit

Permalink
Support GKE Workload Identity for Searchable Snapshots
Browse files Browse the repository at this point in the history
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 elastic#82702
  • Loading branch information
arteam committed Jan 24, 2022
1 parent 3aa9716 commit 76646a3
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -195,7 +195,7 @@ StorageOptions createStorageOptions(
} else {
String defaultProjectId = null;
try {
defaultProjectId = ServiceOptions.getDefaultProjectId();
defaultProjectId = SocketAccess.doPrivilegedIOException(ServiceOptions::getDefaultProjectId);
if (defaultProjectId != null) {
storageOptionsBuilder.setProjectId(defaultProjectId);
}
Expand All @@ -219,7 +219,7 @@ StorageOptions createStorageOptions(
}
if (gcsClientSettings.getCredential() == null) {
try {
storageOptionsBuilder.setCredentials(GoogleCredentials.getApplicationDefault());
storageOptionsBuilder.setCredentials(SocketAccess.doPrivilegedIOException(GoogleCredentials::getApplicationDefault));
} catch (Exception e) {
logger.warn("failed to load Application Default Credentials", e);
}
Expand Down

0 comments on commit 76646a3

Please sign in to comment.