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 all commits
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
7 changes: 7 additions & 0 deletions docs/source/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ 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 TLS/SSL Validation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Bypassing TLS/SSL validation" (lowercase validation)


In some configurations (often on internal networks) users may need Rover to communicate over encrypted channels (e.g., HTTPS) but avoid the more stringent digital certificate verifications which validate hostnames or may even wish to bypass the digital certificate validation entirely. This is generally not recommended and considered to be much less secure but for cases where it's necessary, there are two flags you can use to configure how Rover validates HTTPS requests:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace all instances of "may" with "might" where equivalent

Comma after "networks)"

"users may need" -> "you might need"

"which validate hostnames" -> "that validate hostnames." (end sentence)

"or may even wish" -> "You might even need"


- 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"will disable" -> "disables"

"man-in-the-middle" -> "person-in-the-middle" ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"any valid certificate for any site will be trusted for use from any other" <- Not 100% sure what this means?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"any valid certificate for any site will be trusted for use from any other"

if i understand correctly (this is yanked pretty much directly from the underlying library's docs) it'll just skip the step where it compares a specified hostname (like api.apollographql.com) to your local certs, meaning a cert for maliciouscert.com could be used in its place (but sometimes skipping this check is desirable on internal networks)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


- 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"will disable" -> "disables"

"will be trusted" -> "is trusted"

## 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