Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds options to bypass SSL validation #837

Merged
merged 3 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ git-url-parse = "0.3"
git2 = { version = "0.13", default-features = false, features = ["vendored-openssl"] }
harmonizer = { version = "0.27.0", optional = true }
heck = "0.3"
lazycell = "1"
opener = "0.5"
os_info = "3.0"
prettytable-rs = "0.8"
Expand Down
8 changes: 8 additions & 0 deletions docs/source/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ If you use a version control system besides Git, you can use the environment var

Currently, only Git is fully supported by Apollo Studio.

## Bypass SSL/TLS Validation
EverlastingBugstopper marked this conversation as resolved.
Show resolved Hide resolved

Sometimes, you may want to perform HTTPS requests from Rover, but skip validation checks. This is generally not recommended and insecure, but there are two flags you can use to configure how Rover validates HTTPS requests.

The `--insecure-accept-invalid-hostnames` flag will disable hostname validation. If hostname verification is not used, any valid certificate for any site will be trusted for use from any other. This introduces a significant vulnerability to man-in-the-middle attacks.

The `--insecure-accept-invalid-certs` flag will disable certificate validation. If invalid certificates are trusted, any certificate for any site will be trusted for use. This includes expired certificates. This introduces significant vulnerabilities, and should only be used as a last resort.

EverlastingBugstopper marked this conversation as resolved.
Show resolved Hide resolved
## Supported environment variables

You can configure Rover's behavior by setting the environment variables listed below.
Expand Down
48 changes: 44 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use camino::Utf8PathBuf;
use lazycell::AtomicLazyCell;
use reqwest::blocking::Client;
use serde::Serialize;
use structopt::{clap::AppSettings, StructOpt};

use crate::command::output::JsonOutput;
use crate::command::{self, RoverOutput};
use crate::utils::{
client::StudioClientConfig,
client::{get_configured_client, StudioClientConfig},
env::{RoverEnv, RoverEnvKey},
stringify::option_from_display,
version,
Expand Down Expand Up @@ -66,13 +67,40 @@ pub struct Rover {
#[structopt(long = "output", default_value = "plain", possible_values = &["json", "plain"], case_insensitive = true, global = true)]
output_type: OutputType,

/// Accept invalid certificates when performing HTTPS requests.
///
/// You should think very carefully before using this flag.
///
/// If invalid certificates are trusted, any certificate for any site will be trusted for use.
/// This includes expired certificates.
/// This introduces significant vulnerabilities, and should only be used as a last resort.
#[structopt(
long = "insecure-accept-invalid-certs",
case_insensitive = true,
global = true
)]
accept_invalid_certs: bool,

/// Accept invalid hostnames when performing HTTPS requests.
///
/// You should think very carefully before using this flag.
///
/// If hostname verification is not used, any valid certificate for any site will be trusted for use from any other.
/// This introduces a significant vulnerability to man-in-the-middle attacks.
#[structopt(
long = "insecure-accept-invalid-hostnames",
case_insensitive = true,
global = true
)]
accept_invalid_hostnames: bool,

#[structopt(skip)]
#[serde(skip_serializing)]
pub(crate) env_store: RoverEnv,

#[structopt(skip)]
#[serde(skip_serializing)]
client: Client,
client: AtomicLazyCell<Client>,
EverlastingBugstopper marked this conversation as resolved.
Show resolved Hide resolved
}

impl Rover {
Expand Down Expand Up @@ -214,8 +242,20 @@ impl Rover {
}

pub(crate) fn get_reqwest_client(&self) -> Client {
// we can use clone here freely since `reqwest` uses an `Arc` under the hood
self.client.clone()
// return a clone of the underlying client if it's already been populated
if let Some(client) = self.client.borrow() {
// we can use clone here freely since `reqwest` uses an `Arc` under the hood
client.clone()
} else {
// if a request hasn't been made yet, this cell won't be populated yet
self.client
.fill(
get_configured_client(self.accept_invalid_certs, self.accept_invalid_hostnames)
.expect("Could not configure the request client"),
)
.expect("Could not overwrite the existing request client");
self.get_reqwest_client()
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/utils/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ use rover_client::blocking::StudioClient;
/// the Apollo graph registry's production API endpoint
const STUDIO_PROD_API_ENDPOINT: &str = "https://graphql.api.apollographql.com/api/graphql";

pub(crate) fn get_configured_client(
accept_invalid_certs: bool,
accept_invalid_hostnames: bool,
) -> Result<Client> {
let client = Client::builder()
.gzip(true)
.brotli(true)
.danger_accept_invalid_certs(accept_invalid_certs)
.danger_accept_invalid_hostnames(accept_invalid_hostnames)
.build()?;
Ok(client)
}

pub struct StudioClientConfig {
pub(crate) config: config::Config,
client: Client,
Expand Down