Skip to content

feat: add support for FIPS bouncy castle #3590 #3595

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 1 commit into from
Aug 2, 2024

Conversation

robhafner
Copy link
Contributor

Prefer FIPS version of bouncy castle if available. Otherwise, fallback to non FIPS version.

Copy link

linux-foundation-easycla bot commented Jul 25, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jul 25, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @robhafner!

It looks like this is your first PR to kubernetes-client/java 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/java has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 25, 2024
@brendandburns
Copy link
Contributor

Thanks for the PR. Instead of this approach, I think I would prefer to keep the default and then use some sort of -D flag which would specify the security provider to load.

@robhafner
Copy link
Contributor Author

So we have the bc-fips-1.0.2.4.jar on our classpath and it has a META-INF/services/java.security.Provider file with the "org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider" class defined in it. I would expect that file would trigger loading the required fips provider.

It's a bit unclear to me if there is a security risk with attempting to load the non fips provider class as well (in the event that the non fips provider class ended up on our classpath). We've chosen to only support FIPS compliant algorithms in our software.

This change is based on what we noticed in another project with respect to how they check the provider class.

https://github.com/puppetlabs/jvm-ssl-utils/blob/main/src/java/com/puppetlabs/ssl_utils/SSLUtils.java#L120

@brendandburns
Copy link
Contributor

ok, how about something like

static {
  String className = System.getProperty("io.kubernetes.SecurityProvider");
  if (className == null) {
     className == <non-fips-provider>;
  }
  Security.Provider = Class.forName(className);
}

@robhafner
Copy link
Contributor Author

robhafner commented Jul 31, 2024 via email

@robhafner
Copy link
Contributor Author

robhafner commented Jul 31, 2024 via email

@brendandburns
Copy link
Contributor

I think we need to make sure that this works without anyone doing anything special. I'm worried that if we don't explicitly load the provider that it won't be as easy for the users to use the client.

I want it to be feasible for FIPS users to change their providers, but I don't want to make it harder for the average user.

@robhafner
Copy link
Contributor Author

robhafner commented Jul 31, 2024 via email

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 31, 2024
Dynamically load security providers using the Java Service Provider Interface.

This allows the user to pick the provider based upon the dependencies it has on
its classpath.
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 31, 2024
@robhafner
Copy link
Contributor Author

robhafner commented Jul 31, 2024 via email

@brendandburns
Copy link
Contributor

Thanks for digging in here. Assuming tests pass, this looks good to me.

@brendandburns
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 2, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, robhafner

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 2, 2024
@k8s-ci-robot k8s-ci-robot merged commit 2562407 into kubernetes-client:master Aug 2, 2024
18 checks passed
@jwojcie
Copy link

jwojcie commented Oct 29, 2024

hi, two questions if I may

  1. When this fix is going to be available in maven repo? I understand it is not there yet in 21.0.2: https://github.com/kubernetes-client/java/blob/v21.0.2/util/src/main/java/io/kubernetes/client/util/SSLUtils.java
  2. are you sure this fix you made is going to work? I tested it locally on my FIPS hardened Java, which means that apart from other stuff I have this in java.security:
    security.provider.1=org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider C:DEFRND[SHA256];ENABLE{ALL}; security.provider.2=org.bouncycastle.jsse.provider.BouncyCastleJsseProvider fips:BCFIPS security.provider.3=SUN

So I have 3 providers, nothing more or less. I used this small code snippet:

`public static void listProviders() {

    System.out.println("Kubernetes fix: +++++++++++++++++++++++++++++");
    ServiceLoader<Provider> services = ServiceLoader.load(java.security.Provider.class);
    for (Provider service : services) {
        System.out.println("Found security provider: " + service.getName());
        //Security.addProvider(service);
    }

    System.out.println("Actual providers: +++++++++++++++++++++++++++++++");
    for (Provider provider : Security.getProviders()) {
        System.out.println("Provider: " + provider.getName() + ", Version: " + provider.getVersion());
    }

    System.out.println("Just for reference: +++++++++++++++++++++++++++++++");
    Provider provider = new org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider();
    System.out.println("Provider: " + provider.getName() + ", Version: " + provider.getVersion());

}`

And the result is kind of surprising:
`Kubernetes fix: +++++++++++++++++++++++++++++
Found security provider: SunPCSC
Found security provider: SunEC
Found security provider: SunPKCS11
Found security provider: SunMSCAPI
Found security provider: JdkSASL
Found security provider: XMLDSig
Found security provider: SunJGSS
Found security provider: SunSASL
Found security provider: JdkLDAP
Actual providers: +++++++++++++++++++++++++++++++
Provider: BCFIPS, Version: 2.0
Provider: BCJSSE, Version: 2.0019
Provider: SUN, Version: 11.0
Just for reference: +++++++++++++++++++++++++++++++
Provider: BCFIPS, Version: 2.0

Process finished with exit code 0
`

Which makes me think that the fix you made is not going to work because that loop is returning something else than expected, or do I missed something here?

In that context may I interest you in the netty solution to the problem?
https://github.com/netty/netty/blob/4.1/handler/src/main/java/io/netty/handler/ssl/util/BouncyCastleSelfSignedCertGenerator.java#L44

@brendandburns
Copy link
Contributor

I think that you need to make sure that those other providers are not in your classpath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants