Skip to main content
Skip table of contents

Thales Luna integration in Kubernetes

The Thales Luna HSM sidecar container enables integrating the application container to a network attached Thales Luna. The following covers how to set up the integration in Kubernetes.

For more general information on the HSM integration with PKCS#11, see HSM Integration.


Current version



Running as unprivileged user 10001:0.


Before using this container, you need the following:

  • Luna7 net-HSM with fully configured secured network access. The EJBCA deployment will be configured with:

    • The IP address/hostname of HSM

    • server.pem certificate

  • Administrative access on the HSM for registering a client and assigning partitions a client

  • P11 Proxy must have network access to the HSM service (security groups, network ACL's, etc)

  • An existing key pair credential for the client i.e. the HSM driver container to communicate with HSM.

HSM driver container deployment parameters

This parameters needs to be configured at the HSM sidecar container.

Environment variables

The following environment variable can be used to adjust the containers behavior:





The IP Address or FQDN of the HSM that the client will connect to.

Default: None
Required: True


Enable logging of PKCS11 calls on the HSM client. The values for this variable are 0 = disabled and 1 = enabled

Default: 0
Required: False


How the HSM slot is protected.
0 → No PED
1 → Crypto Officer
2 → Crypto User

Default: 0
Required: False

Volume mounts

All of the volume mount parameters are mandatory and may only be configured at the sidecar container.


Mount point

HSM Server certificate


Client certificate to communicate with HSM


Client private key to communicate with HSM
(Recommended to be configured as Kubernetes secrets)


Prepare HSM configuration

The server certificate and client credentials are assumed to configured as prerequisite.

We need to configure the server certificate and client credentials as described in last section.

  • Create a Kubernetes secret with the client private key to communicate with HSM.

    • It is recommended to keep the file name in secret as dockerlunaclientKey.pem . Otherwise adjust the values.yaml in next section.

    • The namespace may need to be updated

    • The name of the secret needs also to be reflected at corresponding to line 57 in the values.yaml in next section.

kubectl create secret generic hsm-luna-secret-client-key \
     -n cadeploymentnamespace --from-file=dockerlunaclientKey.pem=dockerlunaclientKey.pem
  • Create a Kubernetes Configmap to configure the HSM server and the client certificate.

    • HSM server certificate: See line 43 in the values.yaml in next section.

    • Client certificate: See line 49 in the values.yaml in next section.

The contents of the certificates are truncated for brevity.

apiVersion: v1
kind: ConfigMap
  name: hsm-luna-configmap
  server.pem: |
    -----END CERTIFICATE-----
  dockerlunaclient.pem: |
    -----END CERTIFICATE-----

Configure Deployment

The following provides an example of customizing the deployment using Helm. Note that the Helm chart values file values.yaml describes an example test deployment and does not include:

  • Database connection.

  • Configured imagePullSecrets that may be required.

  • TLS connection required after the deployment and creation of the CAs.

Ensure that the deployment is allowed an Egress to the physical HSM.

Please adjust the SERVER_NAME environment variable for HSM server in line 28.

#imagePullSecrets: []
    TLS_SETUP_ENABLED: "later"
    LOG_AUDIT_TO_DB: true
  # More convenient way to integrate with HSM will be available soon
  # Extra init containers to be added to the deployment
    - name: hsm-driver-init
          "cp --preserve --recursive /opt/keyfactor/p11proxy-client/* /mnt/driver/",
        - name: p11proxy-client
          mountPath: /mnt/driver/
  # Extra sidecar containers to be added to the deployment
    - name: hsm
        - name: SERVER_NAME
          value: ""
        - name: hsm-luna-configmap-servercert
          mountPath: /opt/luna/certs-server/server.pem
          subPath: server.pem
        - name: hsm-luna-configmap-client-cert
          mountPath: /opt/luna/certs-client/dockerlunaclient.pem
          subPath: dockerlunaclient.pem
        - name: hsm-luna-secret-client-key
          mountPath: /opt/luna/certs-client/dockerlunaclientKey.pem
          subPath: dockerlunaclientKey.pem
  # Extra volumes to be added to the deployment
    - name: p11proxy-client
      emptyDir: {}
    - name: hsm-luna-configmap-servercert
        name: hsm-luna-configmap
          - key: "server.pem"
            path: "server.pem"
    - name: hsm-luna-configmap-client-cert
        name: hsm-luna-configmap
          - key: "dockerlunaclient.pem"
            path: "dockerlunaclient.pem"
    - name: hsm-luna-secret-client-key
        secretName: hsm-luna-secret-client-key
  # Extra volume mounts to be added to the deployment
    - name: p11proxy-client
      mountPath: /opt/keyfactor/p11proxy-client
# needed to make softhsm volume mount to work
  fsGroup: 10001
  enabled: true
  className: "nginx"
  annotations: "optional_no_ca" "default/ejbca-ingress-trust-secret" "true" "1"
    - host: ""
        - path: /
          pathType: Prefix
  # tls:
  #   - hosts:
  #       - ""
  #     secretName: ingress-credential-secret-ca

Create and verify HSM crypto token

To create a crypto token and then test the HSM key, do the following:

  1. In the EJBCA menu, click CA Functions > Crypto Tokens.

  2. Click Create new and specify the following on the New Crypto Token page:

    • Name: Specify a name for the crypto token.

    • Type: Select PKCS#11 NG.

    • Auto-activation: Select use to allow EJBCA to save the password and reapply it after a restart so that the CA is always available.

    • For PKCS#11 : Reference Type, select Slot/Token Label.

    • For PKCS#11 : Reference, select one of the listed slots available in the HSM.

    • Authentication Code: Enter a password for auto-activation, same as provided for the slot or token in the HSM.

    • Click Save to create the crypto token.

  3. Next, you can generate key pairs and any existing key pairs on the HSM are also shown.

  4. To verify that the HSM key is operational, click Test.

test key.png

Advanced deployments

The EJBCA Enterprise configuration export/import tool EJBCA ConfigDump allows you to deploy EJBCA with automation. For information on deploying EJBCA with automation, using a soft HSM integration suitable for testing, see Deploy EJBCA as CA with automation with SoftHSM2.

Thales Luna 7 HSM installations can also be automated using the EJBCA ConfigDump tool. For information on how to configure the tool in Kubernetes, see EJBCA Configdump in Kubernetes.


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.