-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add separate SPIFFE integeration test build target. #15324
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
test/extensions/transport_sockets/tls/integration/spiffe_cert_validator_integration_test.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| #include "spiffe_cert_validator_integration_test.h" | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "extensions/transport_sockets/tls/context_manager_impl.h" | ||
|
|
||
| #include "test/integration/integration.h" | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Ssl { | ||
|
|
||
| void SslSPIFFECertValidatorIntegrationTest::initialize() { | ||
| config_helper_.addSslConfig( | ||
| ConfigHelper::ServerSslOptions().setRsaCert(true).setTlsV13(true).setCustomValidatorConfig( | ||
| custom_validator_config_)); | ||
| HttpIntegrationTest::initialize(); | ||
|
|
||
| context_manager_ = | ||
| std::make_unique<Extensions::TransportSockets::Tls::ContextManagerImpl>(timeSystem()); | ||
| registerTestServerPorts({"http"}); | ||
| } | ||
|
|
||
| void SslSPIFFECertValidatorIntegrationTest::TearDown() { | ||
| HttpIntegrationTest::cleanupUpstreamAndDownstream(); | ||
| codec_client_.reset(); | ||
| context_manager_.reset(); | ||
| } | ||
|
|
||
| Network::ClientConnectionPtr SslSPIFFECertValidatorIntegrationTest::makeSslClientConnection( | ||
| const ClientSslTransportOptions& options) { | ||
| ClientSslTransportOptions modified_options{options}; | ||
| modified_options.setTlsVersion(tls_version_); | ||
|
|
||
| Network::Address::InstanceConstSharedPtr address = getSslAddress(version_, lookupPort("http")); | ||
| auto client_transport_socket_factory_ptr = | ||
| createClientSslTransportSocketFactory(modified_options, *context_manager_, *api_); | ||
| return dispatcher_->createClientConnection( | ||
| address, Network::Address::InstanceConstSharedPtr(), | ||
| client_transport_socket_factory_ptr->createTransportSocket({}), nullptr); | ||
| } | ||
|
|
||
| void SslSPIFFECertValidatorIntegrationTest::checkVerifyErrorCouter(uint64_t value) { | ||
| Stats::CounterSharedPtr counter = | ||
| test_server_->counter(listenerStatPrefix("ssl.fail_verify_error")); | ||
| EXPECT_EQ(value, counter->value()); | ||
| counter->reset(); | ||
| } | ||
|
|
||
| INSTANTIATE_TEST_SUITE_P( | ||
| IpVersionsClientVersions, SslSPIFFECertValidatorIntegrationTest, | ||
| testing::Combine( | ||
| testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), | ||
| testing::Values(envoy::extensions::transport_sockets::tls::v3::TlsParameters::TLSv1_2, | ||
| envoy::extensions::transport_sockets::tls::v3::TlsParameters::TLSv1_3)), | ||
| SslSPIFFECertValidatorIntegrationTest::ipClientVersionTestParamsToString); | ||
|
|
||
| // clientcert.pem's san is "spiffe://lyft.com/frontend-team" so it should be accepted. | ||
| TEST_P(SslSPIFFECertValidatorIntegrationTest, ServerRsaSPIFFEValidatorAccepted) { | ||
| auto typed_conf = new envoy::config::core::v3::TypedExtensionConfig(); | ||
| TestUtility::loadFromYaml(TestEnvironment::substitute(R"EOF( | ||
| name: envoy.tls.cert_validator.spiffe | ||
| typed_config: | ||
| "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.SPIFFECertValidatorConfig | ||
| trust_domains: | ||
| - name: lyft.com | ||
| trust_bundle: | ||
| filename: "{{ test_rundir }}/test/config/integration/certs/cacert.pem" | ||
| )EOF"), | ||
| *typed_conf); | ||
|
|
||
| custom_validator_config_ = typed_conf; | ||
| ConnectionCreationFunction creator = [&]() -> Network::ClientConnectionPtr { | ||
| return makeSslClientConnection({}); | ||
| }; | ||
| testRouterRequestAndResponseWithBody(1024, 512, false, false, &creator); | ||
| checkVerifyErrorCouter(0); | ||
| } | ||
|
|
||
| // clientcert.pem's san is "spiffe://lyft.com/frontend-team" so it should be rejected. | ||
| TEST_P(SslSPIFFECertValidatorIntegrationTest, ServerRsaSPIFFEValidatorRejected1) { | ||
| auto typed_conf = new envoy::config::core::v3::TypedExtensionConfig(); | ||
| TestUtility::loadFromYaml(TestEnvironment::substitute(R"EOF( | ||
| name: envoy.tls.cert_validator.spiffe | ||
| typed_config: | ||
| "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.SPIFFECertValidatorConfig | ||
| trust_domains: | ||
| - name: example.com | ||
| trust_bundle: | ||
| filename: "{{ test_rundir }}/test/config/integration/certs/cacert.pem" | ||
| )EOF"), | ||
| *typed_conf); | ||
| custom_validator_config_ = typed_conf; | ||
| initialize(); | ||
| auto conn = makeSslClientConnection({}); | ||
| if (tls_version_ == envoy::extensions::transport_sockets::tls::v3::TlsParameters::TLSv1_2) { | ||
| auto codec = makeRawHttpConnection(std::move(conn), absl::nullopt); | ||
| EXPECT_FALSE(codec->connected()); | ||
| } else { | ||
| auto codec = makeHttpConnection(std::move(conn)); | ||
| ASSERT_TRUE(codec->waitForDisconnect()); | ||
| codec->close(); | ||
| } | ||
| checkVerifyErrorCouter(1); | ||
| } | ||
|
|
||
| // clientcert.pem's san is "spiffe://lyft.com/frontend-team" but the corresponding trust bundle does | ||
| // not match with the client cert. So this should also be rejected. | ||
| TEST_P(SslSPIFFECertValidatorIntegrationTest, ServerRsaSPIFFEValidatorRejected2) { | ||
| auto typed_conf = new envoy::config::core::v3::TypedExtensionConfig(); | ||
| TestUtility::loadFromYaml(TestEnvironment::substitute(R"EOF( | ||
| name: envoy.tls.cert_validator.spiffe | ||
| typed_config: | ||
| "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.SPIFFECertValidatorConfig | ||
| trust_domains: | ||
| - name: lyft.com | ||
| trust_bundle: | ||
| filename: "{{ test_rundir }}/test/extensions/transport_sockets/tls/test_data/fake_ca_cert.pem" | ||
| - name: example.com | ||
| trust_bundle: | ||
| filename: "{{ test_rundir }}/test/config/integration/certs/cacert.pem" | ||
| )EOF"), | ||
| *typed_conf); | ||
| custom_validator_config_ = typed_conf; | ||
| initialize(); | ||
| auto conn = makeSslClientConnection({}); | ||
| if (tls_version_ == envoy::extensions::transport_sockets::tls::v3::TlsParameters::TLSv1_2) { | ||
| auto codec = makeRawHttpConnection(std::move(conn), absl::nullopt); | ||
| EXPECT_FALSE(codec->connected()); | ||
| } else { | ||
| auto codec = makeHttpConnection(std::move(conn)); | ||
| ASSERT_TRUE(codec->waitForDisconnect()); | ||
| codec->close(); | ||
| } | ||
| checkVerifyErrorCouter(1); | ||
| } | ||
|
|
||
| } // namespace Ssl | ||
| } // namespace Envoy |
49 changes: 49 additions & 0 deletions
49
test/extensions/transport_sockets/tls/integration/spiffe_cert_validator_integration_test.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "test/integration/http_integration.h" | ||
| #include "test/integration/server.h" | ||
| #include "test/integration/ssl_utility.h" | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Ssl { | ||
|
|
||
| class SslSPIFFECertValidatorIntegrationTest | ||
| : public testing::TestWithParam< | ||
| std::tuple<Network::Address::IpVersion, | ||
| envoy::extensions::transport_sockets::tls::v3::TlsParameters::TlsProtocol>>, | ||
| public HttpIntegrationTest { | ||
| public: | ||
| SslSPIFFECertValidatorIntegrationTest() | ||
| : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, std::get<0>(GetParam())) {} | ||
|
|
||
| void initialize() override; | ||
| void TearDown() override; | ||
|
|
||
| virtual Network::ClientConnectionPtr | ||
| makeSslClientConnection(const ClientSslTransportOptions& options); | ||
| void checkVerifyErrorCouter(uint64_t value); | ||
|
|
||
| static std::string ipClientVersionTestParamsToString( | ||
| const ::testing::TestParamInfo< | ||
| std::tuple<Network::Address::IpVersion, | ||
| envoy::extensions::transport_sockets::tls::v3::TlsParameters::TlsProtocol>>& | ||
| params) { | ||
| return fmt::format("{}_TLSv1_{}", | ||
| std::get<0>(params.param) == Network::Address::IpVersion::v4 ? "IPv4" | ||
| : "IPv6", | ||
| std::get<1>(params.param) - 1); | ||
| } | ||
|
|
||
| protected: | ||
| envoy::config::core::v3::TypedExtensionConfig* custom_validator_config_{nullptr}; | ||
| std::unique_ptr<ContextManager> context_manager_; | ||
| const envoy::extensions::transport_sockets::tls::v3::TlsParameters::TlsProtocol tls_version_{ | ||
| std::get<1>(GetParam())}; | ||
| }; | ||
|
|
||
| } // namespace Ssl | ||
| } // namespace Envoy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.