Skip to content

Commit

Permalink
Make allow insecure host a global option
Browse files Browse the repository at this point in the history
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
  • Loading branch information
konstin committed Oct 23, 2024
1 parent 76bcb89 commit a8c7c7f
Show file tree
Hide file tree
Showing 30 changed files with 747 additions and 371 deletions.
117 changes: 20 additions & 97 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,26 @@ pub struct GlobalArgs {
#[arg(global = true, long, overrides_with("offline"), hide = true)]
pub no_offline: bool,

/// Allow insecure connections to a host.
///
/// Can be provided multiple times.
///
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
/// bypasses SSL verification and could expose you to MITM attacks.
#[arg(
global = true,
long,
alias = "trusted-host",
env = EnvVars::UV_INSECURE_HOST,
value_delimiter = ' ',
value_parser = parse_insecure_host,
)]
pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,

/// Whether to enable experimental, preview features.
///
/// Preview features may change without warning.
Expand Down Expand Up @@ -1768,25 +1788,6 @@ pub struct PipUninstallArgs {
#[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
pub keyring_provider: Option<KeyringProviderType>,

/// Allow insecure connections to a host.
///
/// Can be provided multiple times.
///
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
/// bypasses SSL verification and could expose you to MITM attacks.
#[arg(
long,
alias = "trusted-host",
env = EnvVars::UV_INSECURE_HOST,
value_delimiter = ' ',
value_parser = parse_insecure_host,
)]
pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,

/// Use the system Python to uninstall packages.
///
/// By default, uv uninstalls from the virtual environment in the current working directory or
Expand Down Expand Up @@ -2360,25 +2361,6 @@ pub struct VenvArgs {
#[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
pub keyring_provider: Option<KeyringProviderType>,

/// Allow insecure connections to a host.
///
/// Can be provided multiple times.
///
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
/// bypasses SSL verification and could expose you to MITM attacks.
#[arg(
long,
alias = "trusted-host",
env = EnvVars::UV_INSECURE_HOST,
value_delimiter = ' ',
value_parser = parse_insecure_host,
)]
pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,

/// Limit candidate packages to those that were uploaded prior to the given date.
///
/// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and local dates in the same
Expand Down Expand Up @@ -4068,26 +4050,6 @@ pub struct InstallerArgs {
)]
pub keyring_provider: Option<KeyringProviderType>,

/// Allow insecure connections to a host.
///
/// Can be provided multiple times.
///
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
/// bypasses SSL verification and could expose you to MITM attacks.
#[arg(
long,
alias = "trusted-host",
env = EnvVars::UV_INSECURE_HOST,
value_delimiter = ' ',
value_parser = parse_insecure_host,
help_heading = "Index options"
)]
pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,

/// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
#[arg(
long,
Expand Down Expand Up @@ -4230,26 +4192,6 @@ pub struct ResolverArgs {
)]
pub keyring_provider: Option<KeyringProviderType>,

/// Allow insecure connections to a host.
///
/// Can be provided multiple times.
///
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
/// bypasses SSL verification and could expose you to MITM attacks.
#[arg(
long,
alias = "trusted-host",
env = EnvVars::UV_INSECURE_HOST,
value_delimiter = ' ',
value_parser = parse_insecure_host,
help_heading = "Index options"
)]
pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,

/// The strategy to use when selecting between the different compatible versions for a given
/// package requirement.
///
Expand Down Expand Up @@ -4645,25 +4587,6 @@ pub struct PublishArgs {
/// Defaults to `disabled`.
#[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
pub keyring_provider: Option<KeyringProviderType>,

/// Allow insecure connections to a host.
///
/// Can be provided multiple times.
///
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
/// bypasses SSL verification and could expose you to MITM attacks.
#[arg(
long,
alias = "trusted-host",
env = EnvVars::UV_INSECURE_HOST,
value_delimiter = ' ',
value_parser = parse_insecure_host,
)]
pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,
}

/// See [PEP 517](https://peps.python.org/pep-0517/) and
Expand Down
21 changes: 0 additions & 21 deletions crates/uv-cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ impl From<ResolverArgs> for PipOptions {
upgrade_package,
index_strategy,
keyring_provider,
allow_insecure_host,
resolution,
prerelease,
pre,
Expand All @@ -58,12 +57,6 @@ impl From<ResolverArgs> for PipOptions {
upgrade_package: Some(upgrade_package),
index_strategy,
keyring_provider,
allow_insecure_host: allow_insecure_host.map(|allow_insecure_host| {
allow_insecure_host
.into_iter()
.filter_map(Maybe::into_option)
.collect()
}),
resolution,
prerelease: if pre {
Some(PrereleaseMode::Allow)
Expand Down Expand Up @@ -91,7 +84,6 @@ impl From<InstallerArgs> for PipOptions {
reinstall_package,
index_strategy,
keyring_provider,
allow_insecure_host,
config_setting,
no_build_isolation,
build_isolation,
Expand All @@ -107,12 +99,6 @@ impl From<InstallerArgs> for PipOptions {
reinstall_package: Some(reinstall_package),
index_strategy,
keyring_provider,
allow_insecure_host: allow_insecure_host.map(|allow_insecure_host| {
allow_insecure_host
.into_iter()
.filter_map(Maybe::into_option)
.collect()
}),
config_settings: config_setting
.map(|config_settings| config_settings.into_iter().collect::<ConfigSettings>()),
no_build_isolation: flag(no_build_isolation, build_isolation),
Expand Down Expand Up @@ -235,7 +221,6 @@ pub fn resolver_options(
upgrade_package,
index_strategy,
keyring_provider,
allow_insecure_host,
resolution,
prerelease,
pre,
Expand Down Expand Up @@ -289,12 +274,6 @@ pub fn resolver_options(
upgrade_package: Some(upgrade_package),
index_strategy,
keyring_provider,
allow_insecure_host: allow_insecure_host.map(|allow_insecure_host| {
allow_insecure_host
.into_iter()
.filter_map(Maybe::into_option)
.collect()
}),
resolution,
prerelease: if pre {
Some(PrereleaseMode::Allow)
Expand Down
22 changes: 18 additions & 4 deletions crates/uv-settings/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ pub struct GlobalOptions {
"#
)]
pub concurrent_installs: Option<NonZeroUsize>,
/// Allow insecure connections to host.
///
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
/// bypasses SSL verification and could expose you to MITM attacks.
#[option(
default = "[]",
value_type = "list[str]",
example = r#"
allow-insecure-host = ["localhost:8080"]
"#
)]
pub allow_insecure_host: Option<Vec<TrustedHost>>,
}

/// Settings relevant to all installer operations.
Expand All @@ -236,7 +252,6 @@ pub struct InstallerOptions {
pub find_links: Option<Vec<PipFindLinks>>,
pub index_strategy: Option<IndexStrategy>,
pub keyring_provider: Option<KeyringProviderType>,
pub allow_insecure_host: Option<Vec<TrustedHost>>,
pub config_settings: Option<ConfigSettings>,
pub exclude_newer: Option<ExcludeNewer>,
pub link_mode: Option<LinkMode>,
Expand All @@ -261,7 +276,6 @@ pub struct ResolverOptions {
pub find_links: Option<Vec<PipFindLinks>>,
pub index_strategy: Option<IndexStrategy>,
pub keyring_provider: Option<KeyringProviderType>,
pub allow_insecure_host: Option<Vec<TrustedHost>>,
pub resolution: Option<ResolutionMode>,
pub prerelease: Option<PrereleaseMode>,
pub dependency_metadata: Option<Vec<StaticMetadata>>,
Expand Down Expand Up @@ -1352,7 +1366,6 @@ impl From<ResolverInstallerOptions> for ResolverOptions {
find_links: value.find_links,
index_strategy: value.index_strategy,
keyring_provider: value.keyring_provider,
allow_insecure_host: value.allow_insecure_host,
resolution: value.resolution,
prerelease: value.prerelease,
dependency_metadata: value.dependency_metadata,
Expand Down Expand Up @@ -1382,7 +1395,6 @@ impl From<ResolverInstallerOptions> for InstallerOptions {
find_links: value.find_links,
index_strategy: value.index_strategy,
keyring_provider: value.keyring_provider,
allow_insecure_host: value.allow_insecure_host,
config_settings: value.config_settings,
exclude_newer: value.exclude_newer,
link_mode: value.link_mode,
Expand Down Expand Up @@ -1635,6 +1647,8 @@ impl From<OptionsWire> for Options {
concurrent_downloads,
concurrent_builds,
concurrent_installs,
// Used twice for backwards compatibility
allow_insecure_host: allow_insecure_host.clone(),
},
top_level: ResolverInstallerOptions {
index,
Expand Down
7 changes: 5 additions & 2 deletions crates/uv/src/commands/build_frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub(crate) async fn build_frontend(
connectivity: Connectivity,
concurrency: Concurrency,
native_tls: bool,
allow_insecure_host: &[TrustedHost],
cache: &Cache,
printer: Printer,
) -> Result<ExitStatus> {
Expand All @@ -80,6 +81,7 @@ pub(crate) async fn build_frontend(
connectivity,
concurrency,
native_tls,
allow_insecure_host,
cache,
printer,
)
Expand Down Expand Up @@ -120,6 +122,7 @@ async fn build_impl(
connectivity: Connectivity,
concurrency: Concurrency,
native_tls: bool,
allow_insecure_host: &[TrustedHost],
cache: &Cache,
printer: Printer,
) -> Result<BuildResult> {
Expand All @@ -128,7 +131,6 @@ async fn build_impl(
index_locations,
index_strategy,
keyring_provider,
allow_insecure_host,
resolution: _,
prerelease: _,
dependency_metadata,
Expand All @@ -144,7 +146,8 @@ async fn build_impl(

let client_builder = BaseClientBuilder::default()
.connectivity(connectivity)
.native_tls(native_tls);
.native_tls(native_tls)
.allow_insecure_host(allow_insecure_host.to_vec());

// Determine the source to build.
let src = if let Some(src) = src {
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/pip/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub(crate) async fn pip_compile(
index_strategy: IndexStrategy,
dependency_metadata: DependencyMetadata,
keyring_provider: KeyringProviderType,
allow_insecure_host: Vec<TrustedHost>,
allow_insecure_host: &[TrustedHost],
config_settings: ConfigSettings,
connectivity: Connectivity,
no_build_isolation: bool,
Expand Down Expand Up @@ -110,7 +110,7 @@ pub(crate) async fn pip_compile(
.connectivity(connectivity)
.native_tls(native_tls)
.keyring(keyring_provider)
.allow_insecure_host(allow_insecure_host);
.allow_insecure_host(allow_insecure_host.to_vec());

// Read all requirements from the provided sources.
let RequirementsSpecification {
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/pip/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pub(crate) async fn pip_install(
index_strategy: IndexStrategy,
dependency_metadata: DependencyMetadata,
keyring_provider: KeyringProviderType,
allow_insecure_host: Vec<TrustedHost>,
reinstall: Reinstall,
link_mode: LinkMode,
compile: bool,
Expand All @@ -79,6 +78,7 @@ pub(crate) async fn pip_install(
prefix: Option<Prefix>,
concurrency: Concurrency,
native_tls: bool,
allow_insecure_host: &[TrustedHost],
cache: Cache,
dry_run: bool,
printer: Printer,
Expand All @@ -89,7 +89,7 @@ pub(crate) async fn pip_install(
.connectivity(connectivity)
.native_tls(native_tls)
.keyring(keyring_provider)
.allow_insecure_host(allow_insecure_host);
.allow_insecure_host(allow_insecure_host.to_vec());

// Read all requirements from the provided sources.
let RequirementsSpecification {
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/pip/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub(crate) async fn pip_sync(
index_strategy: IndexStrategy,
dependency_metadata: DependencyMetadata,
keyring_provider: KeyringProviderType,
allow_insecure_host: Vec<TrustedHost>,
allow_empty_requirements: bool,
connectivity: Connectivity,
config_settings: &ConfigSettings,
Expand All @@ -67,6 +66,7 @@ pub(crate) async fn pip_sync(
sources: SourceStrategy,
concurrency: Concurrency,
native_tls: bool,
allow_insecure_host: &[TrustedHost],
cache: Cache,
dry_run: bool,
printer: Printer,
Expand All @@ -75,7 +75,7 @@ pub(crate) async fn pip_sync(
.connectivity(connectivity)
.native_tls(native_tls)
.keyring(keyring_provider)
.allow_insecure_host(allow_insecure_host);
.allow_insecure_host(allow_insecure_host.to_vec());

// Initialize a few defaults.
let overrides = &[];
Expand Down
Loading

0 comments on commit a8c7c7f

Please sign in to comment.