Skip to content

Commit 95b4b09

Browse files
committed
feat: Allow using self-signed certificates in HTTPS health tests
Usually, the container's HTTPS ports use self-signed certificates instead of real ones. This makes the HTTPS health check always fail and be retried. This PR allows self-signed certificates for health checks by adding the `require_valid_certs` configuration field to `WaitStrategy`. Signed-off-by: Wiktor Kwapisiewicz <[email protected]>
1 parent e7335a1 commit 95b4b09

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

rustainers/src/container/wait_condition.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ pub enum WaitStrategy {
2525
HttpSuccess {
2626
/// If we use HTTPS instead of HTTP
2727
https: bool,
28+
/// If TLS certificates are validated.
29+
///
30+
/// Setting this field to `false` will allow self-signed certificates to be used.
31+
/// This setting is used only when `https` is set to `true`.
32+
require_valid_certs: bool,
2833
/// The path to check
2934
path: String,
3035
/// The container port
@@ -82,6 +87,7 @@ impl WaitStrategy {
8287
let container_port = Port(80);
8388
Self::HttpSuccess {
8489
https: false,
90+
require_valid_certs: true,
8591
path,
8692
container_port,
8793
}
@@ -93,6 +99,7 @@ impl WaitStrategy {
9399
let container_port = Port(443);
94100
Self::HttpSuccess {
95101
https: true,
102+
require_valid_certs: true,
96103
path,
97104
container_port,
98105
}
@@ -168,12 +175,21 @@ impl Display for WaitStrategy {
168175
Self::State(state) => write!(f, "State {state}"),
169176
Self::HttpSuccess {
170177
https,
178+
require_valid_certs,
171179
path,
172180
container_port,
173181
} => write!(
174182
f,
175183
"HTTP success {}on path path {path} with container port {container_port}",
176-
if *https { "(HTTPS)" } else { "" }
184+
if *https {
185+
if *require_valid_certs {
186+
"(HTTPS with valid certs)"
187+
} else {
188+
"(HTTPS with self-signed certs)"
189+
}
190+
} else {
191+
""
192+
}
177193
),
178194
Self::ScanPort {
179195
container_port,

rustainers/src/runner/inner.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ pub(crate) trait InnerRunner: Display + Debug + Send + Sync {
279279
}
280280
WaitStrategy::HttpSuccess {
281281
https,
282+
require_valid_certs,
282283
path,
283284
container_port,
284285
} => {
@@ -291,7 +292,14 @@ pub(crate) trait InnerRunner: Display + Debug + Send + Sync {
291292
"{scheme}://127.0.0.1:{host_port}/{}",
292293
path.trim_start_matches('/')
293294
);
294-
let Ok(response) = reqwest::get(&url).await else {
295+
let Ok(client) = reqwest::ClientBuilder::new()
296+
.danger_accept_invalid_certs(!require_valid_certs)
297+
.build()
298+
else {
299+
warn!(%url,"Could not create new client, will retry later");
300+
continue;
301+
};
302+
let Ok(response) = client.get(&url).send().await else {
295303
warn!(%url,"Fail to get the URL, will retry later");
296304
continue;
297305
};

0 commit comments

Comments
 (0)