Skip to content

Commit ec7c952

Browse files
authored
Merge pull request #2480 from input-output-hk/djo/2460/fix-acl
aggregator: fix setting public access to files uploaded to GCP storage
2 parents 97c1fc4 + 9a3bd9b commit ec7c952

File tree

7 files changed

+32
-19
lines changed

7 files changed

+32
-19
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.7.48"
3+
version = "0.7.49"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }
@@ -36,6 +36,7 @@ mithril-resource-pool = { path = "../internal/mithril-resource-pool" }
3636
mithril-signed-entity-lock = { path = "../internal/signed-entity/mithril-signed-entity-lock" }
3737
mithril-signed-entity-preloader = { path = "../internal/signed-entity/mithril-signed-entity-preloader" }
3838
paste = "1.0.15"
39+
percent-encoding = "2.3.1"
3940
rayon = { workspace = true }
4041
regex = "1.11.1"
4142
reqwest = { workspace = true, features = [

mithril-aggregator/src/file_uploaders/cloud_uploader/gcloud_backend.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tokio_util::codec::{BytesCodec, FramedRead};
1616
use mithril_common::entities::FileUri;
1717
use mithril_common::StdResult;
1818

19-
use crate::file_uploaders::cloud_uploader::CloudBackendUploader;
19+
use crate::file_uploaders::cloud_uploader::{gcp_percent_encode, CloudBackendUploader};
2020
use crate::file_uploaders::CloudRemotePath;
2121

2222
/// Google Cloud Platform file uploader using `gcloud-storage` crate
@@ -133,13 +133,13 @@ impl CloudBackendUploader for GCloudBackendUploader {
133133
role: ObjectACLRole::READER,
134134
};
135135
info!(
136-
self.logger,
137-
"Updating acl for {remote_file_path}: {new_bucket_access_control:?}"
136+
self.logger, "Updating acl for {remote_file_path}";
137+
"inserted_acl" => ?new_bucket_access_control
138138
);
139139
self.storage_client
140140
.insert_object_access_control(&InsertObjectAccessControlRequest {
141141
bucket: self.bucket.clone(),
142-
object: remote_file_path.to_string(),
142+
object: gcp_percent_encode(&remote_file_path.to_string()),
143143
acl: new_bucket_access_control,
144144
..Default::default()
145145
})

mithril-aggregator/src/file_uploaders/cloud_uploader/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,16 @@ mod interface;
55
pub use api::*;
66
pub use gcloud_backend::*;
77
pub use interface::*;
8+
9+
use percent_encoding::{utf8_percent_encode, AsciiSet, NON_ALPHANUMERIC};
10+
11+
const ENCODE_SET: &AsciiSet = &NON_ALPHANUMERIC
12+
.remove(b'*')
13+
.remove(b'-')
14+
.remove(b'.')
15+
.remove(b'_');
16+
17+
/// Encode a string for use in a GCP URL, satisfying: https://cloud.google.com/storage/docs/request-endpoints#encoding
18+
pub fn gcp_percent_encode(input: &str) -> String {
19+
utf8_percent_encode(input, ENCODE_SET).to_string()
20+
}

mithril-aggregator/src/file_uploaders/interface.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ pub trait FileUploader: Sync + Send {
5353
nb_attempts += 1;
5454
match self.upload_without_retry(filepath).await {
5555
Ok(result) => return Ok(result),
56-
Err(_) if nb_attempts >= retry_policy.attempts => {
57-
return Err(anyhow::anyhow!(
58-
"Upload failed after {} attempts",
59-
nb_attempts
60-
));
56+
Err(e) if nb_attempts >= retry_policy.attempts => {
57+
return Err(anyhow::anyhow!(e).context(format!(
58+
"Upload failed after {nb_attempts} attempts. Uploaded file path: {}",
59+
filepath.display()
60+
)));
6161
}
6262
_ => tokio::time::sleep(retry_policy.delay_between_attempts).await,
6363
}

mithril-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-client"
3-
version = "0.12.3"
3+
version = "0.12.4"
44
description = "Mithril client library"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-client/src/file_downloader/retry.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,10 @@ impl FileDownloader for RetryDownloader {
8181
.await
8282
{
8383
Ok(result) => return Ok(result),
84-
Err(_) if nb_attempts >= retry_policy.attempts => {
85-
return Err(anyhow::anyhow!(
86-
"Download of location {:?} failed after {} attempts",
87-
location,
88-
nb_attempts
89-
));
84+
Err(e) if nb_attempts >= retry_policy.attempts => {
85+
return Err(anyhow::anyhow!(e).context(format!(
86+
"Download of location {location:?} failed after {nb_attempts} attempts",
87+
)));
9088
}
9189
_ => tokio::time::sleep(retry_policy.delay_between_attempts).await,
9290
}

0 commit comments

Comments
 (0)