Azure Blob Storage CDN Setup
Azure Blob Storage offers scalable, secure object storage that can be used as a CDN for your static assets such as images, CSS, and JavaScript. Follow these steps to configure your Azure Blob Storage for LibreChat.
1. Create an Azure Storage Account
-
Sign in to Azure:
- Open the Azure Portal and sign in with your Microsoft account.
-
Create a Storage Account:
- Click on “Create a resource” and search for “Storage account”.
- Click “Create” and fill in the required details:
- Subscription & Resource Group: Choose your subscription and either select an existing resource group or create a new one.
- Storage Account Name: Enter a unique name (e.g.,
mylibrechatstorage
). - Region: Select the region closest to your users.
- Performance & Redundancy: Choose the performance tier and redundancy level that best suit your needs.
- Click “Review + Create” and then “Create”. Wait until the deployment completes.
2. Set Up Authentication
You have two options for authenticating with your Azure Storage Account:
Option A: Using a Connection String
-
Navigate to Access Keys:
- In your newly created storage account, go to “Access keys” in the sidebar.
-
Copy Connection String:
- Copy one of the connection strings provided. This string includes the credentials required to connect to your Blob Storage account.
Option B: Using Managed Identity
If your LibreChat application is running on an Azure service that supports Managed Identity (such as an Azure VM, App Service, or AKS), you can use that instead of a connection string.
-
Assign Managed Identity:
- Ensure your Azure resource (VM, App Service, or AKS) has a system-assigned or user-assigned Managed Identity enabled.
-
Grant Storage Permissions:
- In your storage account, assign the Storage Blob Data Contributor (or a similarly scoped role) to your Managed Identity. This allows your application to access Blob Storage without a connection string.
3. Update Your Environment Variables
Create or update your .env
file in your project’s root with the following configuration:
# Option A: Using a Connection String
AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=https;AccountName=yourAccountName;AccountKey=yourAccountKey;EndpointSuffix=core.windows.net
# Option B: Using Managed Identity (do not set the connection string if using Managed Identity)
AZURE_STORAGE_ACCOUNT_NAME=yourAccountName
AZURE_STORAGE_PUBLIC_ACCESS=false
AZURE_CONTAINER_NAME=files
- AZURE_STORAGE_CONNECTION_STRING: Set this if you are using Option A.
- AZURE_STORAGE_ACCOUNT_NAME: Set this if you are using Option B (Managed Identity). Do not set both.
- AZURE_STORAGE_PUBLIC_ACCESS: Set to
false
if you do not want your blobs to be publicly accessible by default. Set totrue
if you need public access (for example, for publicly viewable images). - AZURE_CONTAINER_NAME: This is the container name your application will use (e.g.,
files
). The application will automatically create this container if it doesn’t exist.
4. Configure LibreChat to Use Azure Blob Storage
Update your LibreChat configuration file (librechat.yaml
) to specify that the application should use Azure Blob Storage for file handling:
version: 1.0.8
cache: true
fileStrategy: "azure"
This setting tells LibreChat to use the Azure Blob Storage implementation provided in your code.
Summary
-
Create a Storage Account:
Sign in to the Azure Portal, create a storage account, and wait for deployment to finish. -
Set Up Authentication:
- Option A: Retrieve the connection string from “Access keys” in your storage account.
- Option B: Use Managed Identity by enabling it on your Azure resource and granting it appropriate storage permissions.
- Update Environment Variables:
In your.env
file, set either:
AZURE_STORAGE_CONNECTION_STRING
(for Option A), orAZURE_STORAGE_ACCOUNT_NAME
(for Option B), along with:AZURE_STORAGE_PUBLIC_ACCESS
andAZURE_CONTAINER_NAME
.
- Configure LibreChat:
SetfileStrategy
to"azure"
in yourlibrechat.yaml
configuration file.
With these steps, your LibreChat application will automatically create the container (if it doesn’t exist) and manage file uploads, downloads, and deletions using Azure Blob Storage as your CDN. Managed Identity provides a secure alternative by eliminating the need for long-term credentials.