Skip to content

Commit e0e19a2

Browse files
committed
idraft impl of authorization aware cache
1 parent 55ac0bc commit e0e19a2

17 files changed

+154
-54
lines changed

src/Backups/BackupIO_AzureBlobStorage.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ BackupReaderAzureBlobStorage::BackupReaderAzureBlobStorage(
4747
std::move(client_ptr),
4848
std::move(settings_ptr),
4949
connection_params.getContainer(),
50-
connection_params.getConnectionURL());
50+
connection_params.getConnectionURL(),
51+
connection_params.auth_method);
5152

5253
client = object_storage->getAzureBlobStorageClient();
5354
settings = object_storage->getSettings();
@@ -142,7 +143,8 @@ BackupWriterAzureBlobStorage::BackupWriterAzureBlobStorage(
142143
std::move(client_ptr),
143144
std::move(settings_ptr),
144145
connection_params.getContainer(),
145-
connection_params.getConnectionURL());
146+
connection_params.getConnectionURL(),
147+
connection_params.auth_method);
146148

147149
client = object_storage->getAzureBlobStorageClient();
148150
settings = object_storage->getSettings();

src/Disks/ObjectStorages/AzureBlobStorage/AzureObjectStorage.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,14 @@ AzureObjectStorage::AzureObjectStorage(
108108
ClientPtr && client_,
109109
SettingsPtr && settings_,
110110
const String & object_namespace_,
111-
const String & description_)
111+
const String & description_,
112+
AzureBlobStorage::AuthMethod auth_method_)
112113
: name(name_)
113114
, client(std::move(client_))
114115
, settings(std::move(settings_))
115116
, object_namespace(object_namespace_)
116117
, description(description_)
118+
, auth_method(auth_method_)
117119
, log(getLogger("AzureObjectStorage"))
118120
{
119121
}
@@ -154,6 +156,40 @@ ObjectStorageIteratorPtr AzureObjectStorage::iterate(const std::string & path_pr
154156
return std::make_shared<AzureIteratorAsync>(path_prefix, client_ptr, max_keys ? max_keys : settings_ptr->list_object_keys_size);
155157
}
156158

159+
std::optional<std::string> AzureObjectStorage::getIdentityFingerprint() const
160+
{
161+
std::optional<std::string> fingerprint;
162+
163+
std::visit([&fingerprint](const auto & auth) {
164+
using T = std::decay_t<decltype(auth)>;
165+
166+
if constexpr (std::is_same_v<T, AzureBlobStorage::ConnectionString>)
167+
{
168+
auto connection_string_parts = Azure::Storage::_internal::ParseConnectionString(auth);
169+
fingerprint = std::to_string(std::hash<std::string>()(connection_string_parts.AccountName));
170+
}
171+
else if constexpr (std::is_same_v<T, std::shared_ptr<Azure::Storage::StorageSharedKeyCredential>>)
172+
{
173+
if (auth)
174+
{
175+
fingerprint = std::to_string(std::hash<std::string>()(auth->AccountName));
176+
}
177+
}
178+
/// I am not sure what to do with the other auth methods, needs further investigation
179+
// else if constexpr (std::is_same_v<T, std::shared_ptr<Azure::Identity::WorkloadIdentityCredential>>) {
180+
// }
181+
// else if constexpr (std::is_same_v<T, std::shared_ptr<Azure::Identity::ManagedIdentityCredential>>) {
182+
// }
183+
}, auth_method);
184+
185+
if (!fingerprint)
186+
{
187+
return std::nullopt;
188+
}
189+
190+
return getName() + fingerprint.value();
191+
}
192+
157193
void AzureObjectStorage::listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const
158194
{
159195
auto client_ptr = client.get();
@@ -380,7 +416,7 @@ std::unique_ptr<IObjectStorage> AzureObjectStorage::cloneObjectStorage(
380416
};
381417

382418
auto new_client = AzureBlobStorage::getContainerClient(params, /*readonly=*/ true);
383-
return std::make_unique<AzureObjectStorage>(name, std::move(new_client), std::move(new_settings), new_namespace, params.endpoint.getServiceEndpoint());
419+
return std::make_unique<AzureObjectStorage>(name, std::move(new_client), std::move(new_settings), new_namespace, params.endpoint.getServiceEndpoint(), params.auth_method);
384420
}
385421

386422
}

src/Disks/ObjectStorages/AzureBlobStorage/AzureObjectStorage.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ class AzureObjectStorage : public IObjectStorage
2929
ClientPtr && client_,
3030
SettingsPtr && settings_,
3131
const String & object_namespace_,
32-
const String & description_);
32+
const String & description_,
33+
AzureBlobStorage::AuthMethod auth_method_);
3334

3435
void listObjects(const std::string & path, RelativePathsWithMetadata & children, size_t max_keys) const override;
3536

3637
ObjectStorageIteratorPtr iterate(const std::string & path_prefix, size_t max_keys) const override;
3738

3839
std::string getName() const override { return "AzureObjectStorage"; }
3940

41+
std::optional<std::string> getIdentityFingerprint() const override;
42+
4043
ObjectStorageType getType() const override { return ObjectStorageType::Azure; }
4144

4245
std::string getCommonKeyPrefix() const override { return ""; }
@@ -116,6 +119,8 @@ class AzureObjectStorage : public IObjectStorage
116119
/// We use source url without container and prefix as description, because in Azure there are no limitations for operations between different containers.
117120
const String description;
118121

122+
AzureBlobStorage::AuthMethod auth_method;
123+
119124
LoggerPtr log;
120125
};
121126

src/Disks/ObjectStorages/Cached/CachedObjectStorage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class CachedObjectStorage final : public IObjectStorage
3131

3232
bool exists(const StoredObject & object) const override;
3333

34+
std::optional<std::string> getIdentityFingerprint() const override { return object_storage->getIdentityFingerprint(); }
35+
3436
std::unique_ptr<ReadBufferFromFileBase> readObject( /// NOLINT
3537
const StoredObject & object,
3638
const ReadSettings & read_settings,

src/Disks/ObjectStorages/HDFS/HDFSObjectStorage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class HDFSObjectStorage : public IObjectStorage, public HDFSErrorWrapper
6565

6666
bool exists(const StoredObject & object) const override;
6767

68+
std::optional<std::string> getIdentityFingerprint() const override { return std::nullopt; }
69+
6870
std::unique_ptr<ReadBufferFromFileBase> readObject( /// NOLINT
6971
const StoredObject & object,
7072
const ReadSettings & read_settings,

src/Disks/ObjectStorages/IObjectStorage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ class IObjectStorage
126126

127127
virtual std::string getDescription() const = 0;
128128

129+
// todo arthur add docs
130+
virtual std::optional<std::string> getIdentityFingerprint() const = 0;
131+
129132
virtual const MetadataStorageMetrics & getMetadataStorageMetrics() const;
130133

131134
/// Object exists or not

src/Disks/ObjectStorages/Local/LocalObjectStorage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class LocalObjectStorage : public IObjectStorage
2828

2929
bool exists(const StoredObject & object) const override;
3030

31+
// no auth
32+
std::optional<std::string> getIdentityFingerprint() const override { return getName(); }
33+
3134
std::unique_ptr<ReadBufferFromFileBase> readObject( /// NOLINT
3235
const StoredObject & object,
3336
const ReadSettings & read_settings,

src/Disks/ObjectStorages/ObjectStorageFactory.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ void registerAzureObjectStorage(ObjectStorageFactory & factory)
307307
ObjectStorageType::Azure, config, config_prefix, name,
308308
AzureBlobStorage::getContainerClient(params, /*readonly=*/ false), std::move(azure_settings),
309309
params.endpoint.prefix.empty() ? params.endpoint.container_name : params.endpoint.container_name + "/" + params.endpoint.prefix,
310-
params.endpoint.getServiceEndpoint());
310+
params.endpoint.getServiceEndpoint(),
311+
params.auth_method);
311312
};
312313

313314
factory.registerObjectStorageType("azure_blob_storage", creator);

src/Disks/ObjectStorages/S3/S3ObjectStorage.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ bool S3ObjectStorage::exists(const StoredObject & object) const
164164
return S3::objectExists(*client.get(), uri.bucket, object.remote_path, {});
165165
}
166166

167+
std::optional<std::string> S3ObjectStorage::getIdentityFingerprint() const
168+
{
169+
const auto credentials = client.get()->getCredentials();
170+
171+
return getName() + credentials.GetAWSAccessKeyId();
172+
}
173+
167174
std::unique_ptr<ReadBufferFromFileBase> S3ObjectStorage::readObject( /// NOLINT
168175
const StoredObject & object,
169176
const ReadSettings & read_settings,

src/Disks/ObjectStorages/S3/S3ObjectStorage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class S3ObjectStorage : public IObjectStorage
8181

8282
ObjectStorageType getType() const override { return ObjectStorageType::S3; }
8383

84+
std::optional<std::string> getIdentityFingerprint() const override;
85+
8486
bool exists(const StoredObject & object) const override;
8587

8688
std::unique_ptr<ReadBufferFromFileBase> readObject( /// NOLINT

0 commit comments

Comments
 (0)