Skip to content

Commit 3c72ac9

Browse files
committed
image: add http_proxy for image pull
Note that now we have both http_proxy and https_proxy configurations for image-rs. We use this widely acceptable variable name to replace the old names. Signed-off-by: Xynnn007 <[email protected]>
1 parent e7e9928 commit 3c72ac9

File tree

5 files changed

+73
-14
lines changed

5 files changed

+73
-14
lines changed

image-rs/src/builder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ impl ClientBuilder {
133133
&policy_bytes,
134134
sigstore_config,
135135
&self.config.work_dir,
136-
self.config.skip_proxy_ips.clone(),
137-
self.config.image_pull_proxy.clone(),
136+
self.config.no_proxy.clone(),
137+
self.config.https_proxy.clone(),
138+
self.config.http_proxy.clone(),
138139
self.config.extra_root_certificates.clone(),
139140
resource_provider.clone(),
140141
)

image-rs/src/config.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,21 @@ pub struct ImageConfig {
100100
#[serde(default = "default_max_concurrent_layer_downloads_per_image")]
101101
pub max_concurrent_layer_downloads_per_image: usize,
102102

103-
/// Proxy that will be used to pull image
103+
/// HTTPS proxy that will be used to pull image
104104
///
105105
/// If a registry is not accessible to the guest, you can try
106106
/// pulling an image through a proxy specified here.
107107
///
108108
/// This value defaults to `None`.
109-
pub image_pull_proxy: Option<String>,
109+
pub https_proxy: Option<String>,
110+
111+
/// HTTP proxy that will be used to pull image
112+
///
113+
/// If a registry is not accessible to the guest, you can try
114+
/// pulling an image through a proxy specified here.
115+
///
116+
/// This value defaults to `None`.
117+
pub http_proxy: Option<String>,
110118

111119
/// If the above proxy is enabled, this field can be used to list IPs
112120
/// that will bypass the proxy.
@@ -117,7 +125,7 @@ pub struct ImageConfig {
117125
/// If `image_pull_proxy` is not set, this field will do nothing.
118126
///
119127
/// This value defaults to `None`.
120-
pub skip_proxy_ips: Option<String>,
128+
pub no_proxy: Option<String>,
121129

122130
/// To pull an image from a registry with a self-signed ceritifcate,
123131
/// supply the corresponding trusted root cert (in PEM format) here.
@@ -174,8 +182,9 @@ impl Default for ImageConfig {
174182
sigstore_config_uri: None,
175183
authenticated_registry_credentials_uri: None,
176184
registry_configuration_uri: None,
177-
image_pull_proxy: None,
178-
skip_proxy_ips: None,
185+
http_proxy: None,
186+
https_proxy: None,
187+
no_proxy: None,
179188
extra_root_certificates: Vec::new(),
180189

181190
#[cfg(feature = "keywrap-native")]
@@ -190,6 +199,7 @@ impl Default for ImageConfig {
190199
#[derive(PartialEq, Debug)]
191200
struct KernelParameterConfigs {
192201
https_proxy: Option<String>,
202+
http_proxy: Option<String>,
193203
no_proxy: Option<String>,
194204
authenticated_registry_credentials_uri: Option<String>,
195205
image_security_policy_uri: Option<String>,
@@ -205,6 +215,7 @@ impl KernelParameterConfigs {
205215

206216
Self {
207217
https_proxy: cmdline.get("agent.https_proxy").map(|s| s.to_string()),
218+
http_proxy: cmdline.get("agent.http_proxy").map(|s| s.to_string()),
208219
no_proxy: cmdline.get("agent.no_proxy").map(|s| s.to_string()),
209220
authenticated_registry_credentials_uri: cmdline
210221
.get("agent.image_registry_auth")
@@ -259,8 +270,9 @@ impl ImageConfig {
259270
sigstore_config_uri: None,
260271
authenticated_registry_credentials_uri: None,
261272
registry_configuration_uri: None,
262-
image_pull_proxy: None,
263-
skip_proxy_ips: None,
273+
http_proxy: None,
274+
https_proxy: None,
275+
no_proxy: None,
264276
extra_root_certificates: Vec::new(),
265277

266278
#[cfg(feature = "keywrap-native")]
@@ -273,8 +285,9 @@ impl ImageConfig {
273285
if let Ok(kernel_cmdline) = fs::read_to_string("/proc/cmdline") {
274286
debug!("Try read image pull parameters from kernel cmdline");
275287
let parameters_from_kernel = KernelParameterConfigs::new(&kernel_cmdline);
276-
res.image_pull_proxy = parameters_from_kernel.https_proxy;
277-
res.skip_proxy_ips = parameters_from_kernel.no_proxy;
288+
res.https_proxy = parameters_from_kernel.https_proxy;
289+
res.http_proxy = parameters_from_kernel.http_proxy;
290+
res.no_proxy = parameters_from_kernel.no_proxy;
278291
res.authenticated_registry_credentials_uri =
279292
parameters_from_kernel.authenticated_registry_credentials_uri;
280293
if parameters_from_kernel.enable_signature_verification {
@@ -449,6 +462,7 @@ mod tests {
449462
"BOOT_IMAGE=/boot/vmlinuz-6.2.0-060200-generic root=UUID=f601123 ro vga=792 console=tty0 console=ttyS0,115200n8 agent.https_proxy=http://1.2.3.4:1234",
450463
KernelParameterConfigs {
451464
https_proxy: Some("http://1.2.3.4:1234".into()),
465+
http_proxy: None,
452466
no_proxy: None,
453467
authenticated_registry_credentials_uri: None,
454468
image_security_policy_uri: None,
@@ -459,6 +473,7 @@ mod tests {
459473
BOOT_IMAGE=/boot/vmlinuz-6.2.0-060200-generic agent.no_proxy=localhost root=UUID=f601123 ro vga=792 console=tty0 console=ttyS0,115200n8 agent.https_proxy=http://1.2.3.4:1234",
460474
KernelParameterConfigs {
461475
https_proxy: Some("http://1.2.3.4:1234".into()),
476+
http_proxy: None,
462477
no_proxy: Some("localhost".into()),
463478
authenticated_registry_credentials_uri: None,
464479
image_security_policy_uri: None,
@@ -469,6 +484,7 @@ mod tests {
469484
BOOT_IMAGE=/boot/vmlinuz-6.2.0-060200-generic agent.no_proxy=localhost \n agent.image_registry_auth=kbs:///default/credentials/test root=UUID=f601123 ro vga=792 console=tty0 console=ttyS0,115200n8 agent.https_proxy=http://1.2.3.4:1234",
470485
KernelParameterConfigs {
471486
https_proxy: Some("http://1.2.3.4:1234".into()),
487+
http_proxy: None,
472488
no_proxy: Some("localhost".into()),
473489
authenticated_registry_credentials_uri: Some("kbs:///default/credentials/test".into()),
474490
image_security_policy_uri: None,
@@ -479,6 +495,7 @@ mod tests {
479495
agent.no_proxy=localhost \n agent.image_registry_auth=file:///root/.docker/config.json agent.https_proxy=http://1.2.3.4:1234",
480496
KernelParameterConfigs {
481497
https_proxy: Some("http://1.2.3.4:1234".into()),
498+
http_proxy: None,
482499
no_proxy: Some("localhost".into()),
483500
authenticated_registry_credentials_uri: Some("file:///root/.docker/config.json".into()),
484501
image_security_policy_uri: None,
@@ -489,6 +506,7 @@ mod tests {
489506
BOOT_IMAGE=/boot/vmlinuz-6.2.0-060200-generic agent.no_proxy=localhost agent.image_policy_file=kbs:///default/image-policy/test \n agent.image_registry_auth=kbs:///a/b/c root=UUID=f601123 ro vga=792 console=tty0 console=ttyS0,115200n8 agent.https_proxy=http://1.2.3.4:1234",
490507
KernelParameterConfigs {
491508
https_proxy: Some("http://1.2.3.4:1234".into()),
509+
http_proxy: None,
492510
no_proxy: Some("localhost".into()),
493511
authenticated_registry_credentials_uri: Some("kbs:///a/b/c".into()),
494512
image_security_policy_uri: Some("kbs:///default/image-policy/test".into()),
@@ -499,6 +517,7 @@ mod tests {
499517
BOOT_IMAGE=/boot/vmlinuz-6.2.0-060200-generic agent.no_proxy=localhost agent.image_policy_file=file:///etc/image-policy.json \n agent.image_registry_auth=kbs:///a/b/c root=UUID=f601123 ro vga=792 console=tty0 console=ttyS0,115200n8 agent.https_proxy=http://1.2.3.4:1234",
500518
KernelParameterConfigs {
501519
https_proxy: Some("http://1.2.3.4:1234".into()),
520+
http_proxy: None,
502521
no_proxy: Some("localhost".into()),
503522
authenticated_registry_credentials_uri: Some("kbs:///a/b/c".into()),
504523
image_security_policy_uri: Some("file:///etc/image-policy.json".into()),
@@ -509,6 +528,18 @@ mod tests {
509528
agent.enable_signature_verification=true agent.no_proxy=localhost agent.image_policy_file=file:///etc/image-policy.json \n agent.image_registry_auth=kbs:///a/b/c agent.https_proxy=http://1.2.3.4:1234",
510529
KernelParameterConfigs {
511530
https_proxy: Some("http://1.2.3.4:1234".into()),
531+
http_proxy: None,
532+
no_proxy: Some("localhost".into()),
533+
authenticated_registry_credentials_uri: Some("kbs:///a/b/c".into()),
534+
image_security_policy_uri: Some("file:///etc/image-policy.json".into()),
535+
enable_signature_verification: true
536+
}
537+
)]
538+
#[case("
539+
agent.enable_signature_verification=true agent.no_proxy=localhost agent.image_policy_file=file:///etc/image-policy.json \n agent.image_registry_auth=kbs:///a/b/c agent.https_proxy=http://1.2.3.4:1234 agent.http_proxy=http://1.2.3.4:1234",
540+
KernelParameterConfigs {
541+
https_proxy: Some("http://1.2.3.4:1234".into()),
542+
http_proxy: Some("http://1.2.3.4:1234".into()),
512543
no_proxy: Some("localhost".into()),
513544
authenticated_registry_credentials_uri: Some("kbs:///a/b/c".into()),
514545
image_security_policy_uri: Some("file:///etc/image-policy.json".into()),

image-rs/src/image.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,11 @@ impl ImageClient {
351351
client_config.protocol = ClientProtocol::Http;
352352
}
353353

354-
if let Some(no_proxy) = &self.config.skip_proxy_ips {
354+
if let Some(no_proxy) = &self.config.no_proxy {
355355
client_config.no_proxy = Some(no_proxy.clone())
356356
}
357357

358-
if let Some(https_proxy) = &self.config.image_pull_proxy {
358+
if let Some(https_proxy) = &self.config.https_proxy {
359359
client_config.https_proxy = Some(https_proxy.clone());
360360
if task.task_type != TaskType::Origininal && !task.use_http {
361361
warn!(
@@ -365,6 +365,16 @@ impl ImageClient {
365365
}
366366
}
367367

368+
if let Some(http_proxy) = &self.config.http_proxy {
369+
client_config.http_proxy = Some(http_proxy.clone());
370+
if task.task_type != TaskType::Origininal && task.use_http {
371+
warn!(
372+
"The image pull try from {} will use the configured http proxy",
373+
task.image_reference
374+
);
375+
}
376+
}
377+
368378
let certs = self
369379
.config
370380
.extra_root_certificates

image-rs/src/signature/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub struct SignatureValidator {
6464

6565
no_proxy: Option<String>,
6666
https_proxy: Option<String>,
67+
http_proxy: Option<String>,
6768

6869
#[cfg(feature = "signature-simple")]
6970
simple_signing_sigstore_config: Option<policy::SigstoreConfig>,
@@ -159,6 +160,7 @@ impl SignatureValidator {
159160
workdir: &Path,
160161
no_proxy: Option<String>,
161162
https_proxy: Option<String>,
163+
http_proxy: Option<String>,
162164
certificates: Vec<String>,
163165
resource_provider: Arc<ResourceProvider>,
164166
) -> SignatureResult<Self> {
@@ -202,6 +204,7 @@ impl SignatureValidator {
202204
resource_provider,
203205
no_proxy,
204206
https_proxy,
207+
http_proxy,
205208
certificates,
206209
#[cfg(feature = "signature-simple")]
207210
simple_signing_sigstore_config,

image-rs/src/signature/policy/cosign/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl SignatureValidator {
4444
self.certificates.iter().collect(),
4545
self.no_proxy.as_ref(),
4646
self.https_proxy.as_ref(),
47+
self.http_proxy.as_ref(),
4748
)
4849
.await
4950
}
@@ -58,6 +59,7 @@ impl CosignParameters {
5859
certificates: Vec<&Certificate>,
5960
no_proxy: Option<&String>,
6061
https_proxy: Option<&String>,
62+
http_proxy: Option<&String>,
6163
) -> Result<()> {
6264
// Check before we access the network
6365
self.check_reference_rule_types()?;
@@ -72,7 +74,15 @@ impl CosignParameters {
7274

7375
// Verification, will access the network
7476
let payloads = self
75-
.verify_signature_and_get_payload(image, auth, key, certificates, no_proxy, https_proxy)
77+
.verify_signature_and_get_payload(
78+
image,
79+
auth,
80+
key,
81+
certificates,
82+
no_proxy,
83+
https_proxy,
84+
http_proxy,
85+
)
7686
.await?;
7787

7888
// check the reference rules (signed identity)
@@ -120,6 +130,7 @@ impl CosignParameters {
120130
certificates: Vec<&Certificate>,
121131
no_proxy: Option<&String>,
122132
https_proxy: Option<&String>,
133+
http_proxy: Option<&String>,
123134
) -> Result<Vec<SigPayload>> {
124135
let image_ref = OciReference::from_str(&image.reference.whole())?;
125136
let auth = match auth {
@@ -131,6 +142,7 @@ impl CosignParameters {
131142
let config = ClientConfig {
132143
no_proxy: no_proxy.cloned(),
133144
https_proxy: https_proxy.cloned(),
145+
http_proxy: http_proxy.cloned(),
134146
extra_root_certificates: certificates.into_iter().cloned().collect(),
135147
..Default::default()
136148
};
@@ -245,6 +257,7 @@ mod tests {
245257
vec![],
246258
None,
247259
None,
260+
None,
248261
)
249262
.await;
250263
assert!(
@@ -361,6 +374,7 @@ mod tests {
361374
vec![],
362375
None,
363376
None,
377+
None,
364378
)
365379
.await;
366380
assert_eq!(

0 commit comments

Comments
 (0)