Vugar Yagubov
08/01/2025, 12:32 PMMarvin
08/01/2025, 12:32 PMMarvin
08/01/2025, 12:35 PMPREFECT_API_KEY
and PREFECT_CLIENT_CUSTOM_HEADERS
This design is actually beneficial for your use case because:
- If you update the PREFECT_API_KEY
environment variable during flow execution, subsequent API calls will use the new token
- You can implement token rotation without needing to restart your flows
- There's no risk of getting "stuck" with an expired token for the entire flow duration
Best Practices:
1. If you're implementing token rotation, make sure to update the environment variable with the new token
2. Consider implementing a token refresh mechanism that updates the environment variable before the current token expires
3. For very long-running flows, you might want to implement a mechanism to refresh the token periodically during execution
This behavior is intentional and provides flexibility for authentication management in long-running processes.Vugar Yagubov
08/01/2025, 2:42 PMMarvin
08/01/2025, 2:42 PMMarvin
08/01/2025, 2:43 PMPREFECT_SERVER_API_AUTH_STRING
works:
1. Scope of Authentication:
- The auth string secures BOTH the API and UI access
- It implements basic HTTP authentication across all server endpoints
- When set, it requires authentication for all operations (create, delete, update, etc.)
2. How it works:
- Format: username:password
(e.g., "admin:secretpassword")
- For API access: Used in HTTP Basic Authentication headers
- For UI access: Triggers a browser authentication prompt when you first access the UI
3. UI Authentication Flow:
- When you first access the UI, your browser will show a native authentication prompt
- Once authenticated, the browser will automatically send these credentials with subsequent requests
- The credentials are automatically saved by your browser (standard browser behavior for Basic Auth)
- You don't need to manually save anything; the browser handles credential persistence
4. Important Implementation Notes:
- Don't use quotes when setting the environment variable:
bash
# Correct
export PREFECT_SERVER_API_AUTH_STRING=admin:secretpassword
# Incorrect (with quotes)
export PREFECT_SERVER_API_AUTH_STRING="admin:secretpassword"
- Make sure not to have both PREFECT_API_KEY
and PREFECT_SERVER_API_AUTH_STRING
set simultaneously
- The auth string should be set on both the server and any clients connecting to it
5. Known Limitations/Issues:
- As of Prefect 3.2.14, there's an open issue where WebSocket endpoints (used by prefect events stream
) might not require authentication even when the auth string is set
- Some users have reported UI authentication issues when the auth string contains special characters
6. Security Best Practices:
- Use a strong password in the auth string
- Consider using environment variables or secrets management for storing the auth string
- If behind a reverse proxy (like nginx), you can add an additional layer of authentication at the proxy level
Remember that this is a basic authentication mechanism. For more robust security requirements, you might want to consider:
- Putting Prefect behind a reverse proxy with additional security measures
- Using VPN or similar network-level security
- Implementing additional authentication at the infrastructure level