Chris Marriott
05/18/2026, 9:27 AMMarvin
05/18/2026, 9:27 AMMarvin
05/18/2026, 9:29 AMSecret block.
Example:
python
from prefect.blocks.system import Secret
Secret(value=private_key_pem).save("my-private-key")
key = Secret.load("my-private-key").get()
A few notes:
- Secret is the general-purpose built-in block for sensitive values
- it works fine for multi-line PEM/private key/certificate text
- values are treated as secret in Prefect and not shown plainly in the UI/logs
- if your cert/key is binary, you’d typically base64-encode it first before storing in Secret
If you’re already using a cloud secret manager, these can also be a better fit:
- AWS Secrets Manager via AwsSecret in prefect-aws
- GCP Secret Manager via GcpSecret in prefect-gcp
So the short answer is:
- Use prefect.blocks.system.Secret for most private key certificate storage needs
- use AWS/GCP secret blocks instead if you want external secret management, versioning, or centralized rotation
Relevant docs:
- Blocks overview
- `Secret` block reference
If you want, I can also show the best pattern for loading a PEM cert/key from a Secret block into a flow or worker process.