Skip to content

Commit a8c7c7f

Browse files
committed
Make allow insecure host a global option
Not verifying the certificates of certain hosts should be supported for all kinds of HTTPS connections, so we're making it a global option, just like native tls. This fixes the remaining places using a client but were not configuring allow insecure host. Fixes #6983 (i think) Closes #6983
1 parent 76bcb89 commit a8c7c7f

30 files changed

+747
-371
lines changed

crates/uv-cli/src/lib.rs

Lines changed: 20 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,26 @@ pub struct GlobalArgs {
205205
#[arg(global = true, long, overrides_with("offline"), hide = true)]
206206
pub no_offline: bool,
207207

208+
/// Allow insecure connections to a host.
209+
///
210+
/// Can be provided multiple times.
211+
///
212+
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
213+
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
214+
///
215+
/// WARNING: Hosts included in this list will not be verified against the system's certificate
216+
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
217+
/// bypasses SSL verification and could expose you to MITM attacks.
218+
#[arg(
219+
global = true,
220+
long,
221+
alias = "trusted-host",
222+
env = EnvVars::UV_INSECURE_HOST,
223+
value_delimiter = ' ',
224+
value_parser = parse_insecure_host,
225+
)]
226+
pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,
227+
208228
/// Whether to enable experimental, preview features.
209229
///
210230
/// Preview features may change without warning.
@@ -1768,25 +1788,6 @@ pub struct PipUninstallArgs {
17681788
#[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
17691789
pub keyring_provider: Option<KeyringProviderType>,
17701790

1771-
/// Allow insecure connections to a host.
1772-
///
1773-
/// Can be provided multiple times.
1774-
///
1775-
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
1776-
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
1777-
///
1778-
/// WARNING: Hosts included in this list will not be verified against the system's certificate
1779-
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
1780-
/// bypasses SSL verification and could expose you to MITM attacks.
1781-
#[arg(
1782-
long,
1783-
alias = "trusted-host",
1784-
env = EnvVars::UV_INSECURE_HOST,
1785-
value_delimiter = ' ',
1786-
value_parser = parse_insecure_host,
1787-
)]
1788-
pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,
1789-
17901791
/// Use the system Python to uninstall packages.
17911792
///
17921793
/// By default, uv uninstalls from the virtual environment in the current working directory or
@@ -2360,25 +2361,6 @@ pub struct VenvArgs {
23602361
#[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
23612362
pub keyring_provider: Option<KeyringProviderType>,
23622363

2363-
/// Allow insecure connections to a host.
2364-
///
2365-
/// Can be provided multiple times.
2366-
///
2367-
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
2368-
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
2369-
///
2370-
/// WARNING: Hosts included in this list will not be verified against the system's certificate
2371-
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
2372-
/// bypasses SSL verification and could expose you to MITM attacks.
2373-
#[arg(
2374-
long,
2375-
alias = "trusted-host",
2376-
env = EnvVars::UV_INSECURE_HOST,
2377-
value_delimiter = ' ',
2378-
value_parser = parse_insecure_host,
2379-
)]
2380-
pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,
2381-
23822364
/// Limit candidate packages to those that were uploaded prior to the given date.
23832365
///
23842366
/// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and local dates in the same
@@ -4068,26 +4050,6 @@ pub struct InstallerArgs {
40684050
)]
40694051
pub keyring_provider: Option<KeyringProviderType>,
40704052

4071-
/// Allow insecure connections to a host.
4072-
///
4073-
/// Can be provided multiple times.
4074-
///
4075-
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
4076-
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
4077-
///
4078-
/// WARNING: Hosts included in this list will not be verified against the system's certificate
4079-
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
4080-
/// bypasses SSL verification and could expose you to MITM attacks.
4081-
#[arg(
4082-
long,
4083-
alias = "trusted-host",
4084-
env = EnvVars::UV_INSECURE_HOST,
4085-
value_delimiter = ' ',
4086-
value_parser = parse_insecure_host,
4087-
help_heading = "Index options"
4088-
)]
4089-
pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,
4090-
40914053
/// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
40924054
#[arg(
40934055
long,
@@ -4230,26 +4192,6 @@ pub struct ResolverArgs {
42304192
)]
42314193
pub keyring_provider: Option<KeyringProviderType>,
42324194

