Workspace Encryption
Encrypt sensitive Polycrate workspace files with age: secrets.poly.age, artifacts/secrets/**/*.age, WORKSPACE_ENCRYPTION_KEY, Git hooks, and CI/CD usage.
Polycrate encrypts sensitive files in a workspace directly using age (filippo.io/age). This allows teams to safely version an entire workspace — including configuration secrets, SSH keys, and kubeconfigs — in Git.
What Gets Encrypted?
secrets.poly→secrets.poly.age(sensitive block configuration values)- Workspace secrets under
artifacts/secrets/*→artifacts/secrets/*.age(e.g.,kubeconfig.yml,id_rsa,id_rsa.pub) - Block-specific secrets under
artifacts/secrets/<block>/*→artifacts/secrets/<block>/*.age
During encryption, Polycrate removes the plaintext files, writes the .workspace-encrypted marker, updates .gitignore, and automatically enables a Git pre-commit hook.
acme-production-1/
├── workspace.poly # Public configuration (in Git)
├── secrets.poly.age # Encrypted secrets (in Git)
├── .workspace-encrypted # Encryption marker (in Git)
├── .gitignore # Excludes plaintext secrets
└── artifacts/
└── secrets/
├── kubeconfig.yml.age # Encrypted kubeconfig (in Git)
├── id_rsa.age # Encrypted SSH private key (in Git)
├── id_rsa.pub.age # Encrypted SSH public key (in Git)
└── my-app/
└── api-key.txt.age # Encrypted block secret (in Git)
Generating an Encryption Key
You do not need a separate age installation. Generate an age key directly with the Polycrate CLI:
polycrate tools pwgen -a age
The output provides the public key (age1...) and the private key (AGE-SECRET-KEY-1EXAMPLE...). Store the private key in your team password manager and export it as an environment variable in your shell:
export WORKSPACE_ENCRYPTION_KEY="AGE-SECRET-KEY-1EXAMPLE..."
If WORKSPACE_ENCRYPTION_KEY is not set, Polycrate prompts for the key in an interactive terminal.
Standard Workflow: Encrypt, Decrypt, Inspect
1. Create Secrets
# secrets.poly (same structure as workspace.poly, highest merge priority)
blocks:
- name: postgres
config:
admin_password: "example-password-change-me"
- name: cert-manager
config:
letsencrypt:
cloudflare:
api_token: "example-token-change-me"
Runtime merge precedence: block.poly < workspace.poly < secrets.poly.
2. Encrypt the Workspace
export WORKSPACE_ENCRYPTION_KEY="AGE-SECRET-KEY-1EXAMPLE..."
polycrate workspace encrypt
You can then safely commit the state:
git add .
git commit -m "chore: update encrypted workspace secrets"
git push
3. Check Status
polycrate workspace status
This command shows whether a key is available, which files are encrypted or in plaintext, and whether .gitignore and the pre-commit hook are active.
4. Decrypt the Workspace (Local Work)
After a git clone or before executing actions, decrypt the workspace:
export WORKSPACE_ENCRYPTION_KEY="AGE-SECRET-KEY-1EXAMPLE..."
polycrate workspace decrypt
Polycrate restores secrets.poly and all files under artifacts/secrets/ and removes the .age files locally. Before the next commit, encrypt again with polycrate workspace encrypt.
Single-File Mode (--file)
For scripts and targeted operations outside a full workspace, encrypt and decrypt support single-file mode (leaving the source file untouched):
WORKSPACE_ENCRYPTION_KEY="AGE-SECRET-KEY-1EXAMPLE..." polycrate workspace encrypt --file ./payload.yml -o ./payload.yml.age
WORKSPACE_ENCRYPTION_KEY="AGE-SECRET-KEY-1EXAMPLE..." polycrate workspace decrypt --file ./payload.yml.age -o ./payload.yml
Git Pre-Commit Hook
Once .workspace-encrypted exists, Polycrate installs a Git pre-commit hook that blocks commits containing unencrypted files (secrets.poly or plaintext files under artifacts/secrets/).
Manage the hook manually:
polycrate workspace hook status
polycrate workspace hook install
polycrate workspace hook remove
Accessing Secrets in Actions
- Values from
secrets.poly: Automatically merged and available as usual under{{ block.config.* }}in Ansible playbooks. - Kubeconfig (
artifacts/secrets/kubeconfig.yml): Automatically injected into the container viaKUBECONFIGandK8S_AUTH_KUBECONFIG— do not pass a manual--kubeconfigin playbooks. - Other secret files: Accessible via
{{ workspace.secrets['<file>'] }}or{{ block.secrets['<file>'] }}as file paths inside the container (/workspace/artifacts/secrets/...).
# Example: read a block secret file in a playbook
- name: Load API token from block secrets
ansible.builtin.set_fact:
api_token: "{{ lookup('file', block.secrets['api-key.txt']) | trim }}"
no_log: true
Using in CI/CD Pipelines
In pipelines, decrypt the workspace directly with the Polycrate CLI using WORKSPACE_ENCRYPTION_KEY (no separate age package required):
# Example: GitLab CI / Forgejo Actions (WORKSPACE_ENCRYPTION_KEY as a protected CI variable)
deploy:
before_script:
- curl -fsSL https://app.ayedo.cloud/api/v1/cli/public/install.sh | sh
- export PATH="$HOME/.local/bin:$PATH"
script:
- polycrate workspace decrypt
- polycrate run my-app install --non-interactive --force
Key Rotation and Emergency Compatibility
Rotating the Key
# 1. Decrypt with the old key
WORKSPACE_ENCRYPTION_KEY="$OLD_KEY" polycrate workspace decrypt
# 2. Encrypt with the new key
WORKSPACE_ENCRYPTION_KEY="$NEW_KEY" polycrate workspace encrypt
# 3. Commit the updated .age files
git add . && git commit -m "security: rotate workspace encryption key"
100% age-Compatible
All .age files follow the open standard format and can be decrypted independently of Polycrate in an emergency using the standard age CLI (echo "$WORKSPACE_ENCRYPTION_KEY" | age --decrypt -i - secrets.poly.age > secrets.poly).
Security Rules
- Encrypt before every commit: Run
polycrate workspace encryptbeforegit commit/git push. - Never store keys in Git: Keep
WORKSPACE_ENCRYPTION_KEYexclusively in a password manager or CI/CD secret store. - Do not bypass the hook: Never use
git commit --no-verify.
See Also
- Configuration — Interaction of
workspace.polyandsecrets.poly - Artifacts — Structure of
artifacts/secrets/ - Troubleshooting — Help with encryption errors