Web / Caddy Server Interview questions
How do you configure basic authentication in Caddy?
Caddy protects routes with HTTP Basic Authentication through the basic_auth directive, but it refuses plaintext passwords in the config - you must hash them first.
caddy hash-password --plaintext "mySecretPass" # outputs a bcrypt hash, e.g. $2a$14$Zkq... admin.example.com { basic_auth { alice $2a$14$Zkq... } reverse_proxy localhost:4000 }
The caddy hash-password command produces a bcrypt hash by default (argon2id is also available), which you paste next to the username inside the basic_auth block. Multiple username/hash pairs can be listed for multiple users, and the directive can be scoped to a specific path with a matcher, such as basic_auth /admin/*, so only part of a site requires credentials. On success, Caddy exposes the authenticated username to later directives through the {http.auth.user.id} placeholder.
More Related questions...