Overview
This migration guide covers the breaking changes introduced in Blnk v0.12.0, specifically related to API key security enhancements. The main change involves implementing SHA-256 hashing for API keys, which affects how API keys are stored and retrieved.Breaking changes summary
- From: API keys stored in plain text, retrievable from list endpoint
- To: API keys hashed using SHA-256, plain text only available during creation
- Impact: Once upgraded, existing API keys will return authentication errors when used. You must recreate API keys after upgrading.
What changed
- API key hashing: API keys are now hashed using SHA-256 before being stored in the database.
- Plain text key availability: The plain text key is only returned during API key creation (
POST /api-keys). - List endpoint behavior: When listing API keys (
GET /api-keys?owner=<owner_id>), thekeyfield now returns the hashed version instead of the plain text key. - Security enhancement: Plain text keys cannot be retrieved after creation for security reasons.
What still works
- Creating API keys: Plain text key is returned during creation.
- Authentication: The system automatically hashes incoming keys for comparison.
- API key management: Listing, revoking, and checking status still work.
Migration steps
1
Review your API key usage
Identify all places in your codebase where API keys are retrieved or used:
-
Check for code that reads API keys from
GET /api-keys- Any code that expects to use the
keyfield from list responses. - Automation scripts that retrieve keys after creation.
- Migration scripts that read existing API keys.
- Any code that expects to use the
-
Identify API key storage locations
- Where you currently store API keys.
- How you retrieve them for authentication.
- Any caching mechanisms that rely on plain text keys.
2
Update API key creation workflow
Ensure you store the plain text key immediately after creation:Response:Store the key securely:
- Environment variables.
- Secret management systems (AWS Secrets Manager, HashiCorp Vault, etc.).
- Secure configuration files (excluded from version control).
3
Update existing code
Remove any code that expects plain text keys from the list endpoint:Before (BROKEN):After (CORRECT):
4
Migrate existing API keys
Before upgrading, or immediately after:
- Identify all existing API keys that are currently in use.
- Create new API keys with the same scopes and permissions.
- Store the new plain text keys securely immediately after creation.
- Update your applications to use the new keys.
- Test authentication with the new keys.
- Revoke old API keys once migration is complete.
Old API keys cannot be migrated because their plain text values are not stored. You must create new API keys and update your applications to use them.
5
Verify authentication
Test that authentication works correctly:
Authentication works seamlessly—the system automatically hashes incoming keys for comparison with stored hashes.
Security benefits
- Secure storage: API keys are stored as hashes, not plain text.
- Database protection: Even if database is compromised, plain text keys cannot be extracted.
- Best practices: Follows security best practices for credential storage.
- Reduced exposure risk: Reduces risk of key exposure through logs or database dumps.
Technical details
- Hashing algorithm: SHA-256.
- Authentication: System handles hashing automatically during authentication.
- Caching: API key caching has been improved for better performance.
- Cache invalidation: Occurs automatically when keys are revoked.