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: Adds an X509 certificate provider in the auth libraries. #1624

Draft
wants to merge 6 commits into
base: x509
Choose a base branch
from

Conversation

aeitzman
Copy link
Contributor

@aeitzman aeitzman commented Jan 22, 2025

This PR creates a new "X509" certificate provider in a new Mtls package to handle workload X509 certificate reading. This is part of a larger feature described in go/x509-workload-auth-library-design

Merging this into a feature branch for now until the entire feature is ready.

@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Jan 22, 2025
@aeitzman aeitzman marked this pull request as ready for review January 22, 2025 18:42
@aeitzman aeitzman requested review from a team as code owners January 22, 2025 18:42
@aeitzman aeitzman changed the title Adds an X509 certificate provider in the auth libraries. feat: Adds an X509 certificate provider in the auth libraries. Jan 22, 2025
@aeitzman aeitzman marked this pull request as draft January 22, 2025 18:42
Copy link

@andyrzhao andyrzhao left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

oauth2_http/java/com/google/auth/mtls/X509Provider.java Outdated Show resolved Hide resolved
oauth2_http/java/com/google/auth/mtls/X509Provider.java Outdated Show resolved Hide resolved
}
InputStream certConfigStream = null;
try {
if (!isFile(certConfig)) {

Choose a reason for hiding this comment

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

nit: fileExists(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like file.exists() will return true if the file is a directory, which we do not want here. isFile will return true only if it is a file

}

boolean isFile(File file) {
return file.isFile();

Choose a reason for hiding this comment

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

add null check here as good practice (even if file is not expected to be null)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The purpose of this function is mainly just to help testing the provider by allowing us to mock the file read. I think we should just let the file.isFile() handle the null the check and throw the error instead of putting in our own error handling here.

I'll add comments to this block to make it more clear what the purpose of these functions are.

return System.getProperty(property, def);
}

File getWellKnownCertificateConfigFile() {

Choose a reason for hiding this comment

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

I think all these helper methods should be "private" whenever possible right? and use protected for those that needs to be overridden by the test mock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make this function private, for the methods that need to be overridden, I think its better to keep them package private instead of protected, since we wouldn't expect packages that ingest this library to override them. For context, this is the same pattern that we use for the Default credentials provider in this library (https://github.com/googleapis/google-auth-library-java/blob/main/oauth2_http/java/com/google/auth/oauth2/DefaultCredentialsProvider.java)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants