Authentication overview
Warrant provides an authorization as a service platform, enabling developers to embed fine-grained access control into their applications. Authentication with Warrant is primarily managed through the use of API keys, which serve as credentials to identify and authorize client applications making requests to the Warrant API. This approach allows for a clear separation between authentication (verifying the identity of the client) and authorization (determining what the client is allowed to do).
The Warrant API is designed to be accessible from various environments, including both client-side and server-side applications. To accommodate different security requirements, Warrant distinguishes between two types of API keys: Publishable API Keys and Secret API Keys. Each key type is intended for specific operational contexts, ensuring that sensitive operations are protected while still allowing for client-side interactions where appropriate. The overall authentication model focuses on simplicity and security, integrating with existing application architectures without requiring complex identity management protocols like OAuth 2.0 directly for API access, which is typically handled by the application integrating Warrant for user authentication and authorization decisions.
For detailed information on the API endpoints and expected request formats, developers can consult the official Warrant API reference documentation.
Supported authentication methods
Warrant primarily utilizes API keys for authenticating requests to its service. These keys are provisioned through the Warrant dashboard and come in two types, each designed for different security contexts:
| Method | When to Use | Security Level |
|---|---|---|
| Publishable API Keys | Client-side applications (e.g., web browsers, mobile apps) that need to interact with Warrant for non-sensitive operations, such as checking permissions for a currently logged-in user. These keys are safe to expose publicly. | Low (publicly exposed, limited permissions) |
| Secret API Keys | Server-side applications, backend services, and environments where the key can be kept confidential (e.g., server environments, CI/CD pipelines). These keys grant full access to your Warrant tenant and should never be exposed client-side. | High (confidential, full tenant access) |
The choice between a Publishable API Key and a Secret API Key depends on the origin and sensitivity of the API request. Publishable keys allow for a direct integration in client-side code, typically for fetching authorization data relevant to the current user without exposing sensitive backend operations. Secret keys, conversely, are designed for trusted server environments where they can perform administrative actions, manage policies, or create new authorization objects without risk of public exposure.
While API keys are the direct method for authenticating with Warrant, the broader ecosystem often involves an application's own user authentication system. For instance, user authentication might be handled by an OAuth 2.0 provider, which then issues tokens to the application. The application, in turn, uses its Secret API Key to communicate with Warrant's authorization service to enforce policies for the authenticated user. This approach aligns with the principle of separation of concerns, where dedicated services handle specific security aspects, as described in general API security guidelines by organizations like the W3C Security Activity.
Getting your credentials
To obtain your Warrant API keys, you typically follow these steps through the Warrant dashboard:
- Sign Up or Log In: Navigate to the Warrant website and either sign up for a new account or log in to your existing one.
- Access the Dashboard: Once logged in, you will be directed to your Warrant dashboard.
- Locate API Keys Section: Within the dashboard, look for a section related to API Keys, Settings, or Developers. The exact navigation may vary but is usually intuitive.
- Generate Keys: You will typically find options to generate both Publishable API Keys and Secret API Keys. For server-side applications, generate a Secret API Key. For client-side integrations (with appropriate permissions), a Publishable API Key can be generated.
- Copy and Securely Store: Once generated, copy your API keys immediately. For Secret API Keys, it is critical to store them securely. Do not hardcode them directly into your application's source code, especially for public repositories. Instead, use environment variables or a secrets management service.
Warrant's documentation provides specific instructions on how to manage API keys within its platform, including regeneration and revocation processes. It's good practice to rotate your Secret API Keys periodically, especially if you suspect they may have been compromised.
Authenticated request example
When making requests to the Warrant API, your API key must be included in the HTTP Authorization header. The header format typically uses the Bearer scheme, where the API key acts as the bearer token. Here's an example of an authenticated request using a Secret API Key in Python, assuming you've stored your key securely as an environment variable:
import os
import requests
# Retrieve your Secret API Key from an environment variable
WARRANT_API_KEY = os.environ.get("WARRANT_API_KEY")
if not WARRANT_API_KEY:
raise ValueError("WARRANT_API_KEY environment variable not set.")
# Define the API endpoint for listing roles
api_url = "https://api.warrant.dev/v2/roles"
# Set the Authorization header with the Secret API Key
headers = {
"Authorization": f"Bearer {WARRANT_API_KEY}",
"Content-Type": "application/json"
}
try:
response = requests.get(api_url, headers=headers)
response.raise_for_status() # Raise an exception for HTTP errors
# Process the response
roles = response.json()
print("Successfully retrieved roles:")
for role in roles:
print(f"- {role['roleId']}: {role.get('name', 'N/A')}")
except requests.exceptions.HTTPError as e:
print(f"HTTP error occurred: {e}")
print(f"Response content: {e.response.text}")
except requests.exceptions.RequestException as e:
print(f"An error occurred during the request: {e}")
This Python example demonstrates how to make a GET request to the /v2/roles endpoint. The WARRANT_API_KEY is loaded from an environment variable and then prefixed with Bearer in the Authorization header. Similar patterns apply to other programming languages, often facilitated by Warrant's official SDKs, which abstract away the direct header manipulation. For instance, the Warrant JavaScript SDK provides methods to initialize the client with your key.
Security best practices
Securing your Warrant integration involves careful management of your API keys and adherence to general security principles:
- Protect Secret API Keys: Never expose your Secret API Keys in client-side code, public repositories, or unsecured environments. Store them as environment variables, use a secrets management service (e.g., AWS Secrets Manager, Google Secret Manager, Azure Key Vault), or load them from a secure configuration file that is not committed to version control. This is a fundamental security practice for any API key, as emphasized in general security guidance like that from AWS on managing access keys.
- Use Publishable Keys Appropriately: Only use Publishable API Keys for client-side operations that do not require elevated privileges or access to sensitive data. Ensure that any client-side calls are limited to checking permissions for the current user and do not allow for unintended data modification or administrative actions.
- Least Privilege: If Warrant introduces more granular API key permissions in the future, configure keys with the minimum necessary permissions required for their specific function. This limits the blast radius if a key is compromised.
- Key Rotation: Regularly rotate your Secret API Keys. This practice reduces the window of opportunity for an attacker to use a compromised key. Warrant's dashboard typically provides functionality to regenerate keys, invalidating old ones.
- Environment Variables for Configuration: Avoid hardcoding API keys directly into your application's source code. Instead, utilize environment variables for configuration. This makes it easier to manage keys across different deployment environments (development, staging, production) and prevents accidental exposure.
- Secure Communication: Always ensure that all communication with the Warrant API occurs over HTTPS to encrypt data in transit and protect against eavesdropping and man-in-the-middle attacks.
- Monitor API Key Usage: Keep an eye on your Warrant dashboard for any unusual activity or spikes in API requests that might indicate a compromised key or unauthorized access. Implement alerting where possible.
- IP Whitelisting (if available): If Warrant offers IP whitelisting capabilities for API keys, utilize them to restrict API key usage to known, trusted IP addresses. This adds an additional layer of security by preventing requests from unauthorized locations.
- SDK Usage: Whenever possible, use Warrant's official SDKs. These SDKs are designed to handle authentication and API interactions correctly, reducing the risk of common implementation errors that could lead to vulnerabilities. The Warrant Go SDK, for example, streamlines API key usage.