Skip to main content

A filter for Kubernetes manifests that resolves Keeper URIs in Secret resources using ksm

Project description

Keepomize

A filter for Kubernetes manifests that resolves Keeper URIs in Secret resources using the ksm command-line tool.

Overview

Keepomize is designed to work in a pipeline after Kustomize to resolve Keeper URIs in Kubernetes Secret manifests. It reads a multi-document YAML stream from stdin, finds any Kubernetes Secret resources, and replaces Keeper URIs (keeper://RECORDID/fieldspec) in their stringData and data fields by resolving them through ksm.

Prerequisites

  • Python 3.8 or higher
  • The ksm command-line tool must be installed and available in your PATH
  • Access to Keeper secrets that you want to resolve
  • Any KSM_* environment variables needed for ksm configuration (automatically passed through)

Installation

From PyPI

pip install keepomize

From source

git clone https://github.com/nathanic/keepomize.git
cd keepomize
uv sync
uv run keepomize --help

Development installation

git clone https://github.com/nathanic/keepomize.git
cd keepomize
uv sync --dev

Usage

Basic usage

# Use with kustomize and kubectl
kustomize build overlays/production | keepomize | kubectl apply -f -

# Use with kustomize and oc (OpenShift)
kustomize build overlays/production | keepomize | oc apply -f -

Example Secret manifest

Before processing:

apiVersion: v1
kind: Secret
metadata:
  name: my-app-secrets
  namespace: default
type: Opaque
stringData:
  database-password: keeper://MySQL Database/field/password
  api-key: keeper://API Keys/field/api_key
  username: keeper://MySQL Database/field/login
data:
  secret-token: keeper://Auth Service/field/token  # Will be base64 encoded

After processing with keepomize:

apiVersion: v1
kind: Secret
metadata:
  name: my-app-secrets
  namespace: default
type: Opaque
stringData:
  database-password: my-actual-password
  api-key: sk-1234567890abcdef
  username: mysql_user
data:
  secret-token: bXktYWN0dWFsLXRva2Vu  # base64 encoded value

Keeper URI format

Keeper URIs use Keeper notation which follows this format:

keeper://<TITLE|UID>/<selector>/<parameters>[[predicate1][predicate2]]

Common examples for Kubernetes Secrets:

keeper://MySQL Creds/field/password
keeper://API Keys/field/api_key
keeper://Contact/field/name[first]
keeper://Record/custom_field/phone[1][number]

Where:

  • First segment: Record title or unique identifier (UID)
  • Selector: field for standard fields, custom_field for custom fields, file for files
  • Parameters: Field name or other identifiers
  • Predicates (optional): Array indices [0] and sub-field access [property]

Note: Special characters (/, \, [, ]) in record details must be escaped with backslash.

How it works

  1. Input: Reads multi-document YAML from stdin
  2. Processing:
    • Identifies Kubernetes Secret resources (where kind: Secret)
    • Scans stringData and data fields for Keeper URIs
    • Resolves URIs using ksm secret notation command
    • For data fields, base64 encodes the resolved values
  3. Output: Writes the modified YAML to stdout

Integration with CI/CD

# GitHub Actions example
- name: Deploy with secret resolution
  run: |
    kustomize build overlays/production | keepomize | kubectl apply -f -
  env:
    KSM_CONFIG: ${{ secrets.KSM_CONFIG }}
    KSM_TOKEN: ${{ secrets.KSM_TOKEN }}
    # Any KSM_* environment variables are automatically passed to ksm

Error handling

Keepomize will:

  • Exit with status code 1 if ksm is not found in PATH
  • Exit with status code 1 if any Keeper URI fails to resolve
  • Print error messages to stderr while preserving stdout for the YAML output
  • Preserve all non-Secret resources unchanged

Development

Running tests

uv run pytest

Building for distribution

uv build

Publishing to PyPI

uv publish

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

Changelog

0.1.2

  • Critical Bug Fixes:
    • Fixed trailing newline handling - ksm output now has trailing newlines stripped to prevent malformed secret values
    • Fixed environment variable inheritance - ksm subprocess now inherits full environment (preserves HOME, SSL_CERT_FILE, proxy settings, etc.)
  • Testing: Added comprehensive tests for newline handling edge cases and environment inheritance

0.1.1

  • Bug Fix: Fixed CLI argument parsing to restore --help functionality
  • Testing: Added sys.argv patches to CLI tests for proper argument handling

0.1.0

  • Initial release
  • Support for resolving Keeper URIs in Secret stringData and data fields
  • CLI tool with proper error handling
  • Full test suite

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

keepomize-0.1.2.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

keepomize-0.1.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file keepomize-0.1.2.tar.gz.

File metadata

  • Download URL: keepomize-0.1.2.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for keepomize-0.1.2.tar.gz
Algorithm Hash digest
SHA256 794bf9e62d90ba46afa1d16d03954aacc5c29c97b4f989155692ceb6a03dbbd9
MD5 7f98a33b4ee038e7f469d1530b6c49c2
BLAKE2b-256 e77a298985d8d54106102b977bd30cb5dd7cb0bd9db52a85a519aba940231515

See more details on using hashes here.

Provenance

The following attestation bundles were made for keepomize-0.1.2.tar.gz:

Publisher: release.yml on nathanic/keepomize

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file keepomize-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: keepomize-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for keepomize-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 30ab270c813e09a56391e563d5ac4ee1755d56dda4486706834bcbcc0362649f
MD5 0ee76d2cd76accc0cd416d884755b0f9
BLAKE2b-256 a1230b2739d3a8e4f52752df5624acc8d55cdd643e6a7bd50d1c0710318e67b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for keepomize-0.1.2-py3-none-any.whl:

Publisher: release.yml on nathanic/keepomize

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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