API ReferenceAuthentication

Authentication

BunnyDB uses JWT (JSON Web Token) based authentication. Users must log in to obtain a token, which is then used to authenticate subsequent API requests.

Login

Authenticate with username and password to receive a JWT token.

Endpoint

POST /v1/auth/login

Permission: open (no authentication required)

Request Body

FieldTypeRequiredDescription
usernamestringYesUsername
passwordstringYesPassword

Response

FieldTypeDescription
tokenstringJWT token for authenticating future requests
usernamestringAuthenticated username
rolestringUser role (admin or viewer)

Example

curl -X POST http://localhost:8112/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "username": "admin",
    "password": "admin"
  }'
⚠️

The default admin credentials are admin:admin. Change these immediately in production environments by setting the BUNNY_ADMIN_USER and BUNNY_ADMIN_PASSWORD environment variables.

Error Responses

Status CodeErrorDescription
400Bad RequestMissing username or password
401Invalid credentialsWrong username or password

Get Current User

Retrieve information about the currently authenticated user.

Endpoint

GET /v1/auth/me

Permission: authed (any authenticated user)

Response

FieldTypeDescription
usernamestringCurrent user’s username
rolestringCurrent user’s role (admin or viewer)

Example

curl http://localhost:8112/v1/auth/me \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Error Responses

Status CodeErrorDescription
401UnauthorizedMissing or invalid token

Change Password

Change the password for the currently authenticated user.

Endpoint

POST /v1/auth/change-password

Permission: authed (any authenticated user)

Request Body

FieldTypeRequiredDescription
current_passwordstringYesCurrent password for verification
new_passwordstringYesNew password to set

Response

FieldTypeDescription
messagestringSuccess confirmation message

Example

curl -X POST http://localhost:8112/v1/auth/change-password \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "current_password": "admin",
    "new_password": "new-secure-password"
  }'

After changing your password, your current token remains valid. However, you’ll need to use the new password for future logins.

Error Responses

Status CodeErrorDescription
400Bad RequestMissing current or new password
401UnauthorizedMissing or invalid token, or incorrect current password

Using Authentication Tokens

After obtaining a token from the login endpoint, include it in the Authorization header for all authenticated requests:

Authorization: Bearer <your-token>

Token Lifecycle

  • Tokens are issued upon successful login
  • Tokens do not expire (stateless JWT)
  • Tokens remain valid until the JWT secret is rotated
  • Users can have multiple active tokens simultaneously

Security Best Practices

⚠️

Production Security Recommendations:

  1. Set a strong BUNNY_JWT_SECRET environment variable (not the auto-generated default)
  2. Change default admin credentials immediately
  3. Use HTTPS/TLS for all API communication to protect tokens in transit
  4. Store tokens securely (never in source code or logs)
  5. Deploy BunnyDB in a private network, not exposed to the public internet

Role-Based Access Control

BunnyDB supports two user roles:

Admin Role

  • Full access to all API endpoints
  • Can create, update, and delete resources
  • Can manage users
  • Can perform all mirror control operations

Viewer Role

  • Read-only access to most resources
  • Cannot create, update, or delete resources
  • Cannot manage users
  • Useful for monitoring and reporting purposes

See the Users page for managing user accounts and roles.