4233-
/// Allow insecure connections to a host.
4234-
///
4235-
/// Can be provided multiple times.
4236-
///
4237-
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
4238-
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
4239-
///
4240-
/// WARNING: Hosts included in this list will not be verified against the system's certificate
4241-
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
4242-
/// bypasses SSL verification and could expose you to MITM attacks.
4243-
#[arg(
4244-
long,
4245-
alias = "trusted-host",
4246-
env = EnvVars::UV_INSECURE_HOST,
4247-
value_delimiter = ' ',
4248-
value_parser = parse_insecure_host,
4249-
help_heading = "Index options"
4250-
)]
4251-
pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,
4252-
42534195
/// The strategy to use when selecting between the different compatible versions for a given
42544196
/// package requirement.
42554197
///
@@ -4645,25 +4587,6 @@ pub struct PublishArgs {
46454587
/// Defaults to `disabled`.
46464588
#[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
46474589
pub keyring_provider: Option<KeyringProviderType>,
4648-
4649-
/// Allow insecure connections to a host.
4650-
///
4651-
/// Can be provided multiple times.
4652-
///
4653-
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
4654-
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
4655-
///
4656-
/// WARNING: Hosts included in this list will not be verified against the system's certificate
4657-
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
4658-
/// bypasses SSL verification and could expose you to MITM attacks.
4659-
#[arg(
4660-
long,
4661-
alias = "trusted-host",
4662-
env = EnvVars::UV_INSECURE_HOST,
4663-
value_delimiter = ' ',
4664-
value_parser = parse_insecure_host,
4665-
)]
4666-
pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,
46674590
}
46684591

46694592
/// See [PEP 517](https://peps.python.org/pep-0517/) and

crates/uv-cli/src/options.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ impl From<ResolverArgs> for PipOptions {
4040
upgrade_package,
4141
index_strategy,
4242
keyring_provider,
43-
allow_insecure_host,
4443
resolution,
4544
prerelease,
4645
pre,
@@ -58,12 +57,6 @@ impl From<ResolverArgs> for PipOptions {
5857
upgrade_package: Some(upgrade_package),
5958
index_strategy,
6059
keyring_provider,
61-
allow_insecure_host: allow_insecure_host.map(|allow_insecure_host| {
62-
allow_insecure_host
63-
.into_iter()
64-
.filter_map(Maybe::into_option)
65-
.collect()
66-
}),
6760
resolution,
6861
prerelease: if pre {
6962
Some(PrereleaseMode::Allow)
@@ -91,7 +84,6 @@ impl From<InstallerArgs> for PipOptions {
9184
reinstall_package,
9285
index_strategy,
9386
keyring_provider,
94-
allow_insecure_host,
9587
config_setting,
9688
no_build_isolation,
9789
build_isolation,
@@ -107,12 +99,6 @@ impl From<InstallerArgs> for PipOptions {
10799
reinstall_package: Some(reinstall_package),
108100
index_strategy,
109101
keyring_provider,
110-
allow_insecure_host: allow_insecure_host.map(|allow_insecure_host| {
111-
allow_insecure_host
112-
.into_iter()
113-
.filter_map(Maybe::into_option)
114-
.collect()
115-
}),
116102
config_settings: config_setting
117103
.map(|config_settings| config_settings.into_iter().collect::<ConfigSettings>()),
118104
no_build_isolation: flag(no_build_isolation, build_isolation),
@@ -235,7 +221,6 @@ pub fn resolver_options(
235221
upgrade_package,
236222
index_strategy,
237223
keyring_provider,
238-
allow_insecure_host,
239224
resolution,
240225
prerelease,
241226
pre,
@@ -289,12 +274,6 @@ pub fn resolver_options(
289274
upgrade_package: Some(upgrade_package),
290275
index_strategy,
291276
keyring_provider,
292-
allow_insecure_host: allow_insecure_host.map(|allow_insecure_host| {
293-
allow_insecure_host
294-
.into_iter()
295-
.filter_map(Maybe::into_option)
296-
.collect()
297-
}),
298277
resolution,
299278
prerelease: if pre {
300279
Some(PrereleaseMode::Allow)

crates/uv-settings/src/settings.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,22 @@ pub struct GlobalOptions {
224224
"#
225225
)]
226226
pub concurrent_installs: Option<NonZeroUsize>,
227+
/// Allow insecure connections to host.
228+
///
229+
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
230+
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
231+
///
232+
/// WARNING: Hosts included in this list will not be verified against the system's certificate
233+
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
234+
/// bypasses SSL verification and could expose you to MITM attacks.
235+
#[option(
236+
default = "[]",
237+
value_type = "list[str]",
238+
example = r#"
239+
allow-insecure-host = ["localhost:8080"]
240+
"#
241+
)]
242+
pub allow_insecure_host: Option<Vec<TrustedHost>>,
227243
}
228244

229245
/// Settings relevant to all installer operations.
@@ -236,7 +252,6 @@ pub struct InstallerOptions {
236252
pub find_links: Option<Vec<PipFindLinks>>,
237253
pub index_strategy: Option<IndexStrategy>,
238254
pub keyring_provider: Option<KeyringProviderType>,
239-
pub allow_insecure_host: Option<Vec<TrustedHost>>,
240255
pub config_settings: Option<ConfigSettings>,
241256
pub exclude_newer: Option<ExcludeNewer>,
242257
pub link_mode: Option<LinkMode>,
@@ -261,7 +276,6 @@ pub struct ResolverOptions {
261276
pub find_links: Option<Vec<PipFindLinks>>,
262277
pub index_strategy: Option<IndexStrategy>,
263278
pub keyring_provider: Option<KeyringProviderType>,
264-
pub allow_insecure_host: Option<Vec<TrustedHost>>,
265279
pub resolution: Option<ResolutionMode>,
266280
pub prerelease: Option<PrereleaseMode>,
267281
pub dependency_metadata: Option<Vec<StaticMetadata>>,
@@ -1352,7 +1366,6 @@ impl From<ResolverInstallerOptions> for ResolverOptions {
13521366
find_links: value.find_links,
13531367
index_strategy: value.index_strategy,
13541368
keyring_provider: value.keyring_provider,
1355-
allow_insecure_host: value.allow_insecure_host,
13561369
resolution: value.resolution,
13571370
prerelease: value.prerelease,
13581371
dependency_metadata: value.dependency_metadata,
@@ -1382,7 +1395,6 @@ impl From<ResolverInstallerOptions> for InstallerOptions {
13821395
find_links: value.find_links,
13831396
index_strategy: value.index_strategy,
13841397
keyring_provider: value.keyring_provider,
1385-
allow_insecure_host: value.allow_insecure_host,
13861398
config_settings: value.config_settings,
13871399
exclude_newer: value.exclude_newer,
13881400
link_mode: value.link_mode,
@@ -1635,6 +1647,8 @@ impl From<OptionsWire> for Options {
16351647
concurrent_downloads,
16361648
concurrent_builds,
16371649
concurrent_installs,
1650+
// Used twice for backwards compatibility
1651+
allow_insecure_host: allow_insecure_host.clone(),
16381652
},
16391653
top_level: ResolverInstallerOptions {
16401654
index,

crates/uv/src/commands/build_frontend.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub(crate) async fn build_frontend(
5858
connectivity: Connectivity,
5959
concurrency: Concurrency,
6060
native_tls: bool,
61+
allow_insecure_host: &[TrustedHost],
6162
cache: &Cache,
6263
printer: Printer,
6364
) -> Result<ExitStatus> {
@@ -80,6 +81,7 @@ pub(crate) async fn build_frontend(
8081
connectivity,
8182
concurrency,
8283
native_tls,
84+
allow_insecure_host,
8385
cache,
8486
printer,
8587
)
@@ -120,6 +122,7 @@ async fn build_impl(
120122
connectivity: Connectivity,
121123
concurrency: Concurrency,
122124
native_tls: bool,
125+
allow_insecure_host: &[TrustedHost],
123126
cache: &Cache,
124127
printer: Printer,
125128
) -> Result<BuildResult> {
@@ -128,7 +131,6 @@ async fn build_impl(
128131
index_locations,
129132
index_strategy,
130133
keyring_provider,
131-
allow_insecure_host,
132134
resolution: _,
133135
prerelease: _,
134136
dependency_metadata,
@@ -144,7 +146,8 @@ async fn build_impl(
144146

145147
let client_builder = BaseClientBuilder::default()
146148
.connectivity(connectivity)
147-
.native_tls(native_tls);
149+
.native_tls(native_tls)
150+
.allow_insecure_host(allow_insecure_host.to_vec());
148151

149152
// Determine the source to build.
150153
let src = if let Some(src) = src {

crates/uv/src/commands/pip/compile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub(crate) async fn pip_compile(
7676
index_strategy: IndexStrategy,
7777
dependency_metadata: DependencyMetadata,
7878
keyring_provider: KeyringProviderType,
79-
allow_insecure_host: Vec<TrustedHost>,
79+
allow_insecure_host: &[TrustedHost],
8080
config_settings: ConfigSettings,
8181
connectivity: Connectivity,
8282
no_build_isolation: bool,
@@ -110,7 +110,7 @@ pub(crate) async fn pip_compile(
110110
.connectivity(connectivity)
111111
.native_tls(native_tls)
112112
.keyring(keyring_provider)
113-
.allow_insecure_host(allow_insecure_host);
113+
.allow_insecure_host(allow_insecure_host.to_vec());
114114

115115
// Read all requirements from the provided sources.
116116
let RequirementsSpecification {

crates/uv/src/commands/pip/install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub(crate) async fn pip_install(
5656
index_strategy: IndexStrategy,
5757
dependency_metadata: DependencyMetadata,
5858
keyring_provider: KeyringProviderType,
59-
allow_insecure_host: Vec<TrustedHost>,
6059
reinstall: Reinstall,
6160
link_mode: LinkMode,
6261
compile: bool,
@@ -79,6 +78,7 @@ pub(crate) async fn pip_install(
7978
prefix: Option<Prefix>,
8079
concurrency: Concurrency,
8180
native_tls: bool,
81+
allow_insecure_host: &[TrustedHost],
8282
cache: Cache,
8383
dry_run: bool,
8484
printer: Printer,
@@ -89,7 +89,7 @@ pub(crate) async fn pip_install(
8989
.connectivity(connectivity)
9090
.native_tls(native_tls)
9191
.keyring(keyring_provider)
92-
.allow_insecure_host(allow_insecure_host);
92+
.allow_insecure_host(allow_insecure_host.to_vec());
9393

9494
// Read all requirements from the provided sources.
9595
let RequirementsSpecification {

crates/uv/src/commands/pip/sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub(crate) async fn pip_sync(
4848
index_strategy: IndexStrategy,
4949
dependency_metadata: DependencyMetadata,
5050
keyring_provider: KeyringProviderType,
51-
allow_insecure_host: Vec<TrustedHost>,
5251
allow_empty_requirements: bool,
5352
connectivity: Connectivity,
5453
config_settings: &ConfigSettings,
@@ -67,6 +66,7 @@ pub(crate) async fn pip_sync(
6766
sources: SourceStrategy,
6867
concurrency: Concurrency,
6968
native_tls: bool,
69+
allow_insecure_host: &[TrustedHost],
7070
cache: Cache,
7171
dry_run: bool,
7272
printer: Printer,
@@ -75,7 +75,7 @@ pub(crate) async fn pip_sync(
7575
.connectivity(connectivity)
7676
.native_tls(native_tls)
7777
.keyring(keyring_provider)
78-
.allow_insecure_host(allow_insecure_host);
78+
.allow_insecure_host(allow_insecure_host.to_vec());
7979

8080
// Initialize a few defaults.
8181
let overrides = &[];

0 commit comments

Comments
 (0)