Virtual HSM
Home
  • Virtual HSM
  • Documentation
    • What is Virtual HSM?
    • Use Case: Attested Secret Provisioning in the Cloud
    • Setup
      • Install
      • vHSM Server Configuration
        • Parameters
        • vHSM Telemetry Parameters
      • vHSM Agent
        • Agent Configuration
      • vHSM Proxy
        • Proxy Configuration
    • Get Started
      • Start the Vault server
      • MariaDB root admin password provisioning on Azure DCXas_v5 VM
    • Supported Cloud Configurations
  • Tutorials
    • Deploying the vhsm Container on an EC2 Instance
    • CLI quickstart
    • vHSM Agent quickstart
    • vHSM Proxy quickstart
    • Passing vHSM secrets using ConfigMaps
    • Provisioning MariaDB Password on Azure DCXas_v5 VM
    • Registering a buckypaper plugin
    • Monitoring vHSM with Grafana
  • Integration with Utimaco SecurityServer
    • Integrate enclaive vHSM with Utimaco HSM
  • API
    • Auth
    • Default
    • Secrets
    • System
    • Identity
    • Models
  • vHSM CLI
    • Server and Infrastructure Management
      • vhsm server
      • vhsm proxy
      • vhsm monitor
      • vhsm status
      • vhsm agent
    • Secret Management
      • vhsm read
      • vhsm write
      • vhsm delete
      • vhsm list
      • vhsm secrets
        • vhsm secrets enable
        • vhsm secrets disable
        • vhsm secrets list
        • vhsm secrets move
        • vhsm secrets tune
      • vhsm unwrap
    • Configuration and Management
      • vhsm plugin
        • vhsm plugin info
        • vhsm plugin deregister
        • vhsm plugin list
        • vhsm plugin register
        • vhsm plugin reload
        • vhsm plugin reload-status
      • vhsm namespace
      • vhsm operator
      • vhsm print
      • vhsm path-help
      • vhsm lease
    • Auditing and Debugging
      • vhsm audit
      • vhsm debug
    • Attestation
    • Security and Encryption
      • vhsm pki
        • vhsm pki health-check
        • vhsm pki issue
        • vhsm pki list-intermediates
        • vhsm pki reissue
        • vhsm pki verify-sign
      • vhsm transit
      • vhsm ssh
      • vhsm transform
    • Authentication and Authorization
      • vhsm login
      • vhsm auth
      • vhsm token
      • vhsm policy
    • Storage and Data Mangement
      • vhsm kv
      • vhsm patch
    • vhsm version
      • vhsm version-history
  • Troubleshooting
    • CA Validity Period
    • CRL Validity Period
    • Root Certificate Issued Non-CA Leaves
    • Role Allows Implicit Localhost Issuance
    • Role Allows Glob-Based Wildcard Issuance
    • Performance Impact
    • Accessibility of Audit Information
    • Allow If-Modified-Since Requests
    • Auto-Tidy Disabled
    • Tidy Hasn't Run
    • Too Many Certificates
    • Enable ACME Issuance
    • ACME Response Headers Configuration
  • Resources
    • Community
    • GitHub
    • Youtube
    • CCx101 wiki
Powered by GitBook
On this page

Was this helpful?

  1. Tutorials

Passing vHSM secrets using ConfigMaps

Learn to inject vHSM secrets using ConfigMaps to an application running in Kubernetes.

PreviousvHSM Proxy quickstartNextProvisioning MariaDB Password on Azure DCXas_v5 VM

Last updated 1 month ago

Was this helpful?

vHSM stores secrets securely, but Kubernetes applications need a way to access them. One method is using This section provides instructions to inject vHSM secrets using ConfigMaps to an application running in Kubernetes.

Prerequisites

  • Install

  • Install a Kubernetes cluster

To pass vault secrets using ConfigMaps:

Deploy a sample application

  1. Create a deployment YAML file, named app-deployment.yaml.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: my-app
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: my-app
      template:
        metadata:
          labels:
            app: my-app
        spec:
          containers:
          - name: my-app
            image: nginx
            ports:
            - containerPort: 80
  2. Change to the directory that contains the app-deployment.yaml and apply the deployment.

    kubectl apply -f app-deployment.yaml

    The output is similar to:

    deployment.apps/my-app created
  3. Verify that the application is deployed.

    kubectl get pods

    It might takes a couple of minutes for Pods to be in a Running status. The output is similar to:

    NAME                      READY   STATUS   RESTARTS   AGE
    my-app-86d5bc587d-g85bz   1/1     Running   0          7s
    my-app-86d5bc587d-j4x4p   1/1     Running   0          7s
  4. Create a service to expose the application.

    kubectl expose deployment my-app --type=NodePort --port=80
  5. Find the port on which the application is running.

    kubectl get svc my-app

    The output is similar to:

    NAME     TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
    my-app   NodePort   10.96.114.36   <none>        80:32696/TCP   8s
  6. Port forward the application to access the application in your browser.

    kubectl port-forward svc/my-app 8080:80
  7. Access the application that you deployed in your browser at: http://localhost:8080.

Enable vHSM secrets engine and store the secret

  1. Ensure that vHSM is running and the status is unsealed. For more information about using vHSM CLI, see the vHSM CLI documentation.

    vhsm status

    The output is similar to:

    Key             Value
    ---             -----
    Seal Type       shamir
    Initialized     true
    Sealed          false
    Total Shares    1
    Threshold       1
    Version         1.3.7-0
    Build Date      2025-01-29T15:11:42Z
    Storage Type    inmem
    Cluster Name    vault-cluster-64dcd906
    Cluster ID      d36a3be0-d5ae-380d-58ae-ad2a18b01c6c
    HA Enabled      false
    
  2. Enable KV Secrets Engine, a key-value store that contains secrets in vHSM's physical storage:

    vhsm secrets enable -path=secret kv-v2

    The output is similar to:

    Success! Enabled the kv-v2 secrets engine at: secret/
  3. Store a secret in vHSM:

    vhsm kv put secret/myapp DB_PASSWORD="super-secret-password"

    The output is similar to:

    ===== Secret Path =====
    secret/data/myapp
    
    ======= Metadata =======
    Key                Value
    ---                -----
    created_time       2025-02-02T06:40:35.316916Z
    custom_metadata    <nil>
    deletion_time      n/a
    destroyed          false
    version            1

Create a ConfigMap from vHSM secrets

  1. Retrive the password that you stored in the vHSM server.

    DB_PASSWORD=$(vault kv get -field=DB_PASSWORD secret/myapp)
  2. Create a ConfigMap that would inject the secret from the vHSM.

    kubectl create configmap app-config --from-literal=DB_PASSWORD=$DB_PASSWORD

    The output is similar to:

    configmap/app-config created
  3. Create a new deployment YAML file, named app-with-configmap.yaml.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: my-app-with-configmap
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: my-app
      template:
        metadata:
          labels:
            app: my-app
        spec:
          containers:
          - name: my-app
            image: nginx
            env:
            - name: DB_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: app-config
                  key: DB_PASSWORD
  4. Change to the directory that contains the app-with-configmap.yaml and apply the deployment.

    kubectl apply -f app-with-configmap.yaml

    The output is similar to:

    deployment.apps/my-app-with-configmap created
  5. Verify that the application is deployed.

    kubectl get pods

    The output is similar to:

    NAME                                     READY   STATUS    RESTARTS   AGE
    my-app-86d5bc587d-g85bz                  1/1     Running   0          8m57s
    my-app-86d5bc587d-j4x4p                  1/1     Running   0          8m57s
    my-app-with-configmap-6946f8b754-hfhcn   1/1     Running   0          20s
  6. Verify that secrets are passed to the newly deployed application using the command: kubectl exec -it <pod> -- printenv | grep DB_PASSWORD In this case the Pod that is running with the application with ConfigMap is my-app-with-configmap-6946f8b754-hfhcn.

    kubectl exec -it my-app-with-configmap-6946f8b754-hfhcn -- printenv | grep DB_PASSWORD

    The output is:

    DB_PASSWORD=super-secret-password

    This confirms that the secret for the application is injected to the application using ConfigMaps.

ConfigMaps.
Install vHSM CLI
kubectl
Deploy a sample application in your Kubernetes cluster
Enable vHSM secrets engine and store the secret
Create a ConfigMap from vHSM secrets