Skip to main content

Access Token

RustMailer provides an Access Token mechanism to secure access to both REST and gRPC APIs.

Security Recommendation

Access Token protection is disabled by default.

It is strongly recommended to enable it in production environments using environment variables like RUSTMAILER_ENABLE_ACCESS_TOKEN=true.


Enabling Access Token

You can enable token-based access control by setting the following environment variable:

RUSTMAILER_ENABLE_ACCESS_TOKEN=true

Alternatively, you can pass the flag via CLI:

./rustmailer --rustmailer-enable-access-token

If not specified, the default value is false.


Types of Access Tokens

RustMailer supports two types of access tokens:

1. Root Token (Super Admin Token)

  • Grants full system-level privileges.
  • Used to log into the Web UI for administrative operations.
  • The root token can be reset via the Web UI.
  • It is stored in the deployment instance under the directory specified by rustmailer_root_dir.
  • The token is stored in a file named root.

2. Regular Access Tokens

  • Can be created via the Web UI or the OpenAPI interface.
  • Each access token is associated with one or more email accounts.
    • It only allows access to those specific accounts.
  • Each token can be assigned one or more access scopes:
pub enum AccessTokenScope {
/// Grants access to API-related operations.
Api,
/// Grants access to Prometheus metrics endpoints.
Metrics,
}
  • Api scope allows access to all API endpoints (currently no fine-grained control).
  • Metrics scope allows access to Prometheus-compatible metrics.

Future releases may add finer-grained access control based on user feedback.


Rate Limiting and Access Control

  • Access tokens support allowlist (IP whitelisting) and rate limiting based on time windows.
  • Both root tokens and regular tokens use Bearer Authentication, and are supported in both REST and gRPC endpoints.