Skip to content

Use PKCS#12 encoder to encode JKS - #603

Merged
cert-manager-prow[bot] merged 1 commit into
cert-manager:mainfrom
erikgb:deprecate-jks
Apr 24, 2025
Merged

cert-manager-prow[bot] merged 1 commit into
cert-manager:mainfrom
erikgb:deprecate-jks

Conversation

@erikgb

@erikgb erikgb commented Apr 16, 2025

Copy link
Copy Markdown
Member

While working on #486, I think the new API could be greatly simplified by removing explicit support for JKS. And after digging a bit deeper into code, issues and PRs in https://github.com/SSLMate/go-pkcs12, I became convinced that just using this module for trust stores in trust-manager is the way forward. Password-less JKS truststores, which is the new Java default (starting Java 18) is also not supported by our currently used JKS module. Support for it was rejected in pavlo-v-chernykh/keystore-go#37.

In this PR I propose to:

I have added a (skipped) test that can be used to verify that the Java keytool can read the new "JKS" truststores, but it requires paths to installed Java and cannot be enabled in CI.

We should probably also verify that the trust stores are usable by a Java application. I don't know how simple this would be to test, but we could ask the community for help in testing after releasing an alpha release of trust-manager? Maybe we could specifically ask historical contributors of JKS features?

@cert-manager-prow cert-manager-prow Bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 16, 2025
@erikgb
erikgb force-pushed the deprecate-jks branch 2 times, most recently from 69d798e to dece7d8 Compare April 16, 2025 13:44
@erikgb

erikgb commented Apr 16, 2025

Copy link
Copy Markdown
Member Author

/test pull-trust-manager-integration

@SgtCoDFish SgtCoDFish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is great, and I'd merge it happily! I've got a bunch of suggestions about the keytool test because I think that'd be a great addition even if it's skipped often - so I'll add a hold in case you want to change anything there

/lgtm
/approve
/hold

Comment on lines +150 to +151
tests := map[string]struct {
keytool string
}{
"Java 21": {
keytool: "/usr/lib/jvm/java-21-openjdk-amd64/bin/keytool",
},
"Java 17": {
keytool: "/usr/lib/jvm/java-17-openjdk-amd64/bin/keytool",
},
"Java 11": {
keytool: "/usr/lib/jvm/java-11-openjdk-amd64/bin/keytool",
},
"Java 8": {
keytool: "/usr/lib/jvm/java-8-openjdk-amd64/bin/keytool",
},
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion: I don't know if the differing versions of keytool would meaningfully change this - it's not the same as running different versions of Java AFAIK. Plus, these paths assume amd64 (and so wouldn't work for me)

I'd vote to remove the different versions here and, like in my other suggestion, just run this test if keytool can be found on $PATH.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it's not the same as running different versions of Java AFAIK.

Important note! Hmmm, then I must find a better way to test this. 🤔

@erikgb erikgb Apr 16, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@SgtCoDFish, I hacked together a test that actually runs Java against a Go HTTP server using a self-signed certificate. And it seems to work on my machine for all the LTS Java versions: 8, 11, 17 and 21. Do you have Java installed? It would be nice if you could also test! 😅

Comment thread pkg/apis/trust/v1alpha1/types_bundle.go Resolved
@cert-manager-prow cert-manager-prow Bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed lgtm Indicates that a PR is ready to be merged. labels Apr 16, 2025
@erikgb
erikgb force-pushed the deprecate-jks branch 4 times, most recently from 901ac88 to 8647077 Compare April 16, 2025 20:39

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Haven't been able to test this yet but I'd like to! Thank you for looking into this

@erikgb erikgb Apr 18, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Please do! I am 99% sure this should work fine, and all tests pass on my machine with Java 8, 11, 17 and 21.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It works on my Windows + WSL2 Ubuntu Linux laptop:

$ sudo apt install openjdk-21-jdk-headless
...

$ go test -v ./pkg/bundle/internal/truststore/...
=== RUN   Test_Java_keytool_can_read_JKS
    java_test.go:73: combined out:
        Keystore type: PKCS12
        Keystore provider: SUN

        Your keystore contains 3 entries

        3c95e845|cn=cmct-test-root,o=cert-manager, Apr 24, 2025, trustedCertEntry,
        Certificate fingerprint (SHA-256): 3C:95:E8:45:AC:75:2D:FC:13:A9:8B:71:67:41:7E:89:2D:83:02:BC:0F:FB:48:7F:10:A9:DF:AA:C0:D1:26:73
        548b988f|cn=cmct-test-root,o=cert-manager, Apr 24, 2025, trustedCertEntry,
        Certificate fingerprint (SHA-256): 54:8B:98:8F:4B:AD:7B:DD:0D:3B:75:23:DE:37:15:4E:E4:7F:28:5E:EE:36:D3:B1:F5:3F:AA:27:20:FC:A3:07
        96bcec06|cn=isrg root x1,o=internet security research group,c=us, Apr 24, 2025, trustedCertEntry,
        Certificate fingerprint (SHA-256): 96:BC:EC:06:26:49:76:F3:74:60:77:9A:CF:28:C5:A7:CF:E8:A3:C0:AA:E1:1A:8F:FC:EE:05:C0:BD:DF:08:C6
--- PASS: Test_Java_keytool_can_read_JKS (0.22s)
=== RUN   Test_Java_can_use_JKS
    java_test.go:136: combined out:
        Note: TestHTTPConnection.java uses or overrides a deprecated API.
        Note: Recompile with -Xlint:deprecation for details.
    java_test.go:168: combined out:
        Successfully connected to https://127.0.0.1:42583

Signed-off-by: Erik Godding Boye <[email protected]>

@wallrj wallrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @erikgb

@ali-hamza-noor and I have tested the new Java integration tests on Ubuntu Linux and Mac.

Ash has reviewed the code, so I'll approve this, as discussed at the cert-manager standup 2025-04-24.

/approve
/lgtm

@cert-manager-prow cert-manager-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Apr 24, 2025
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: SgtCoDFish, wallrj

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

The pull request process is described here

Details 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

@erikgb

erikgb commented Apr 24, 2025

Copy link
Copy Markdown
Member Author

/unhold

@cert-manager-prow cert-manager-prow Bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 24, 2025
@cert-manager-prow
cert-manager-prow Bot merged commit a5dfb3c into cert-manager:main Apr 24, 2025
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. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants