-
Notifications
You must be signed in to change notification settings - Fork 275
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
Improve handling of CA certificates #378
Conversation
Could someone take a look at this? It’s a significant improvement. Once I found https://www.graalvm.org/latest/reference-manual/native-image/dynamic-features/CertificateManagement/#build-time-options, everything fell in place. |
8f59659
to
a0ae6ca
Compare
I haven't forgotten about this one. Will take a look when I get the chance. |
d7fb715
to
c9806d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, using system properties to bake the certs into the trust store is a good change! Also, I'm down with getting rid of the pkl-certs
distribution.
However, I think we should not change how the options works. For example, this is currently an error, and should continue to be an error:
pkl eval --ca-certificates not/a/valid/path.pem
Going by the same logic, if the provided argument is a directory and we scan it to include those certs, I would expect it to replace the set of trusted certs. An empty directory would logically mean: don't trust any certs.
Because of this, I don't think we should say that the default value of --ca-certificates
is ~/.pkl/cacerts
. Rather, we should keep it the way it is; if there is no --ca-certificates
argument, then Pkl will look for it in ~/.pkl/cacerts
, and otherwise fall back to its own certs.
Because of this, I don't think accepting directories as --ca-certificates
actually provides that much value. With that said, though, I can go either way; am okay with keeping it if there's a good use-case for it.
|
||
Setting this option replaces the existing set of CA certificates bundled into the CLI. | ||
Setting this option to anything other than a non-existing or empty directory | ||
replaces the existing set of CA certificates bundled into the CLI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is asking for hidden configuration errors. This will execute just fine, even if the path doesn't exist:
pkl eval --ca-certificates not/a/valid/path/
I think it's better to keep the way it works today.
More thoughts left in the review summary.
To recap the current behavior:
The changes proposed in this PR have many upsides:
Given that a non-existing
I think I like (2) relatively best because it keeps most of the listed upsides. What do you think? One more question: Are we certain that |
In 0.25 (the current release), I'll do some benchmarking here; I'm curious how much time we're saving by trying to make things lazy.
I don't think this is needed anymore, now that we don't use classpath resources for embedding the cert files. |
We discussed before that being lazy means that SSL initialization errors are deferred. The conclusion was that being lazy is in the Pkl spirit. Lazy SSL initialization is why 0.26 is much snappier than 0.25. The JVM also initializes SSL lazily. It’s known to be expensive. |
c9806d9
to
aec2c16
Compare
Removed. |
You're right; initializing cert stuff takes quite a while. In particular, Also: I'm kind of shocked that it takes so along to initialize. I'm curious if there's some better approach here. Another observation: |
I think that accepting a directory makes sense both from a user perspective (can use a directory other than
Default SSL context with baked-in certificates and lazy SSL initialization is already a significant improvement compared to 0.25. Perhaps SSL initialization time for user-provided certificates could be further improved by accepting a .p12 file instead of .pem files and changing the |
Hmm... yeah, I don't feel strongly about this. Sounds fine to me to accept directories too, especially since both cURL and wget do. But I think let's follow their lead in this case, and make it a separate flag (I think maybe call it |
Which config errors are you trying to guard against? I feel a single option is more elegant and keeps the CLI/API smaller. Also |
Instead of bundling Pkl's built-in CA certificates as a class path resource and loading them at runtime, pass them to the native image compiler as the default SSL context's trust store. This results in faster SSL initialization and is more consistent with how default certificates are handled when running on the JVM. Further related improvements: - Change `--ca-certificates` and corresponding APIs to accept directories in addition to files. Passing a directory has the same effect as passing each of the directory's regular files. - Set the `~/.pkl/cacerts` CLI default directly in `CliBaseOptions`. - Remove HttpClientBuilder methods `addDefaultCliCertificates` and `addBuiltInCertificates`. - Remove pkl-certs subproject and the optional dependencies on it. - Move `PklCARoots.pem` to `pkl-cli/src/certs`. - Rename occurrences of `certificateFiles` to `certificatePaths`. - Fix certificate related error messages that were missing an argument. - Prevent PklBugException if initialization of `CliBaseOptions.httpClient` fails.
Rationale: There is no longer a clear need for this feature.
a7551bd
to
e4b5823
Compare
The error would be accidentally setting the flag to a directory, when it was supposed to be a file, or vice versa. I also like that:
|
Instead of bundling Pkl's built-in CA certificates as a class path resource and loading them at runtime, pass them to the native image compiler as the default SSL context's trust store. This results in faster SSL initialization and is more consistent with how default certificates are handled when running on the JVM.
Further related improvements:
--ca-certificates
and corresponding APIs to accept directories in addition to files. Passing a directory has the same effect as passing each of the directory's regular files.~/.pkl/cacerts
CLI default directly inCliBaseOptions
.addDefaultCliCertificates
andaddBuiltInCertificates
.PklCARoots.pem
topkl-cli/src/certs
.certificateFiles
tocertificatePaths
.CliBaseOptions.httpClient
fails.