Skip to content

Platform Secret Management: From Kubernetes to Key Vault

Interactive Diagram

새 탭 ↗

This article covers the design and implementation of a security architecture for a cloud-based system. Building on the security requirements identified during Discovery, it establishes a comprehensive security framework (Secret management, container security, CSPM (Cloud Security Posture Management)) to build a secure, compliant cloud environment.

From the CDS’s vantage point, the security areas we can actually act on are limited to Platform-adjacent domains such as Application and Kubernetes; overall security needs a much broader approach from a Security Engineering standpoint. This project was scoped to the following:

IDTaskDescription
3.2.6.1Establish a Secret management approachCentralized management of certificates and secrets (e.g., Azure Key Vault), Secret rotation and lifecycle management, wiring secrets into applications
3.2.6.2Container image vulnerability scanningAutomated container vulnerability scanning, establishing a remediation process
3.2.6.3Establish SBOM and container image signing managementSoftware supply chain traceability, generating SBOMs for container images, CI/CD integration for image signing
3.2.6.4Establish CSPM managementManaging the overall security posture of cloud infra via CSPM
  • Security work runs on its own track separate from the application development Sprint, and needs to address actual requirements rather than generic checklists.
  • Scope needs to be coordinated with the existing security organization early in the project.
  • Security: Zero Trust-based access control, least privilege, audit log management, security incident response
  • Scalability: scanning large-scale container environments, unified multi-cloud management, automated vulnerability response
  • Maintainability: version control for security policies, tool upgrade strategy, documentation and training
  • Severity-tiered response, enforcement mechanisms such as blocking deployment on policy violations, and a mandatory approval process for changes to production security policy
  • Keys (encryption keys)
    • Software-protected keys: general-purpose encryption keys
    • HSM-protected keys: high-assurance keys protected by a hardware security module
    • Supported algorithms: RSA_OAEP_256 and other encryption algorithms
    • Mandatory key expiration dates (no permanent keys)
  • Secrets
    • Database connection strings, API keys, passwords
    • Access keys (Redis Cache, Event Hubs, Cosmos DB, etc.)
    • SSH keys and other sensitive configuration
  • Certificates
    • SSL/TLS certificates, client certificates
    • A key and secret with the same name are auto-generated whenever a certificate is created
  • Vault separation: separate Vaults per application, per environment (DEV/STG/PRD), and per region; multi-tenant environments get a Vault per tenant
  • Access control model
    • RBAC-based permissions (no Legacy Access Policy)
    • Least privilege
    • Just-in-time access control (via PIM): PIM (Privileged Identity Management) is an Azure AD capability for temporary elevation and management of admin rights. Administrators activate elevated permissions only when needed (e.g., Key Vault admin rights for 2 hours), and PIM provides audit history and reporting on permission usage.
    • Multi-factor authentication is mandatory

There are broadly two ways to manage and deliver secret data inside Kubernetes.

  • Kubernetes Secrets Store CSI Driver
  • External Secrets Operator

Azure Key Vault, as an Azure managed service, is delivered through the CSI Driver-based model.

Kubernetes Secrets Store CSI Driver

Secrets held in an external secret store are surfaced as a Persistent Volume inside Kubernetes and delivered to consumers that way.

  • No separate Secrets object is created inside Kubernetes; the data is only reachable from within the actual Pod container.
  • With additional configuration, it can also create Kubernetes Secrets from the same data if needed.

External Secret Operator

  • Secrets held in an external secret store are materialized as Kubernetes Secrets and delivered to consumers that way.

  • It also supports the reverse flow (PushSecret), syncing Secrets stored inside Kubernetes back out to an external secret store.

Example: Azure Key Vault-based Secret management

Section titled “Example: Azure Key Vault-based Secret management”

This is an AKS Secrets Store CSI Driver integration with Azure Key Vault. This project ran Applications on Kubernetes-based Container Orchestration and applied a Secrets management approach that integrates Azure Key Vault with Kubernetes. Using SecretProviderClass requires deploying the CSI Driver and creating the CRD, which we enabled through IaC.

AKS ↔ Azure Key Vault integration approach

  • Create a Kubernetes ServiceAccount backed by an Azure User Assigned Managed Identity
  • Based on the ServiceAccount token, a Key Vault secret volume is created and mounted when a Pod is created
  • Secret volume provisioning driven by the Kubernetes custom resource SecretProviderClass
  • Flow: mount the CSI volume to integrate with Key Vault

Enabling the AKS Secrets Store CSI Driver

Enable the secret store add-on in the Terraform resource.

resource "azurerm_kubernetes_cluster" "aks" {
...
key_vault_secrets_provider {
secret_rotation_enabled = true
}
}

Verify the AKS installation:

> kubectl get all -n kube-system -l app=secrets-store-csi-driver
NAME READY STATUS RESTARTS AGE
pod/aks-secrets-store-csi-driver-dj9gj 3/3 Running 0 5h32m
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
daemonset.apps/aks-secrets-store-csi-driver 1 1 1 1 1 <none> 14d

AKS SecretProviderClass (volume-based)

A SecretProviderClass is preconfigured per namespace in AKS, requesting a secret volume whenever a Pod is created in that namespace. It defines the data for specific Azure Key Vault secret objects based on a Managed Identity. You can also generate a Kubernetes Secret from the Key Vault secret value, but the example below avoids creating a Secret object for security reasons.

apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
metadata:
name: frontend-app
namespace: frontend-app
spec:
provider: azure
parameters:
usePodIdentity: "false"
tenantId: <unique-id>
clientID: <unique-id>
keyvaultName: kv-az01-dev-frontend-app-01
objects: |
array:
- |
objectName: sql-az01-dev-frontend-app-01-password
objectType: secret
objectVersion: ""
- |
objectName: redis-az01-dev-frontend-app-01-password
objectType: secret
objectVersion: ""
- |
objectName: cosmos-az01-dev-frontend-app-01-password
objectType: secret
objectVersion: ""

The Deployment mounts the volume and consumes the secret values as files. A separate script reads those files and sets environment variables (ENV) in the Dockerfile.

volumeMounts:
- name: application-properties
mountPath: "/config"
readOnly: true
- name: app-db-secret
mountPath: "/mnt/secrets-store"
readOnly: true
volumes:
- name: application-properties
configMap:
name: app-be-config
items:
- key: application-dev.yml
path: application-dev.yml
- name: app-db-secret
csi:
driver: secrets-store.csi.k8s.io
readOnly: true
volumeAttributes:
secretProviderClass: "app-secrets"

AKS SecretProviderClass (volume + Secret creation)

This approach defines secretObjects data so that a Secret is also created in the namespace. It adds some management/security overhead from having an actual Secret object, but removes the need to manage an entrypoint script in the Dockerfile.

apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
metadata:
name: backend-apps
namespace: backend-apps
spec:
provider: azure
parameters:
usePodIdentity: "false"
tenantId: 00000000-0000-0000-0000-000000000000
clientID: 00000000-0000-0000-0000-000000000000
keyvaultName: kv-az01-dev-backend-01
cloudName: ""
objects: |
array:
- |
objectName: psgrdb-az01-dev-svc-cca-01-cca-app-user
objectType: secret
objectVersion: ""
- |
objectName: psgrdb-az01-dev-svc-cca-01-cca-app-password
objectType: secret
objectVersion: ""
- |
objectName: redis-az01-dev-svc-01-password
objectType: secret
objectVersion: ""
secretObjects:
- data:
- key: DB_USER
objectName: psgrdb-az01-dev-svc-cca-01-cca-app-user
- key: DB_PASSWORD
objectName: psgrdb-az01-dev-svc-cca-01-cca-app-password
secretName: psgrdb-az01-dev-svc-cca-01
type: Opaque
- data:
- key: REDIS_PASSWORD
objectName: redis-az01-dev-svc-01-password
secretName: redis-az01-dev-svc-01
type: Opaque

The Deployment then references these environment variables from the Secret.

- env:
- name: SPRING_PROFILES_ACTIVE
value: dev
- name: JAVA_OPTIONS
value: "-XX:+UseContainerSupport"
- name: DB_ENDPOINT
value: "postgresql-az01-dev-svc-01.postgres.database.azure.com"
- name: DB_SCHEMA_NAME
value: "psgrdb-az01-dev-svc-adm-01"
- name: DB_USER
valueFrom:
secretKeyRef:
key: DB_USER
name: psgrdb-az01-dev-svc-adm-01
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
key: DB_PASSWORD
name: psgrdb-az01-dev-svc-adm-01

Example: Azure Key Vault-based Key management

Section titled “Example: Azure Key Vault-based Key management”

This is how an Application deployed on AKS encrypts data using a Key registered in Azure Key Vault. A data-at-rest encryption requirement surfaced for one of the applications we built, and we managed the key used for that key-based encryption via Azure Key Vault.

The flow by which a Pod running in AKS reaches Azure Key Vault is as follows.

  • Configure a Managed Identity federated to the Service Account of a specific Namespace in the AKS cluster.
  • Grant that Managed Identity permission to use the Azure Key Vault key.
  • Attach the Service Account tied to that identity to the Pod, completing the basic setup for Key Vault access.
  • The application itself uses this identity to obtain a short-lived Azure auth token and access Azure Key Vault with it.

Example Spring Boot application.yaml config:

azure:
keyvault:
uri: https://kv-az01-dev-svc-01.vault.azure.net
key:
name: key-az01-dev-svc-01

Next post: Container Image Vulnerability Management: Registry Scanning and Runtime Risk