Skip to main content

Syncs Azure Key Vault Secrets with a `kube_secret_name` label to Kubernetes Secrets.

Project description

kv-to-kube

Syncs Azure Key Vault Secrets with a kube_secret_name label to Kubernetes Secrets.

Installation

Via Kustomize/Flux for Kubernetes

Installation via Kustomize/Flux 2.0 is the recommended installation approach for kv-to-kube, note this requires Azure Workload Identity to be setup and working along with the respective OIDC Federated Credentials.

Create a kustomize.yaml file with the following content, being sure to replace keyvault-name, excluded-namespaces, and azure.workload.identity/client-id with your desired values:

resources:
  - github.com/cpressland/kv-to-kube/deploy

patches:
  - target:
      kind: CronJob
    patch: |
      - op: replace
        path: /spec/jobTemplate/spec/template/spec/containers/0/command
        value:
        - kv-to-kube
        - --keyvault-name=my-keyvault
        - --excluded-namespaces=kube-system
  - target:
      kind: ServiceAccount
    patch: |
      - op: replace
        path: /metadata/annotations/azure.workload.identity~1client-id
        value: 5d4017fa-3f60-4fcb-a15c-2ffbd8081807

Apply this to your cluster with kubectl apply -k . or using Flux 2.0.

Via Pipx

Pipx is the recommended installation method for running locally, outside of Kubernetes, note this requires azure-cli to be installed and working.

pipx install kv-to-kube

Usage

Once the application is installed either locally or in your cluster, simply create or update secrets within your Key Vault to match the following spec:

{
    "postgres_user": "lunalux",
    "postgres_pass": "asmr",
    "postgres_host": "katherina.postgres.database.azure.com"
}

with a tag of: {"kube_secret_name": "azure-postgres"}

This will create a Kubernetes Secret in all namespaces, as follows:

{
    "apiVersion": "v1",
    "kind": "Secret",
    "metadata": {
        "name": "azure-postgres",
        "namespace": "default",
    },
    "data": {
        "postgres_host": "a2F0aGVyaW5hLnBvc3RncmVzLmRhdGFiYXNlLmF6dXJlLmNvbQ==",
        "postgres_pass": "YXNtcg==",
        "postgres_user": "bHVuYWx1eA=="
    },
    "type": "Opaque"
}

FAQs

Q: What would I use this for? A: I use it with Terraform. During the creation of something like a Postgres Server we store the connection details in Azure Key Vault, AKS then uses kv-to-kube to syncronise those secrets so they can be used in a Pods environment variables.

Q: Why does this delete and re-create secrets instead of updating them? A: I couldn't find an elegant way to perform this operation with the kr8s library. I've opened an issue here, should that get a satifactory resolution I'll change this to update and provide an annotation on the secret for the last updated time. Because of this, I wouldn't recommend using this for secrets that require mounting as a volume. But if thats your use case, you should probably be using a Secrets Store CSI Driver

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kv_to_kube-1.0.4.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kv_to_kube-1.0.4-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file kv_to_kube-1.0.4.tar.gz.

File metadata

  • Download URL: kv_to_kube-1.0.4.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for kv_to_kube-1.0.4.tar.gz
Algorithm Hash digest
SHA256 2ea4069b99ad17c4d7b0ac6d1f2d3cfc4080ff246ea04d5915299a6a52dd3c0a
MD5 f6e965dd79c332e5e37ff227481a6752
BLAKE2b-256 7131b7d638fc9a16859cb7441853adb664672b78a4ba9722dedd1c61929573bd

See more details on using hashes here.

File details

Details for the file kv_to_kube-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: kv_to_kube-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for kv_to_kube-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b2cc5a37a5b5b02ca9bf6a83d97026148f2cb4e64d4a1f7662f67ed6acd9dceb
MD5 a3cd426c73f4e2ea82d29a97303db10a
BLAKE2b-256 fbd1093c9ed8dff6b0178d8514e5489c0ae9c84ea52e07d34a09e7a9e796e63a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page