Syncing Secrets
The sync command re-encrypts all secret files with a newly generated symmetric key. This is useful for periodic key rotation, after adding team members, or if you suspect a key may have been compromised.
When to use sync
Section titled “When to use sync”Use kanuka secrets sync when you want to:
- Rotate keys periodically for security hygiene
- Ensure consistency after adding new team members
- Respond to potential compromise by invalidating the old key
After syncing, all users with access will receive the new symmetric key encrypted with their public key. The old symmetric key will no longer work.
Running sync
Section titled “Running sync”To sync all secrets with a new encryption key:
kanuka secrets syncThis command:
- Decrypts all secret files using your current symmetric key
- Generates a new symmetric key
- Re-encrypts the symmetric key for each user with access
- Re-encrypts all secret files with the new key
- Writes the updated files to disk
After syncing, commit and push the changes so other team members can pull the newly encrypted files.
Previewing sync
Section titled “Previewing sync”Use the --dry-run flag to see what would happen without making any changes:
kanuka secrets sync --dry-runThis shows:
- How many secret files would be re-encrypted
- Which users would receive the new key
- No files are modified during a dry run
Sync examples
Section titled “Sync examples”# Standard sync with new key generationkanuka secrets sync
# Preview without making changeskanuka secrets sync --dry-run
# Verbose output for debuggingkanuka secrets sync --verboseUsing in CI/CD pipelines
Section titled “Using in CI/CD pipelines”In automated environments where your private key isn’t stored on disk, you can
pipe it directly from a secrets manager using the --private-key-stdin flag:
# From HashiCorp Vaultvault read -field=private_key secret/kanuka | kanuka secrets sync --private-key-stdin
# From 1Password CLIop read "op://Vault/Kanuka/private_key" | kanuka secrets sync --private-key-stdin
# From environment variableecho "$KANUKA_PRIVATE_KEY" | kanuka secrets sync --private-key-stdinWhat happens during sync
Section titled “What happens during sync”The sync operation is atomic - either all files are updated or none are:
- All secret files are decrypted into memory
- A new 256-bit symmetric key is generated using secure random bytes
- The new key is encrypted for each user’s public key
- All secrets are re-encrypted with the new key
- Only after all encryption succeeds are files written to disk
If any step fails, no files are modified.
After syncing
Section titled “After syncing”After a successful sync:
- Commit the changes - All
.kanukafiles have been updated - Push to remote - So team members get the new encrypted files
- Team members pull and decrypt - They can decrypt with no additional steps
git add .git commit -m "Rotate encryption key"git pushNext steps
Section titled “Next steps”- Status command - Check encryption status of files
- Access command - View who has access to secrets
- Revoke guide - Remove a user’s access (includes automatic sync)