<@ULVA73B9P> how do enable auth for the server api...
# ask-marvin
r
@Marvin how do enable auth for the server api. the server is self hosted
m
thought for 33.7 seconds
Let me provide you with a clear guide on enabling authentication for your self-hosted Prefect server. Here's how to set it up: 1. Enable Basic Authentication - Set the
server.api.auth_string
configuration with your desired admin username and password in the format
"admin:password"
. - You can do this in several ways:
Copy code
bash
     # Option 1: Using environment variable
     export PREFECT_SERVER_API_AUTH_STRING="admin:your_secure_password"
     
     # Option 2: Using Prefect configuration
     prefect config set server.api.auth_string="admin:your_secure_password"
2. Client Configuration - Any clients connecting to your server must use the same authentication string:
Copy code
bash
     prefect config set api.auth_string="admin:your_secure_password"
3. Important Security Notes: - Store the auth string securely (e.g., in a
.env
file or Kubernetes secret) - Make sure
PREFECT_API_KEY
is not set in your environment or profile - Consider enabling CSRF protection for additional security:
Copy code
bash
     prefect config set server.api.csrf_protection_enabled=true
4. Verify Configuration After setting up authentication, test your connection to ensure it's working:
Copy code
bash
   prefect server status
For additional security, you can also configure CSRF token expiration (default is 1 hour):
Copy code
bash
prefect config set server.api.csrf_token_expiration="2h"  # Set to 2 hours
You can find more detailed information about security settings in the Prefect documentation. Let me know if you need help with any specific aspect of the authentication setup or if you're running into any issues!