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

fix(common): missed using CARootsFilePathOption #12997

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
30 changes: 25 additions & 5 deletions google/cloud/credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,37 @@ struct AccessTokenLifetimeOption {
* Configures a custom CA (Certificates Authority) certificates file.
*
* Most applications should use the system's root certificates and should avoid
* setting this option unnecessarily. A common exception to this recommendation
* are containerized applications. These often deploy without system's root
* certificates and need to explicitly configure a root of trust.
* setting this option unnecessarily.
*
* The value of this option should be the name of a file in [PEM format].
* Consult your security team and/or system administrator for the contents of
* this file. Be aware of the security implications of adding new CA
* certificates to this file. Only use trustworthy sources for the CA
* certificates.
*
* The most common cases where this option is needed include:
*
* - Containerized applications that deploy without the system's root
* certificates and need to explicitly configure a root of trust.
* - Applications using gRPC-based services on Windows and macOS, where gRPC
* does not use the default root of trust. Though it might be possible to
* set the `GRPC_DEFAULT_SSL_ROOTS_FILE_PATH` environment variable instead.
*
* You should set this option both in the credentials and the client options.
Copy link
Member

Choose a reason for hiding this comment

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

s/and the client options/and in the connection options/

They would not apply if passed to the client only, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

* For example:
* @code
* using gc = ::google::cloud;
Copy link
Member

Choose a reason for hiding this comment

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

s/using/namespace/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

* auto ca = gc::Options{}.set<gc::CARootsFilePathOption>("path/to/roots.pem");
* auto credentials = gc::MakeServiceAccountCredentials(..., ca);
* // Make a copy, only needed if you plan to use `ca` again.
* auto opts = ca;
* // Using bigtable to illustrate the option usage, this applies to all
* // libraries in `google-cloud-cpp`.
* auto connection = gc::bigtable::MakeDataConnection(
* opts.set<gc::UnifiedCredentialsOption>(credentials));
* // Use `connection` as usual.
* @endcode
*
* For REST-based libraries this configures the [CAINFO option] in libcurl.
* These are used for all credentials that require authentication, including the
* default credentials.
Expand All @@ -325,8 +346,7 @@ struct AccessTokenLifetimeOption {
*
* @warning gRPC does not have a programmatic mechanism to set the CA
* certificates for the default credentials. This option only has no effect
* with `MakeGoogleDefaultCredentials()`, or
* `MakeServiceAccountCredentials()`.
* with `MakeGoogleDefaultCredentials()`.
* Consider using the `GRPC_DEFAULT_SSL_ROOTS_FILE_PATH` environment
* variable in these cases.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ GrpcServiceAccountAuthentication::GrpcServiceAccountAuthentication(

std::shared_ptr<grpc::Channel> GrpcServiceAccountAuthentication::CreateChannel(
std::string const& endpoint, grpc::ChannelArguments const& arguments) {
// TODO(#6311) - support setting SSL options
auto credentials = grpc::SslCredentials(grpc::SslCredentialsOptions{});
auto credentials = grpc::SslCredentials(ssl_options_);
return grpc::CreateCustomChannel(endpoint, credentials, arguments);
}

Expand Down
5 changes: 4 additions & 1 deletion google/cloud/internal/unified_grpc_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ std::shared_ptr<GrpcAuthenticationStrategy> CreateAuthenticationStrategy(
cfg.json_object(), std::move(options));
}
void visit(ExternalAccountConfig const& cfg) override {
grpc::SslCredentialsOptions ssl_options;
auto cainfo = LoadCAInfo(options);
if (cainfo) ssl_options.pem_root_certs = std::move(*cainfo);
result = std::make_unique<GrpcChannelCredentialsAuthentication>(
grpc::CompositeChannelCredentials(
grpc::SslCredentials(grpc::SslCredentialsOptions()),
grpc::SslCredentials(ssl_options),
GrpcExternalAccountCredentials(cfg)));
}
} visitor(std::move(cq), std::move(options));
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/storage/testing/temp_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TempFile {

~TempFile();

std::string name() { return name_; }
std::string name() const { return name_; }

private:
std::string name_;
Expand Down
Loading