This topic tells you how to configure Tanzu Platform to trust a custom certificate authority (CA) for your container image registry.
If the registry you store application images in uses a custom CA, several parties must trust this CA to enable you to build and deploy a secure application:
-
tanzu build (pushing to the registry):
- If you are building your app on Tanzu Platform, you must configure the
CACertificateSecretRefs
field of theBuildConfiguration
. For more information, see Configure builds to run on Tanzu Platform. - If you are building your app locally, see Configure trusted CAs for daemon builds later in this topic.
- If you are building your app on Tanzu Platform, you must configure the
-
tanzu deploy:
- If you are deploying an application from an existing build using
tanzu deploy --from-build dir
, you do not need to configure any further settings fortanzu deploy
to work. - If you are using
tanzu deploy
to both build and deploy the application, you must supply the same configuration as fortanzu build
. If you are using daemon build, provide theTANZU_BUILD_CA_CERTS
environment variable to link the certificates directory as described in Configure trusted CAs for daemon builds later in this topic.
- If you are deploying an application from an existing build using
-
The Kubernetes clusters where the application is deployed:
The clusters where the Tanzu Platform Space is scheduled require you to:
- Configure the container runtime of each cluster node to trust the certificate.
- Configure the kapp controller for the cluster to trust the certificate. For instructions, see Configure trusted CAs for kapp controller later in this topic.
If you use Tanzu Kubernetes Grid for cluster management, both steps are handled with a single configuration that you can configure using the Tanzu Platform UI or using a cluster YAML configuration.
To configure this when creating a new Tanzu Kubernetes Grid cluster in the Tanzu Platform UI, configure the settings under Additional cluster settings. You must base64-encode the value you set in the data field. For the YAML configuration and information about the supported fields, see the vSphere documentation.
Configure trusted CAs for daemon builds
To configure daemon builds to trust custom CA certificates for your registry:
-
Authenticate to the registry using
docker login
. -
Ensure that the
containerapp-registry
configured does not includehttps://
prefix, for example:tanzu build config --containerapp-registry my-registry.io/{contact.businessunit}/app-{name}
-
Enable daemon build by running:
tanzu build config --build-engine daemon
-
Create a directory to store certificates, for example:
mkdir path/to/certs/dir
-
Save registry certificate to file in the directory, for example:
openssl s_client -connect my-registry.io:443 -showcerts </dev/null 2>/dev/null|openssl x509 -outform PEM >path/to/certs/dir/registrycert.pem
-
Enable experimental features by running:
tanzu build config --enable-experimental-features
-
Build the application with CA certificate by doing one of the following:
-
Run
tanzu build
with the--ca-certs
flag pointing to the directory storing certificates, for example:tanzu build --ca-certs path/to/certs/dir
-
Alternatively, set the
TANZU_BUILD_CA_CERTS
environment variable before you runtanzu build
, for example:export TANZU_BUILD_CA_CERTS=path/to/certs/dir
-
Configure trusted CAs for kapp controller
If you use a provider other than Tanzu Kubernetes Grid for cluster life cycle management, you must configure the kapp controller on the clusters to trust custom CA certificates for your image registries.
You configure this though a dedicated Secret
or ConfigMap
resource in each cluster called kapp-controller-config
in the same namespace as the kapp-controller
deployment. For more information about configuring the kapp controller, see the Carvel documentation.
If you use Tanzu Kubernetes Grid for cluster life cycle management, this procedure is not required. Configuring the CAs on the Tanzu Kubernetes clusters automatically configures the kapp controller.
To configure this when creating a new Tanzu Kubernetes Grid cluster in the Tanzu Platform UI, configure the settings under Additional cluster settings. You must base64-encode the value you set in the data field. For the YAML configuration and information about the supported fields, see the vSphere documentation.
Follow the steps in this section if you see an error message for your application similar to the following:
vendir: Error: Syncing directory '0':
Syncing directory '.' with imgpkgBundle contents:
Fetching image:
Error while preparing a transport to talk with the registry:
Unable to create round tripper:
Get "https://my-registry.io": tls: failed to verify certificate: x509: certificate signed by unknown authority
(hint: The CA Certificate from URL is unknown/invalid. Add valid CA certificate to the kapp-controller configuration to reconcile successfully)
To configure the kapp controller to trust custom CA certificates for your the registry:
-
Generate a certificate for your registry, for example:
openssl s_client -connect my-registry.io:443 -showcerts </dev/null 2>/dev/null|openssl x509 -outform PEM >/path/to/registrycert.pem
Where the
/path/to/registrycert.pem
is the location to save the new certificate. -
Store the new certificate in a variable, for example:
NEW_CERTS=$(cat /path/to/registrycert.pem)
Where the
/path/to/registrycert.pem
contains the new certificate. -
Retrieve the namespace where the
kapp-controller
deployment is located by running:kubectl get deploy -A | grep kapp-controller
-
Find out if the cluster already has a
Secret
orConfigMap
resource for the kapp controller by running:kubectl get secret -n NAMESPACE kapp-controller-config
kubectl get configmap -n NAMESPACE kapp-controller-config
Where
NAMESPACE
is the namespace of thekapp-controller
you retrieved. -
If a
Secret
orConfigMap
resource does not exist, create aSecret
resource in the namespace for thekapp-controller
by running:kubectl create secret generic kapp-controller-config -n NAMESPACE
Where
NAMESPACE
is the namespace of thekapp-controller
you retrieved. -
Add the new certificate. depending on whether you need to update a
ConfigMap
orSecret
resource:- ConfigMap
- To add the certificate to a
ConfigMap
resource:-
Append the new certificate for your registry to the current contents of the
caCerts
key of yourConfigMap
resource:kubectl edit configmap -n NAMESPACE kapp-controller-config
Where
NAMESPACE
is the namespace of thekapp-controller
you retrieved.
-
- Secret
- To add the certificate to a
Secret
resource:-
If a value already exists in the
caCerts
key:-
Store the value in a variable, for example:
CURRENT_CERTS=$(kubectl get secret -n NAMESPACE kapp-controller-config -o jsonpath="{.data.caCerts}" | base64 --decode)
Where
NAMESPACE
is the namespace of thekapp-controller
you retrieved. -
Add the contents of the
caCerts
key to the variable you set earlier for the new registry certificate, for example:NEW_CERTS=$(echo -n "$CURRENT_CERTS\n$NEW_CERTS")
-
-
Encode the certificates in base64 and copy the result:
echo $NEW_CERTS | base64
-
Update the
caCerts
key of yourSecret
resource with the copied value:kubectl edit secret -n NAMESPACE kapp-controller-config
Where
NAMESPACE
is the namespace of thekapp-controller
you retrieved.
-
After this, Tanzu Platform will trust the new certificates so that you can deploy applications on this cluster from your registry.
Content feedback and comments