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: Add experimental S2A integration in client libraries grpc transport #3326

Merged
merged 59 commits into from
Nov 14, 2024
Merged
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
aebd139
bump grpc versions.
rmehta19 Oct 29, 2024
b456935
bump auth to local SNAPSHOT.
rmehta19 Oct 29, 2024
3510643
implementation.
rmehta19 Nov 1, 2024
e799526
tests.
rmehta19 Nov 1, 2024
70ae8d0
use endpoint override.
rmehta19 Nov 1, 2024
7ef7313
fix typo
rmehta19 Nov 1, 2024
6d98115
cleanup.
rmehta19 Nov 4, 2024
250fecc
Merge branch 'main' into grpc-channel-using-s2a
rmehta19 Nov 4, 2024
8469a1a
resolve merge conflict with PR#1560
rmehta19 Nov 4, 2024
e880fbe
remove unnecessary dependency.
rmehta19 Nov 4, 2024
28adb31
add mtlsEndpoint to ClientSettings.
rmehta19 Nov 4, 2024
b3e2e06
add logs.
rmehta19 Nov 4, 2024
90892ef
remove ignore rule.
rmehta19 Nov 4, 2024
33b710c
separate into single condition if statements.
rmehta19 Nov 4, 2024
b320cc2
add logic to resolve endpointOverride / customEndpoint in EndpointCon…
rmehta19 Nov 4, 2024
035e17e
add javadocs.
rmehta19 Nov 4, 2024
759c3df
mtlsendpoint changes.
rmehta19 Nov 5, 2024
c096cb7
isS2AEnabled.
rmehta19 Nov 5, 2024
dc4b61e
expose endpointContext.
rmehta19 Nov 5, 2024
d4fcc71
Merge branch 'main' into grpc-channel-using-s2a
rmehta19 Nov 5, 2024
393190a
remove needsEndpointContext.
rmehta19 Nov 6, 2024
30a37c2
reduce nesting.
rmehta19 Nov 6, 2024
c3b93a0
check Strings null or empty.
rmehta19 Nov 6, 2024
18a4cf2
remove unecessary check.
rmehta19 Nov 6, 2024
0897730
set endpointContext in grpc transport provider tests.
rmehta19 Nov 6, 2024
9901656
package private.
rmehta19 Nov 6, 2024
257c515
set System::getenv as envProvider.
rmehta19 Nov 6, 2024
e4565f4
add javadoc.
rmehta19 Nov 6, 2024
33bd7a6
no getters for endpointcontext.
rmehta19 Nov 6, 2024
f9eef5b
nits + package private.
rmehta19 Nov 6, 2024
a7af12e
update javadocs + add mtlsServiceAddress.
rmehta19 Nov 6, 2024
eb70225
add javadocs.
rmehta19 Nov 6, 2024
2a50985
update readme.
rmehta19 Nov 6, 2024
943683d
private + readme updates.
rmehta19 Nov 6, 2024
34f030f
Merge branch 'main' into grpc-channel-using-s2a
rmehta19 Nov 6, 2024
fb3d608
update CLIRR-ignored-differences.
rmehta19 Nov 6, 2024
926faca
mark endpoint as Obsolete.
rmehta19 Nov 6, 2024
4ee2ee9
fix remaining tests to mock endpointContext.resolvedEndpoint().
rmehta19 Nov 6, 2024
2f70bf8
modify obsolete statement.
rmehta19 Nov 6, 2024
cb5768f
Merge branch 'main' into grpc-channel-using-s2a
rmehta19 Nov 7, 2024
c96c760
revert usage of endpointContext.resolvedEndpoint().
rmehta19 Nov 7, 2024
30ff3d6
Merge branch 'main' into grpc-channel-using-s2a
rmehta19 Nov 8, 2024
791ab2c
don't propogate endpointContext.
rmehta19 Nov 11, 2024
a4ee6c5
log as warning.
rmehta19 Nov 11, 2024
6eeccb2
package private + comment on S2A env var.
rmehta19 Nov 11, 2024
03eb991
package private useS2A.
rmehta19 Nov 12, 2024
91175ef
check if files exist.
rmehta19 Nov 12, 2024
04d47a0
default unsupported exception.
rmehta19 Nov 12, 2024
7d7b233
log a warning.
rmehta19 Nov 12, 2024
a42dcbd
pass File to TlsChannelCredentials.
rmehta19 Nov 12, 2024
56551c6
test createPlaintextS2AChannelCredentials.
rmehta19 Nov 12, 2024
1ff7a92
fix file checking logic.
rmehta19 Nov 12, 2024
2958fb4
document mtls mds.
rmehta19 Nov 13, 2024
c9a7edd
rename mtls mds vars to be clear these are filepaths.
rmehta19 Nov 13, 2024
8bf770d
bump auth dep and add some tests for createS2ASecuredChannelCredentials.
rmehta19 Nov 13, 2024
33faba1
Merge branch 'main' into grpc-channel-using-s2a
rmehta19 Nov 13, 2024
924a4e4
fix BUILD.
rmehta19 Nov 13, 2024
b00fd53
Merge branch 'main' into grpc-channel-using-s2a
rmehta19 Nov 14, 2024
ca5be85
fix: Do not build s2a frpm grpc's Bazel target.
blakeli0 Nov 14, 2024
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
Prev Previous commit
Next Next commit
check if files exist.
  • Loading branch information
rmehta19 committed Nov 12, 2024
commit 91175ef017d1acf1ddd00cf3af2ad64037583fdd
Original file line number Diff line number Diff line change
Expand Up @@ -503,35 +503,45 @@ ChannelCredentials createS2ASecuredChannelCredentials() {
// Currently, MTLS to MDS is only available on GCE. See:
// https://cloud.google.com/compute/docs/metadata/overview#https-mds
// Try to load MTLS-MDS creds.
InputStream trustBundle = null;
InputStream privateKey = null;
InputStream certChain = null;
try {
trustBundle = new FileInputStream(MTLS_MDS_ROOT);
privateKey = new FileInputStream(MTLS_MDS_CERT_CHAIN_AND_KEY);
certChain = new FileInputStream(MTLS_MDS_CERT_CHAIN_AND_KEY);
} catch (FileNotFoundException ignore) {
// Fallback to plaintext-to-S2A connection.
LOG.log(
Level.INFO,
"Cannot establish an mTLS connection to S2A due to error loading MTLS to MDS credentials, falling back to plaintext connection to S2A: "
+ ignore.getMessage());
return createPlaintextToS2AChannelCredentials(plaintextAddress);
}
ChannelCredentials mtlsToS2AChannelCredentials = null;
try {
File rootFile = new File(MTLS_MDS_ROOT);
File certKeyFile = new File(MTLS_MDS_CERT_CHAIN_AND_KEY);
if (!rootFile.isFile() || !certKeyFile.isFile()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be if (rootFile.isFile() && certKeyFile.isFile())? Or refactor this to

if (!rootFile.isFile() || !certKeyFile.isFile()) {
  return createPlaintextToS2AChannelCredentials(plaintextAddress);
}

to reduce indentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry this is my bad! Changed to if (rootFile.isFile() && certKeyFile.isFile()). Thanks for catching! 1ff7a92

Copy link
Collaborator

@blakeli0 blakeli0 Nov 12, 2024

Choose a reason for hiding this comment

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

Thanks! I think that means we don't have any test coverage for createS2ASecuredChannelCredentials() though, and to some extend, also no test coverage for the logics in createSingleChannel().

It's probably hard to test the channels created from createSingleChannel() since there are no getters in ManagedChannel for us to verify it, and that's probably we don't have much test for it in the past either. For the new method createS2ASecuredChannelCredentials(), we could probably extract the file path as parameters of this method so that we can unit test it properly.

// Try to connect to S2A using mTLS.
mtlsToS2AChannelCredentials =
createMtlsToS2AChannelCredentials(trustBundle, privateKey, certChain);
} catch (IOException ignore) {
// Fallback to plaintext-to-S2A connection.
ChannelCredentials mtlsToS2AChannelCredentials = null;
InputStream trustBundle = null;
InputStream privateKey = null;
InputStream certChain = null;
try {
trustBundle = new FileInputStream(MTLS_MDS_ROOT);
privateKey = new FileInputStream(MTLS_MDS_CERT_CHAIN_AND_KEY);
certChain = new FileInputStream(MTLS_MDS_CERT_CHAIN_AND_KEY);
} catch (FileNotFoundException ignore) {
// Fallback to plaintext-to-S2A connection on error.
LOG.log(
Level.INFO,
"Cannot establish an mTLS connection to S2A due to error loading MTLS to MDS credentials, falling back to plaintext connection to S2A: "
+ ignore.getMessage());
return createPlaintextToS2AChannelCredentials(plaintextAddress);
}
try {
mtlsToS2AChannelCredentials =
createMtlsToS2AChannelCredentials(trustBundle, privateKey, certChain);
} catch (IOException ignore) {
// Fallback to plaintext-to-S2A connection on error.
LOG.log(
Level.WARNING,
"Cannot establish an mTLS connection to S2A due to error creating MTLS to MDS TlsChannelCredentials credentials, falling back to plaintext connection to S2A: "
+ ignore.getMessage());
return createPlaintextToS2AChannelCredentials(plaintextAddress);
}
return S2AChannelCredentials.newBuilder(mtlsAddress, mtlsToS2AChannelCredentials).build();
} else {
// Fallback to plaintext-to-S2A connection if MTLS-MDS creds do not exist.
LOG.log(
Level.WARNING,
"Cannot establish an mTLS connection to S2A due to error creating MTLS to MDS TlsChannelCredentials credentials, falling back to plaintext connection to S2A: "
+ ignore.getMessage());
Level.INFO,
"Cannot establish an mTLS connection to S2A MTLS to MDS credentials do not exist on filesystem, falling back to plaintext connection to S2A");
return createPlaintextToS2AChannelCredentials(plaintextAddress);
}
return S2AChannelCredentials.newBuilder(mtlsAddress, mtlsToS2AChannelCredentials).build();
}

private ManagedChannel createSingleChannel() throws IOException {
Expand Down
Loading