Commit
+57 -2 +/-3 browse
1 | diff --git a/Cargo.lock b/Cargo.lock |
2 | index cfa9f8c..e4cc5e7 100644 |
3 | --- a/Cargo.lock |
4 | +++ b/Cargo.lock |
5 | @@ -335,6 +335,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" |
6 | checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" |
7 | |
8 | [[package]] |
9 | + name = "dtoa" |
10 | + version = "0.4.7" |
11 | + source = "registry+https://github.com/rust-lang/crates.io-index" |
12 | + checksum = "88d7ed2934d741c6b37e33e3832298e8850b53fd2d2bea03873375596c7cea4e" |
13 | + |
14 | + [[package]] |
15 | name = "env_logger" |
16 | version = "0.7.1" |
17 | source = "registry+https://github.com/rust-lang/crates.io-index" |
18 | @@ -1141,7 +1147,9 @@ dependencies = [ |
19 | "pretty_env_logger", |
20 | "rand", |
21 | "rusoto_core", |
22 | + "rusoto_credential", |
23 | "rusoto_s3", |
24 | + "rusoto_sts", |
25 | "serde", |
26 | "serde_json", |
27 | "sha2", |
28 | @@ -1234,6 +1242,21 @@ dependencies = [ |
29 | ] |
30 | |
31 | [[package]] |
32 | + name = "rusoto_sts" |
33 | + version = "0.46.0" |
34 | + source = "registry+https://github.com/rust-lang/crates.io-index" |
35 | + checksum = "2f93005e0c3b9e40a424b50ca71886d2445cc19bb6cdac3ac84c2daff482eb59" |
36 | + dependencies = [ |
37 | + "async-trait", |
38 | + "bytes 1.0.0", |
39 | + "chrono", |
40 | + "futures", |
41 | + "rusoto_core", |
42 | + "serde_urlencoded", |
43 | + "xml-rs", |
44 | + ] |
45 | + |
46 | + [[package]] |
47 | name = "rustc_version" |
48 | version = "0.2.3" |
49 | source = "registry+https://github.com/rust-lang/crates.io-index" |
50 | @@ -1378,6 +1401,18 @@ dependencies = [ |
51 | ] |
52 | |
53 | [[package]] |
54 | + name = "serde_urlencoded" |
55 | + version = "0.6.1" |
56 | + source = "registry+https://github.com/rust-lang/crates.io-index" |
57 | + checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" |
58 | + dependencies = [ |
59 | + "dtoa", |
60 | + "itoa", |
61 | + "serde", |
62 | + "url", |
63 | + ] |
64 | + |
65 | + [[package]] |
66 | name = "sha1" |
67 | version = "0.6.0" |
68 | source = "registry+https://github.com/rust-lang/crates.io-index" |
69 | diff --git a/Cargo.toml b/Cargo.toml |
70 | index 729fbfd..0a04d85 100644 |
71 | --- a/Cargo.toml |
72 | +++ b/Cargo.toml |
73 | @@ -48,6 +48,14 @@ version = "0.46" |
74 | default_features = false |
75 | features = ["rustls"] |
76 | |
77 | + [dependencies.rusoto_credential] |
78 | + version = "0.46" |
79 | + |
80 | + [dependencies.rusoto_sts] |
81 | + version = "0.46" |
82 | + features = ["rustls"] |
83 | + default_features = false |
84 | + |
85 | [dependencies.rusoto_s3] |
86 | version = "0.46" |
87 | default_features = false |
88 | diff --git a/src/storage/s3.rs b/src/storage/s3.rs |
89 | index 8882663..f659d82 100644 |
90 | --- a/src/storage/s3.rs |
91 | +++ b/src/storage/s3.rs |
92 | @@ -23,7 +23,9 @@ use bytes::Bytes; |
93 | use derive_more::{Display, From}; |
94 | use futures::{stream, stream::TryStreamExt}; |
95 | use http::StatusCode; |
96 | - use rusoto_core::{Region, RusotoError}; |
97 | + use rusoto_core::{Region, HttpClient, RusotoError}; |
98 | + use rusoto_credential::{CredentialsError, AutoRefreshingProvider, ProvideAwsCredentials}; |
99 | + use rusoto_sts::WebIdentityProvider; |
100 | use rusoto_s3::{ |
101 | GetObjectError, GetObjectRequest, HeadBucketError, HeadBucketRequest, |
102 | HeadObjectError, HeadObjectRequest, PutObjectError, PutObjectRequest, |
103 | @@ -43,6 +45,8 @@ pub enum Error { |
104 | |
105 | /// The uploaded object is too large. |
106 | TooLarge(u64), |
107 | + |
108 | + From(CredentialsError), |
109 | } |
110 | |
111 | impl ::std::error::Error for Error {} |
112 | @@ -145,7 +149,15 @@ impl Backend { |
113 | region.name() |
114 | ); |
115 | |
116 | - Backend::with_client(S3Client::new(region), bucket, prefix).await |
117 | + let k8s_provider = WebIdentityProvider::from_k8s_env(); |
118 | + let client: S3Client = if let Ok(_) = k8s_provider.credentials().await { |
119 | + log::info!("Using credentials from Kubernetes"); |
120 | + S3Client::new_with(HttpClient::new().unwrap(), AutoRefreshingProvider::new(k8s_provider)?, region) |
121 | + } else { |
122 | + S3Client::new(region) |
123 | + }; |
124 | + |
125 | + Backend::with_client(client, bucket, prefix).await |
126 | } |
127 | } |
128 |