- Added Caddyfile example for HTTPS configuration. - Updated README to include Caddy as an optional component. - Modified make-certs.sh to use dynamic account names for certificate generation. - Improved add-account.sh to handle missing accounts.env file gracefully. - Enhanced run-server.sh to support Caddy integration and OAuth options.
87 lines
4.4 KiB
Markdown
87 lines
4.4 KiB
Markdown
# Azure Storage Emulator
|
|
|
|
This is a simple guide that will help you set up and run the Azure Storage Emulator on your local machine. The Azure Storage Emulator allows you to develop and test your applications that use Azure Storage services without needing an actual Azure subscription nor Internet connection.
|
|
|
|
## Prerequisites
|
|
|
|
- Any system that supports fairly recent versions of Node.js (LTS vesions are recommended).
|
|
- A Bash shell (a Linux or macOS system or Windows with WSL2 installed).
|
|
- Docker Community Edition or Docker Desktop (for running the emulator in a containerized environment).
|
|
- Apple `container` command (for running the containerized version of the emulator on macOS).
|
|
- (Optional) Caddy HTTP server (for running the emulator with triple HTTPS endpoints, as it would be in Azure).
|
|
|
|
## Native Installation
|
|
|
|
To install the Azure Storage Emulator natively on your machine, follow these steps:
|
|
|
|
1. Clone the repository:
|
|
|
|
```bash
|
|
git clone https://github.com/azure/azurite
|
|
```
|
|
|
|
2. Navigate to the cloned directory:
|
|
|
|
```bash
|
|
cd azurite
|
|
```
|
|
|
|
3. Build the emulator package.
|
|
|
|
```bash
|
|
npm ci
|
|
npm run build
|
|
npm pack
|
|
```
|
|
|
|
4. Install the package globally using npm:
|
|
|
|
```bash
|
|
npm install -g azurite-*.tgz
|
|
```
|
|
|
|
5. Remove the clone directory, it will not be needed anymore:
|
|
|
|
```bash
|
|
cd ..
|
|
rm -rf azurite
|
|
```
|
|
|
|
## Running the Emulator
|
|
|
|
There are two ways to run the Azure Storage Emulator: as a development server exposing the API on localhost using high ports (10000-10002) or as a fake Azure Storage service. The first one is easy, just run the `azurite` command in your terminal and that's it. The second one is a bit more complex, but it allows you to use the emulator as if it were the real Azure Storage service, and connect to it applications that do not support custom endpoints (Terraform azurerm state storage backend for example).
|
|
|
|
Run the `make-certs.sh` script to generate a self-signed CA certificate and a server certificate signed by that CA. The server certificate will be used by the emulator to serve HTTPS traffic, and the CA certificate can be imported into your system's trusted root certificates store to avoid security warnings when connecting to the emulator.
|
|
|
|
The `make-certs.sh` script will create a storage directory for the emulator and place the generated PEM files there. The script will create a certificate for the `devstoreaccount1.blob.core.windows.net`. You can change that by adding you own storage account name as a single positional parameter. You will also need to map that name to `127.0.0.1` in your hosts file.
|
|
|
|
```bash
|
|
./make-certs.sh myaccount
|
|
```
|
|
|
|
```
|
|
127.0.0.1 devstoreaccount1.blob.core.windows.net devstoreaccount1.queue.core.windows.net devstoreaccount1.table.core.windows.net
|
|
```
|
|
|
|
Next, create an empty `accounts.env` file in the same directory. This file will be used by the emulator to retrieve the storage accounts names and access keys. You can use a single key or a pair of keys for each account. The format of the file is as follows:
|
|
|
|
```shell
|
|
AZURITE_ACCOUNTS="account1:key1,key2;account2:key1,key2;..."
|
|
```
|
|
|
|
Use `add-account.sh` script to add at least one account to the `accounts.env` file. The script will generate random key for each added account. You can use `list-accounts.sh` script to list all accounts and their keys. You can also specify a password that will be used as the value for the key. The key is always Base64 encoded, and you password will also be Base64 encoded before being stored in the `accounts.env` file. The benefit of using a password is that the account key will be deterministic, so you can easily recreate the same account with the same key if needed.
|
|
|
|
Finally, run the emulator using the `run-emulator.sh` script.
|
|
|
|
You can specify `--oauth` to enable simulation of Entra ID Authentication. It requires the endpoints to be directly accessed via HTTPS.
|
|
|
|
The `run-emulator.sh` will detect if Caddy HTTP server is installed on your system, and if it is, it will use it to serve the emulator on triple HTTPS endpoints (Blob, Queue and Table services) as it would be in Azure.
|
|
|
|
Use `--no-caddy` to disable Caddy even if it is installed. It is required to test Entra ID Authentication simulation.
|
|
|
|
## Reference
|
|
|
|
- [Azure Storage Emulator GitHub Repository](https://github.com/azure/azurite)
|
|
- [Azure Storage Emulator Documentation](https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite)
|
|
- [Caddy Server](https://caddyserver.com)
|