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

Enable CA certificates to be baked into an image #94

Closed
3 tasks
dmikusa opened this issue Mar 15, 2022 · 11 comments · Fixed by #97
Closed
3 tasks

Enable CA certificates to be baked into an image #94

dmikusa opened this issue Mar 15, 2022 · 11 comments · Fixed by #97
Labels
type:enhancement A general enhancement

Comments

@dmikusa
Copy link
Contributor

dmikusa commented Mar 15, 2022

What happened?

Right now you need to pass ca-certificates bindings at build and at runtime. The buildpack will add a helper which loads the certs in the runtime environment. You need to have the certs present at runtime though so the helper can load them.

It's annoying to have to specify them twice.

We should support a more flexible configuration:

1. No build ca certs required to enable the helper. If you just need certs at runtime, then just set them at runtime. (this already works this way, it's enabled by default but you can opt-out and disable it).
2. Embed ca certs into the image. CA certs are public certs, they are not secrets and we could include them in the image. It's just less flexible because you can't change the certs included at runtime. There is still utility in this though and we should allow it.

Checklist

  • I have included log output.
  • The log output includes an error message.
  • I have included steps for reproduction.
@dmikusa dmikusa added the type:enhancement A general enhancement label Mar 15, 2022
@jjsheridan
Copy link

@dmikusa-pivotal If possible, we would like to have the certs we add also added to the java cert store.

@dmikusa
Copy link
Contributor Author

dmikusa commented Mar 21, 2022

@jjsheridan - That happens elsewhere. The JVM provider buildpacks (Bellsoft, Microsoft, Amazon, etc...) will load the system certs into the JVM.

If you add certs using ca-certificates buildpack, they'll get installed to the right place so that the JVM provider buildpacks can pick them up.

@jjsheridan
Copy link

@dmikusa-pivotal It sounds like I can accomplish adding custom certs by creating our own ca-cert buildpack. Is that correct? If so, what would be the drawbacks to this method?

@dmikusa
Copy link
Contributor Author

dmikusa commented Mar 25, 2022

@dmikusa-pivotal It sounds like I can accomplish adding custom certs by creating our own ca-cert buildpack. Is that correct? If so, what would be the drawbacks to this method?

Sorry, not sure I follow what you'd need to create a buildpack to do.

The Paketo ca-certificates buildpack will handle copying certs from bindings to a location that is suitable for them to be used by OpenSSL. In addition, all of the Paketo Java buildpacks, the ones that provide various vendors' OpenJDK binaries, should load all of the OpenSSL certificate into the JVM keystore.

So the two buildpacks work together to get your bound CA certificates into the JVM keystore.

How were you thinking another buildpack would fit in here? Is there a gap in functionality? If so, we can try to cover that in the Paketo buildpacks. We'd like them to cover most situations out-of-the-box.

@jjsheridan
Copy link

@dmikusa-pivotal As a way of including our custom certs in the system cert store. Couldn't this be done by creating our own ca-certificates buildpack that would include all the certs that come with the buildpack and just adding ours?

@dmikusa
Copy link
Contributor Author

dmikusa commented Mar 26, 2022

Couldn't this be done by creating our own ca-certificates buildpack that would include all the certs that come with the buildpack and just adding ours?

If you want to create a buildpack that embeds your ca-certificates with the buildpack itself, you could do that. The Paketo ca-certificates buildpack doesn't have a way to do that.

Typically what I see being done though, instead of a custom buildpack, is a custom stack (build/run image) with the CA certs already trusted in the base image. This has a couple of advantages:

  1. It's in the stack, so your users won't need to include an extra buildpack.

  2. When you create the build/run base images, you can have root access, so you can install the CA certificates into the default locations for your Linux distro. This means you don't need the special OpenSSL env variables that the ca-certificates buildpack uses. A buildpack cannot add CA certificates to the default locations because those are almost always under /etc or some other location to which the buildpack cannot write.

There are probably other ways to attack this problem as well.

@jjsheridan
Copy link

@dmikusa-pivotal Thanks. The drawback I see is we would need to have some automation in place to upgrade our stack as updates are released. Given the way we're creating our images via AWS CodePipeline and CodeBuild, it might complicate things a bit too much.

dmikusa pushed a commit that referenced this issue Apr 11, 2022
Prior to this PR, a helper is added at build time. This helper will execute in the runtime environment and load any ca-certs that are presented through a binding. This is the most flexible, but requires the individual executing the image to specify the binding with the CA certificates. If the CA certificates binding is skipped/forgotten, then the run will likely fail.

Since CA certificates are public certificates and not secret, we can build the CA certificates into the image if the user would prefer. This provides the CA certificates by default, so there is no ca-certificates binding required at runtime. You can add additional CA certs at runtime with a binding, but you cannot remove CA certs baked into the image without rebuilding.

To include in the image, set `BP_EMBED_CERTS=true` and rebuild your image.

CA certificates are copied into the layer. Then the normal symlinking procedure is applied referencing the copies.

This resolves #94.

In addition, this PR deprecates `BP_ENABLE_RUNTIME_CERT_BINDING` because this has a default `true` value and we are moving all config to be default `false`. This env variable is replaced by `BP_RUNTIME_CERT_BINDING_DISABLED` which defaults to false. The meaning is basically the same. Going forward, set `BP_RUNTIME_CERT_BINDING_DISABLED=true` to remove the runtime helper from the produced image.

Signed-off-by: Daniel Mikusa <[email protected]>
dmikusa pushed a commit that referenced this issue Apr 11, 2022
Prior to this PR, a helper is added at build time. This helper will execute in the runtime environment and load any ca-certs that are presented through a binding. This is the most flexible, but requires the individual executing the image to specify the binding with the CA certificates. If the CA certificates binding is skipped/forgotten, then the run will likely fail.

Since CA certificates are public certificates and not secret, we can build the CA certificates into the image if the user would prefer. This provides the CA certificates by default, so there is no ca-certificates binding required at runtime. You can add additional CA certs at runtime with a binding, but you cannot remove CA certs baked into the image without rebuilding.

To include in the image, set `BP_EMBED_CERTS=true` and rebuild your image.

CA certificates are copied into the layer. Then the normal symlinking procedure is applied referencing the copies.

This resolves #94.

In addition, this PR deprecates `BP_ENABLE_RUNTIME_CERT_BINDING` because this has a default `true` value and we are moving all config to be default `false`. This env variable is replaced by `BP_RUNTIME_CERT_BINDING_DISABLED` which defaults to false. The meaning is basically the same. Going forward, set `BP_RUNTIME_CERT_BINDING_DISABLED=true` to remove the runtime helper from the produced image.

Signed-off-by: Daniel Mikusa <[email protected]>
dmikusa pushed a commit that referenced this issue Apr 12, 2022
Prior to this PR, a helper is added at build time. This helper will execute in the runtime environment and load any ca-certs that are presented through a binding. This is the most flexible, but requires the individual executing the image to specify the binding with the CA certificates. If the CA certificates binding is skipped/forgotten, then the run will likely fail.

Since CA certificates are public certificates and not secret, we can build the CA certificates into the image if the user would prefer. This provides the CA certificates by default, so there is no ca-certificates binding required at runtime. You can add additional CA certs at runtime with a binding, but you cannot remove CA certs baked into the image without rebuilding.

To include in the image, set `BP_EMBED_CERTS=true` and rebuild your image.

CA certificates are copied into the layer. Then the normal symlinking procedure is applied referencing the copies.

This resolves #94.

In addition, this PR deprecates `BP_ENABLE_RUNTIME_CERT_BINDING` because this has a default `true` value and we are moving all config to be default `false`. This env variable is replaced by `BP_RUNTIME_CERT_BINDING_DISABLED` which defaults to false. The meaning is basically the same. Going forward, set `BP_RUNTIME_CERT_BINDING_DISABLED=true` to remove the runtime helper from the produced image.

Signed-off-by: Daniel Mikusa <[email protected]>
dmikusa pushed a commit that referenced this issue Apr 12, 2022
Prior to this PR, a helper is added at build time. This helper will execute in the runtime environment and load any ca-certs that are presented through a binding. This is the most flexible, but requires the individual executing the image to specify the binding with the CA certificates. If the CA certificates binding is skipped/forgotten, then the run will likely fail.

Since CA certificates are public certificates and not secret, we can build the CA certificates into the image if the user would prefer. This provides the CA certificates by default, so there is no ca-certificates binding required at runtime. You can add additional CA certs at runtime with a binding, but you cannot remove CA certs baked into the image without rebuilding.

To include in the image, set `BP_EMBED_CERTS=true` and rebuild your image.

CA certificates are copied into the layer. Then the normal symlinking procedure is applied referencing the copies.

This resolves #94.

In addition, this PR deprecates `BP_ENABLE_RUNTIME_CERT_BINDING` because this has a default `true` value and we are moving all config to be default `false`. This env variable is replaced by `BP_RUNTIME_CERT_BINDING_DISABLED` which defaults to false. The meaning is basically the same. Going forward, set `BP_RUNTIME_CERT_BINDING_DISABLED=true` to remove the runtime helper from the produced image.

Signed-off-by: Daniel Mikusa <[email protected]>
@dmikusa
Copy link
Contributor Author

dmikusa commented Apr 12, 2022

@jjsheridan If you want, you can give https://github.com/paketo-buildpacks/ca-certificates/releases/tag/v3.2.0 a try. This has a PR I committed which allows one to include CA certificates into the built image. You then do not need to include them as a binding at runtime.

This is convenient as it simplifies running the image. The downside is that it's less flexible. If you need to change the certs included with the image then you must rebuild the image.

This should be included in the Paketo buildpacks composite & builder releases on Friday. To try now, just add -b gcr.io/paketo-buildpacks/ca-certificates:3.2.0 -b paketo-buildpacks/java to one of your pack build commands.

@jjsheridan
Copy link

Great, thanks @dmikusa-pivotal !

@jjsheridan
Copy link

@dmikusa-pivotal I'm finally getting around to trying this, but since no binding is required, I'm not sure where the certs should be stored for pack to pick them up?

@dmikusa
Copy link
Contributor Author

dmikusa commented May 14, 2022

@jjsheridan You would still need a binding, but only during build. So you would set BP_EMBED_CERTS=true and pass the binding when you run pack build.

After that, the CA certs are part of the image, so you do not need the binding at runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants