A CLI tool that makes editing Kubernetes Secrets easier by automatically decoding and encoding base64 values.
When editing Kubernetes Secrets with kubectl edit secret, all values in the data section are base64-encoded, making them difficult to read and edit. You typically have to:
- Decode base64 values manually
- Edit the plaintext
- Re-encode to base64
- Paste back into the YAML
This is tedious and error-prone.
swk (secret-wrapper-k8s) acts as an editor wrapper that:
- Receives the Secret YAML from kubectl
- Automatically decodes all base64 values in the
datasection - Opens your preferred editor with the decoded values
- After you save and exit, re-encodes the values to base64
- Returns the encoded YAML to kubectl
# Clone the repository
git clone https://github.com/davidschrooten/secret-wrapper-k8s.git
cd secret-wrapper-k8s
# Enable nix flake (or install go)
direnv allow
# Build and install
sudo make install
# Or specify a custom installation path
make install INSTALL_PATH=$HOME/.local/bingo build -o swk ./cmd/swkSet swk as your editor when using kubectl edit:
# Use swk with your preferred editor (vim in this example)
EDITOR="swk --editor vim" kubectl edit secret my-secret
# Or using the short flag
EDITOR="swk -e nano" kubectl edit secret my-secretswk determines which editor to use with the following priority:
--editoror-eflag (highest priority)$EDITORenvironment variable$VISUALenvironment variablevi(default fallback)
# Use vim
EDITOR="swk -e vim" kubectl edit secret database-credentials
# Use nano
EDITOR="swk -e nano" kubectl edit secret api-keys
# Use emacs
EDITOR="swk --editor emacs" kubectl edit secret tls-cert
# Use your default $EDITOR
EDITOR=swk kubectl edit secret my-secretYou can set swk as your default Kubernetes editor:
# In your ~/.bashrc or ~/.zshrc
export KUBE_EDITOR="swk -e vim"
# Now you can edit ANY resource type:
kubectl edit secret my-secret # Decodes base64 automatically
kubectl edit deployment my-app # Pass-through (no transformation)
kubectl edit ingress my-ingress # Pass-through (no transformation)
kubectl edit configmap my-config # Pass-through (no transformation)swk intelligently detects whether you're editing a Secret or any other Kubernetes resource:
- kubectl calls
swkwith a temporary YAML file path swkreads the file and detects it's a Kubernetes Secret- All values in the
datasection are decoded from base64 to plaintext - The decoded YAML is written to a new temporary file
- Your chosen editor opens the temporary file
- You edit the plaintext values and save
swkreads the edited file and encodes alldatavalues back to base64- The encoded YAML is written back to kubectl's original temp file
- kubectl applies the changes
swkdetects it's not a Secret- It passes the file directly to your editor without any transformation
- You edit normally and save
- kubectl applies the changes
Note:
swkonly processes thedatasection of Secrets. ThestringDatasection (if present) is left as-is, since it's already plaintext.- You can safely set
export KUBE_EDITOR="swk -e vim"and use it for editing any Kubernetes resource, not just Secrets!
- Go 1.25.5 or later
- make (optional, but recommended)
make build# Run all tests
make test
# Generate coverage report
make coverage# Run linter (requires golangci-lint)
make lint
# Or just run go vet
make vet.
├── cmd/swk/ # Main application entry point
│ ├── main.go # CLI orchestration
│ └── main_test.go # Integration tests
├── internal/
│ ├── editor/ # Editor selection and launching
│ │ ├── editor.go
│ │ └── editor_test.go
│ └── secret/ # YAML transformation (base64 encode/decode)
│ ├── transformer.go
│ └── transformer_test.go
├── Makefile # Build automation
└── README.md # This file
$ kubectl get secret my-secret -o yaml
apiVersion: v1
kind: Secret
metadata:
name: my-secret
type: Opaque
data:
password: cGFzc3dvcmQxMjM= # What does this mean?
username: YWRtaW4= # Have to decode manually$ EDITOR="swk -e vim" kubectl edit secret my-secret
# Your editor opens with:
apiVersion: v1
kind: Secret
metadata:
name: my-secret
type: Opaque
data:
password: password123 # Easy to read!
username: admin # Easy to edit!
# Edit the values directly, save, and exit
# swk automatically encodes them back to base64MIT
Contributions are welcome! Please feel free to submit a Pull Request.
David Schrooten