Skip to content

envoy: allowing alt-svc from IPs, fixing HTTP/3 cert bypass - #35551

Merged
alyssawilk merged 11 commits into
envoyproxy:mainfrom
alyssawilk:cronet
Aug 6, 2024
Merged

alyssawilk merged 11 commits into
envoyproxy:mainfrom
alyssawilk:cronet

Conversation

@alyssawilk

Copy link
Copy Markdown
Contributor

This adds a real HTTP/3 test for Envoy mobile's Cronet APIs.
In order for this to work it fixes 2 issues in Envoy, the first that the connection grid didn't do lookups for ip based hostname. The second that ACCEPT_UNTRUSTED didn't fully work for QUIC.

Risk Level: low
Testing: e2e test
Docs Changes: n/a
Release Notes: inline
[Optional Runtime guard:] guarded both functional changes

@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #35551 was opened by alyssawilk.

see: more, trace.

@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/runtime-guard-changes: FYI only for changes made to (source/common/runtime/runtime_features.cc).

🐱

Caused by: #35551 was opened by alyssawilk.

see: more, trace.

@alyssawilk
alyssawilk marked this pull request as ready for review August 1, 2024 17:37
@alyssawilk

Copy link
Copy Markdown
Contributor Author

not sure if this will pass CI - I only ran the new test so there may be extra cleanup I need to do. Either way I'd appreciate @fredyw doing a pass of my horrible Java, and @RyanTheOptimist telling me if you think this a valid workaround for the handshake problem (i.e. if I'm not abusing https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/transport_sockets/tls/v3/common.proto#enum-extensions-transport-sockets-tls-v3-certificatevalidationcontext-trustchainverification)

@alyssawilk

Copy link
Copy Markdown
Contributor Author

oh and also @RyanTheOptimist let me know if I should split out one or both functional changes. I feel weird doing 2 runtime guards in one PR but they're both so bitty I also didn't want to deluge everyone with PRs

"This is a simple text file served by QUIC.\n",
Collections.emptyMap());
// Next set up the HTTP/2 server, advertising HTTP/3 support for the HTTP/3 server
String alt_svc = "h3=\":" + mHttp3TestServer.getPort() + "\"; ma=86400";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: altSvc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

butIWantMySnakeCase! ;-) (fixed)


// If true, dump envoy logs on test completion.
// Ideally we could override this from the command line but that's TBD.
boolean mPrintEnvoyLogs = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: can be made private.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

// The log file name, set up if mPrintEnvoyLogs is true.
private String mLogFilename;
// The engine for this test.
CronvoyUrlRequestContext mCronvoyEngine;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: can be made private.

JniLibrary.loadTestLibrary();
}

public void setUp(boolean setUpLogging) throws Exception {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can add @Before annotation here, so we don't need to explicitly call setup in each test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah I'd had that before but I thought it might be useful to have the option of turning up debug logging for a single test once we had a bunch. I can put it back if you prefer though

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense.


// Optionally, set up logging. This will slow down the tests a bit but make debugging much
// easier.
if (setUpLogging) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of using netlog, there's another way to show Envoy logs via

private CronvoyLogger mLogger  = new CronvoyLogger() {
  @Override
  public void log(int logLevel, String message) {
    System.out.print(message);
  }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

very good call - done


// Do a request to https://127.0.0.1:test_server_port/
TestUrlRequestCallback callback = new TestUrlRequestCallback();
String mNewUrl = "https://" + mHttp2TestServer.getAddress() + "/";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: newUrl

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch

// Ideally we could override this from the command line but that's TBD.
boolean mPrintEnvoyLogs = false;
// The HTTP/2 server, set up to alt-svc to the HTTP/3 server
private HttpTestServerFactory.HttpTestServer mHttp2TestServer;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

optional: In Java, the convention is to use camelCase and not Hungarian notation although there's a lot of existing code in Envoy Mobile that uses Hungarian notation. Since this is a new file, let's use camelCase.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SG

mCronvoyEngine = new CronvoyUrlRequestContext(nativeCronetEngineBuilder);

// Do a request to https://127.0.0.1:test_server_port/
TestUrlRequestCallback callback = new TestUrlRequestCallback();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Maybe call this callback1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SG

Signed-off-by: Alyssa Wilk <[email protected]>

@alyssawilk alyssawilk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for the review!


// If true, dump envoy logs on test completion.
// Ideally we could override this from the command line but that's TBD.
boolean mPrintEnvoyLogs = false;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

// Ideally we could override this from the command line but that's TBD.
boolean mPrintEnvoyLogs = false;
// The HTTP/2 server, set up to alt-svc to the HTTP/3 server
private HttpTestServerFactory.HttpTestServer mHttp2TestServer;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SG

JniLibrary.loadTestLibrary();
}

public void setUp(boolean setUpLogging) throws Exception {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah I'd had that before but I thought it might be useful to have the option of turning up debug logging for a single test once we had a bunch. I can put it back if you prefer though

"This is a simple text file served by QUIC.\n",
Collections.emptyMap());
// Next set up the HTTP/2 server, advertising HTTP/3 support for the HTTP/3 server
String alt_svc = "h3=\":" + mHttp3TestServer.getPort() + "\"; ma=86400";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

butIWantMySnakeCase! ;-) (fixed)


// Optionally, set up logging. This will slow down the tests a bit but make debugging much
// easier.
if (setUpLogging) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

very good call - done

mCronvoyEngine = new CronvoyUrlRequestContext(nativeCronetEngineBuilder);

// Do a request to https://127.0.0.1:test_server_port/
TestUrlRequestCallback callback = new TestUrlRequestCallback();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SG


// Do a request to https://127.0.0.1:test_server_port/
TestUrlRequestCallback callback = new TestUrlRequestCallback();
String mNewUrl = "https://" + mHttp2TestServer.getAddress() + "/";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch

Signed-off-by: Alyssa Wilk <[email protected]>

@RyanTheOptimist RyanTheOptimist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few small comments on the C++. I'll leave the Java to Fredy! :)

const std::string hostname_;
// Leaf cert needs to be retained in case of asynchronous validation.
std::string leaf_cert_;
const bool accept_untrusted_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: might be worth a comment, perhaps mentioning that this should really only be true in tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in .h flile

public:
explicit EnvoyQuicProofVerifier(Envoy::Ssl::ClientContextSharedPtr&& context)
: context_(std::move(context)) {
explicit EnvoyQuicProofVerifier(Envoy::Ssl::ClientContextSharedPtr&& context,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or alternatively comment here about accept_untrusted?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah I'll point at the docs, which don't mention tests probabably because people do terrible things in prod too =P

Comment thread source/common/http/conn_pool_grid.cc Outdated
return options->serverNameOverride().value();
}
return std::string(transport_socket_factory.defaultServerNameIndication());
std::string transport = std::string(host->transportSocketFactory().defaultServerNameIndication());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: should this variable perhaps be named default_sni?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good call

return std::string(transport_socket_factory.defaultServerNameIndication());
std::string transport = std::string(host->transportSocketFactory().defaultServerNameIndication());
if (!transport.empty() ||
!Runtime::runtimeFeatureEnabled("envoy.reloadable_features.allow_alt_svc_for_ips")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IPs are illegal in the TLS SNI extension so if this method were actually returning the SNI, this would be bad. But it seems like that's not really what this method returns. Instead it's returning something like the target hostname? So how 'bout we rename this method to getTargetHostname()? Or something better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SGTM

Signed-off-by: Alyssa Wilk <[email protected]>
RyanTheOptimist
RyanTheOptimist previously approved these changes Aug 1, 2024
!Runtime::runtimeFeatureEnabled("envoy.reloadable_features.allow_alt_svc_for_ips")) {
return transport;
}
return host->hostname();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this supposed to be an IP string?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, otherwise the SNI checks return the hostname

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you comment "if there is no configured SNI, try to return IP string as the host name"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, done

if (!succeeded) {
error = error_details;
} else {
} else if (!accept_untrusted_ || !Runtime::runtimeFeatureEnabled(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need this for E-M test to pass?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The platform verifier code respects envoy::extensions::transport_sockets::tls::v3::CertificateValidationContext::ACCEPT_UNTRUSTED but the quic proof verifier complains about
49] Client: Closing connection: c145fcaf20ae11af, with wire error: CRYPTO_ERROR(certificate unknown), error: QUIC_TLS_CERTIFICATE_UNKNOWN, and details: TLS handshake failure (ENCRYPTION_HANDSHAKE) 46: certificate unknown
I'd think if I ask to accept untrusted certs I'd accept this unknown cert but it's broken without this change

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, I see. The test uses IP address as the host but the test server sends a test cert for lyft.com. Fair enough!

fredyw
fredyw previously approved these changes Aug 1, 2024
Signed-off-by: Alyssa Wilk <[email protected]>
@alyssawilk
alyssawilk dismissed stale reviews from fredyw and RyanTheOptimist via 000b019 August 1, 2024 19:40
@alyssawilk

Copy link
Copy Markdown
Contributor Author

/retest

Signed-off-by: Alyssa Wilk <[email protected]>
RyanTheOptimist
RyanTheOptimist previously approved these changes Aug 5, 2024
s
Signed-off-by: Alyssa Wilk <[email protected]>
RyanTheOptimist
RyanTheOptimist previously approved these changes Aug 5, 2024
@alyssawilk

Copy link
Copy Markdown
Contributor Author

/wait on CI

Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Alyssa Wilk <[email protected]>
@alyssawilk

Copy link
Copy Markdown
Contributor Author

/retest

@alyssawilk
alyssawilk merged commit aa8d0f7 into envoyproxy:main Aug 6, 2024
martinduke pushed a commit to martinduke/envoy that referenced this pull request Aug 8, 2024
…xy#35551)

This adds a real HTTP/3 test for Envoy mobile's Cronet APIs.
In order for this to work it fixes 2 issues in Envoy, the first that the
connection grid didn't do lookups for ip based hostname. The second that
ACCEPT_UNTRUSTED didn't fully work for QUIC.

Risk Level: low
Testing: e2e test
Docs Changes: n/a
Release Notes: inline
[Optional Runtime guard:] guarded both functional changes

---------

Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Martin Duke <[email protected]>
asingh-g pushed a commit to asingh-g/envoy that referenced this pull request Aug 20, 2024
…xy#35551)

This adds a real HTTP/3 test for Envoy mobile's Cronet APIs.
In order for this to work it fixes 2 issues in Envoy, the first that the
connection grid didn't do lookups for ip based hostname. The second that
ACCEPT_UNTRUSTED didn't fully work for QUIC.

Risk Level: low
Testing: e2e test
Docs Changes: n/a
Release Notes: inline
[Optional Runtime guard:] guarded both functional changes

---------

Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: asingh-g <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants