Conversation
There was a problem hiding this comment.
why did this need to be a non static private function? I don't think it uses any member variable?
include/envoy/ssl/context_config.h
Outdated
source/common/secret/sds_api.cc
Outdated
There was a problem hiding this comment.
Can move subcription_ creation into the constructor so we don't need to store so many object references.
Only call start in the initialize() function
There was a problem hiding this comment.
We cannot move subcription_ into constructor. Envoy::Config::SubscriptionFactory::subscriptionFromConfigSourceenvoy::api::v2::auth::Secre will access members of those objects, which are not ready when SdsApi constructor is called. That causes segmentation fault in test runs.
There was a problem hiding this comment.
for easy to read, maybe create a member function removeDynamicSecretProvider() function, can the lambda function just call it.
There was a problem hiding this comment.
only save the callback when provider is not null.
You can do
if (secret_callback_) {
if (secret_callback_) {
secret_callback_->remove
}
secret_callback_ = &callback;
secret_callback_->add
}
source/common/ssl/ssl_socket.cc
Outdated
There was a problem hiding this comment.
Please add comment for this class
// This SslSocket will be used when SSL secret is not fetched from SDS server.
There was a problem hiding this comment.
You can call erase() directly, then check the return value. If 0, log an error.
There was a problem hiding this comment.
may not need this variable, just use the lambda directly in the function argument. such
xxx(....,
[map_key, this] () { removeDynamicSecretProvider(map_key); }
);
1c67da7 to
5b9e45f
Compare
|
Can you merge master and run clang-format on 6.0 per #4168? |
854b7af to
b4a354d
Compare
|
@lizan I have run clang-format on 6.0 |
| @@ -0,0 +1,22 @@ | |||
| #pragma once | |||
|
|
|||
| #include <memory> | |||
| @@ -0,0 +1,21 @@ | |||
| #pragma once | |||
|
|
|||
| #include <string> | |||
f1c054b to
02e1c52
Compare
mattklein123
left a comment
There was a problem hiding this comment.
Thanks for the hard work here and extra thanks for the integration tests. It gives me good confidence this change works. Nice! I have some high level comments to get started with. FYI, @htuch is going to take over senior maintainer review on this since I am out for a month starting tomorrow. Thank you!
There was a problem hiding this comment.
nit: It would probably be better to just move this interface into the secret or SSL/TLS namespace but not a big deal.
There was a problem hiding this comment.
Thanks, I will keep this.
include/envoy/ssl/context_config.h
Outdated
There was a problem hiding this comment.
Do we need the forward declare here?
There was a problem hiding this comment.
I have removed this forward declaration and included secret_callbacks.h.
include/envoy/ssl/context_config.h
Outdated
There was a problem hiding this comment.
Can we add more information about what ready means?
include/envoy/ssl/context_config.h
Outdated
There was a problem hiding this comment.
Can you add more information about when callbacks will be invoked? It's not clear at the interface level why/when this happens.
There was a problem hiding this comment.
More information is added into comment. Thanks.
There was a problem hiding this comment.
It's not optimal that this interface has a setter and a getter for the init manager. Is there any way to simplify this so that the init manager is known ahead of time and we only need a getter?
There was a problem hiding this comment.
Ideally the init manager should exist when we create TransportSocketFactoryContext, so that we only need a getter. But we create TransportSocketFactoryContext at ClusterManagerFactory and then create init manager per cluster, we have to add it into factory context. @qiwzhang proposed #3831, I think once we are working on that, we can get rid of this setter.
There was a problem hiding this comment.
Shouldn't the init manager then be part of the factory context?
There was a problem hiding this comment.
For now, init manager is per cluster. At the time of the construction of TransportSocketFactoryContext, per cluster init manager is not available. We have to set it when init manager is available.
source/common/ssl/ssl_socket.cc
Outdated
There was a problem hiding this comment.
Do we really need this? What causes us to require an instantiated connection? Can't we cause the control flow to return in such a way that there is no socket and we just fail whatever we are doing?
There was a problem hiding this comment.
Our first attempt was to return nullptr in socket creation when ssl_context is not ready (SDS client failed to get secret). This works for ListenerImpl, but did not work for ClusterImpl. After looked at the ClusterImpl codes, most of them do not expect nullptr socket nor nullptr connection. It will require a lot of code changes to make these code to handle null connection.
For less code change, we decided to return such dummy socket which would just reset the connect.
There was a problem hiding this comment.
I don't have an opinion on whether this is the best course of action or not. @htuch hopefully can have a look. In general I would prefer that we don't do this but if it's the best way I can accept that.
source/common/ssl/ssl_socket.cc
Outdated
There was a problem hiding this comment.
Pretty positive this needs locking. I think you will be accessing ssl_ctx_ across threads to make transport sockets. Thus, you will need a R/W lock here and ultimately should move to using TLS but a R/W lock is OK for now? I think at a high level having a locking/threading analysis of this change would be useful. Can you add that to the description somewhere?
There was a problem hiding this comment.
Good point! Thanks! Will add R/W lock.
There was a problem hiding this comment.
I have added a lock to protect read/write to ssl_ctx_, and added comments.
There was a problem hiding this comment.
I don't think you will need a lock beyond what shared_ptr already provide, it seems unnecessary. Though you might want to have a local variable of shared_ptr during create socket, so the access to the member variable is always atomic.
There was a problem hiding this comment.
@lizan Thanks for pointing this out. Yes the lock is not necessary as we already use shared_ptr. They are removed.
source/common/ssl/ssl_socket.cc
Outdated
There was a problem hiding this comment.
Locking. Is there a way to share this code in a base class somehow? Would prefer to not implement a bunch of this twice.
There was a problem hiding this comment.
Lock is added, thanks! ServerSslSocketFactory::onAddOrUpdateSecret() and ClientSslSocketFactory::onAddOrUpdateSecret() are different, one owns ServerContextSharedPtr ssl_ctx_ and the other owns ClientContextSharedPtr ssl_ctx_, and they are created by calling different methods at context manager. I would like to leave this method in separate class.
There was a problem hiding this comment.
Please move init_manager_impl out of server/ and into a new subdirectory in source/ called init/. Feel free to do this in a followup but please add a TODO.
There was a problem hiding this comment.
Added TODO in init_manager_impl.h. Thanks.
There was a problem hiding this comment.
Remove references to SDS or make it clear that SDS is one of the things that init manager is used for. We are likely to add other things in the future.
There was a problem hiding this comment.
Removed references to SDS from comment. Thanks.
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
d7fe495 to
d6eb302
Compare
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
htuch
left a comment
There was a problem hiding this comment.
Some comments to get started. This is a pretty huge PR; FWIW, I strongly encourage shorter PRs for reviewabilty and velocity.
| * Finds and returns a dynamic secret provider associated to SDS config. Create | ||
| * a new one if such provider does not exist. | ||
| * | ||
| * @param config_source a protobuf message object contains SDS config source. |
| * a new one if such provider does not exist. | ||
| * | ||
| * @param config_source a protobuf message object contains SDS config source. | ||
| * @param config_name a name that uniquely refers to the SDS config source |
There was a problem hiding this comment.
Nit: full stop at end of sentence.
| * @param config_name a name that uniquely refers to the SDS config source | ||
| * @param secret_provider_context context that provides components for creating and initializing | ||
| * secret provider. | ||
| * @return the dynamic TLS secret provider. |
There was a problem hiding this comment.
Nit: @return TlsCertificateConfigProviderSharedPtr the dynamic TLS secret provider.
|
|
||
| // TODO(lizan): Add more methods for dynamic secret provider. | ||
| /** | ||
| * Add secret callback into secret provider. |
There was a problem hiding this comment.
Can you add some comments on thread safety? E.g. from which threads is it safe to call this, on which thread will the callback be invoked?
There was a problem hiding this comment.
Comments are added. Thanks.
There was a problem hiding this comment.
Shouldn't the init manager then be part of the factory context?
source/common/secret/sds_api.cc
Outdated
| } | ||
| const auto& secret = resources[0]; | ||
| MessageUtil::validate(secret); | ||
| if (!(secret.name() == sds_config_name_)) { |
| void SecretManagerImpl::removeDynamicSecretProvider(const std::string& map_key) { | ||
| ENVOY_LOG(debug, "Unregister secret provider. hash key: {}", map_key); | ||
|
|
||
| ASSERT(dynamic_secret_providers_.erase(map_key) == 1); |
There was a problem hiding this comment.
This should be RELEASE_ASSERT; otherwise in opt builds, this entire line disappears.
There was a problem hiding this comment.
Thanks for pointing that out. Fixed.
| TlsCertificateConfigProviderSharedPtr SecretManagerImpl::findOrCreateDynamicSecretProvider( | ||
| const envoy::api::v2::core::ConfigSource& sds_config_source, const std::string& config_name, | ||
| Server::Configuration::TransportSocketFactoryContext& secret_provider_context) { | ||
| std::string map_key = std::to_string(MessageUtil::hash(sds_config_source)) + config_name; |
| ASSERT(secret_provider_context.initManager() != nullptr); | ||
|
|
||
| std::function<void()> unregister_secret_provider = [map_key, this]() { | ||
| removeDynamicSecretProvider(map_key); |
There was a problem hiding this comment.
Maybe add some lifetime comments here. @ambuc recently hit issues where these kinds of callbacks were invoked and the equivalent of SdsApi outlived the equivalent of SecreteManagerImpl (this was in ListenerManager).
There was a problem hiding this comment.
The lifetime issue has been captured by integration tests. We have adjusted the order of secret manager and other components to make sure SdsApi objects are destroyed before SecretManagerImpl. Comments are added. Thanks.
source/common/ssl/ssl_socket.cc
Outdated
| return std::make_unique<Ssl::SslSocket>(ssl_ctx_, Ssl::InitialState::Client); | ||
| // SDS would update ssl_ctx_ when Envoy is running. | ||
| // Need a read lock to let multiple threads gain read access to ssl_ctx_. | ||
| std::shared_lock<std::shared_timed_mutex> lock(ssl_ctx_mutex_); |
There was a problem hiding this comment.
I haven't looked into this yet, but this is something I'd like to understand the necessity for better; usually in Envoy, needing to do shared memory concurrency is not needed, and other mechanisms like TLS posting are the right solution.
|
@JimmyCYJ also, personal plea to avoid force push; general GH etiquette avoids this to make reviewer lives easier (so they can just look a the delta between each PR). |
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
|
This PR didn't update correctly. I am going to close this one and create a new PR. |
|
I have created PR #4256, please take a look. Thanks! |
Description: Implement SDS api that fetches secrets from remote SDS server. Secrets are stored in Secret Provider. Listeners and Clusters are updated when secrets are received.
Risk Level: Low
Testing: Unit tests and integration tests
Fixes #1194
Signed-off-by: Jimmy Chen jimmychen.0102@gmail.com