Customize & Configure
Lunar offers a comprehensive set of configuration options through its policies.yaml
file located in the /etc/lunar-proxy
directory. Serving as the central configuration hub, this file acts as the backbone of Lunar's functionality.
The configuration abilities enable engineering teams to define global policies or end-point related policies, and is used to define remedy and diagnose plugins.
If no remedy or diagnose plugins are defined, Lunar Proxy will act as a regular proxy, forwarding requests to the upstream server and returning the response.
This file is loaded by Lunar Proxy on startup and can be edited and reloaded at runtime. For more information on how to update the configuration at runtime, see Update policies.yaml
while Lunar Proxy is running.
To effectively manage your Lunar configuration and policies, it's recommended to create a local file named policies.yaml
with the described settings. Once you have your custom configuration file ready, you can run Lunar Proxy with this file by mounting it into the Docker container.
Create a local file named policies.yaml
with your desired Lunar configuration settings (as instructed below).
Use the -v
flag in your Docker run command to mount your local policies.yaml
file to the /etc/lunar-proxy
directory inside the Lunar Proxy container. In the docker
command below, please make sure to replace your_local_path
with the actual path to your policies.yaml
file on your host machine, and modify the TENANT_NAME
as you desire.
Here's the modified Docker run command with the local file mount:
docker run -d --rm -p 8000:8000 -p 8081:8081 -p 8040:8040 -e TENANT_NAME="ORGANIZATION" -v "your_local_path":/etc/lunar-proxy --name lunar-proxy lunarapi/lunar-proxy:latest
By mounting your custom policies.yaml
file into the container, you can easily update your Lunar Proxy configuration without the need to stop and restart the container. After making changes to your local policies.yaml
file, use the apply_policies
command to apply the new policies.
docker exec lunar-proxy apply_policies
Structure
The policies.yaml
file is divided into four main sections, which are all optional: allowed_domains, blocked_domains, global, endpoints, exporters, and accounts. The sections are described in detail below.
Overview
The structure of policies.yaml
file is as follows:
Section | Description |
---|---|
mTLS | A list of domains that require mutual TLS (mTLS), each with a specific path to its certificate file. |
allowed_domains | A list of domains to allow through the proxy. |
blocked_domains | A list of domains to block from the proxy. |
global | A list of global remedy and diagnose plugins to apply to all endpoints. |
endpoints | A list of endpoints to configure remedy and diagnose plugins for. |
exporters | A list of exporters to configure. |
accounts | A list of accounts to configure. |
Template
mTLS: # (optional)
- domain: <The upstream provider's domain that requires mTLS.>
cert: <The path to the mTLS certificate file, which must be accessible within the container.>
allowed_domains: # (optional)
- <allowed_domain>
blocked_domains: # (optional)
- <blocked_domain>
global: # (optional)
remedies: # (optional) A list of remedy plugins to apply to all endpoints.
- name: <user_defined_name>
enabled: <true/false>
config:
<remedy_plugin_type>:
# Remedy-specific configuration...
diagnosis: # (optional) A list of diagnose plugins to apply to all endpoints.
- name: <user_defined_name>
enabled: <true/false>
export: <exporter_type> # The name of the exporter to use.
config:
<diagnose_plugin_type>:
# Diagnose-specific configuration...
endpoints: # (optional)
- method: <http_method> # GET/POST/PUT/DELETE/...
url: <url_pattern>
remedies: # (optional) A list of remedy plugins to apply to the endpoint.
- name: <user_defined_name>
enabled: <true/false>
config:
<remedy_plugin_type>:
# Remedy-specific configuration...
diagnosis: # (optional) A list of diagnose plugins to apply to the endpoint.
- name: <user_defined_name>
enabled: <true/false>
export: <exporter_type> # The name of the exporter to use.
config:
<diagnose_plugin_type>:
# Diagnose-specific configuration...
exporters: # (optional)
file:# (optional)
# ...
prometheus:# (optional)
# ...
s3:# (optional)
# ...
accounts:# (optional)
# ...
Path Parameters Configuration
Path parameters allow you to create flexible and reusable URL patterns by defining variable segments within the URL. This enables you to group similar endpoints and apply consistent policies across them.
Why Use Path Parameters?
Path parameters are particularly useful when you have multiple variations of an endpoint that follow a similar pattern, want to apply the same policies to endpoints with variable segments, and need to manage a large number of dynamic endpoints efficiently.
By using path parameters, the discover
command of the proxy presents a more ordered and grouped view, making endpoint management easier. The UI control plane also reflects this organization, offering a clearer and more manageable interface.
Case Example:
Consider an API with multiple URLs, each containing different IDs:
api.com/users/123/profile
api.com/users/456/profile
api.com/users/789/profile
Without declaring a path parameter, each URL variation would be treated as a separate entry, leading to a difficult policy management. Declaring a path parameter like api.com/users/{userId}/profile
consolidates these variations into a single, manageable endpoint, simplifying policy application and improving metrics views.
Defining Path Parameters in policies.yaml
To configure path parameters, you can use the following guidelines:
Basic Syntax:
Define the path parameter within curly braces {}
in the URL pattern.
Example: api.com/api/v1/users/{id}
Combining Wildcards and Path Parameters:
You can use wildcards (*
) along with path parameters.
Example: api.com/api/v1/users/{id}/*
- Defining endpoints explicitly in your
policies.yaml
helps in grouping them appropriately. If high cardinality (50+ variations) is detected, the system will automatically suggest parameter grouping.
Example Configurations:
As part of a Strategy-Based Throttling Remedy Plugin:
endpoints:
- method: GET
url: api.com/api/v1/users/{id}
remedies:
- name: Throttle 1000 requests per minute per account
enabled: true
config:
strategy_based_throttling:
allowed_request_count: 1000
window_size_in_seconds: 60
response_status_code: 429
diagnosis:
- name: Export HAR logs to S3
enabled: true
config:
har_exporter:
transaction_max_size: 100000
obfuscate:
enabled: true
exclusions:
path_params:
- id
response_headers:
- Retry-After
export: s3
As void configurations:
endpoints:
- url: api.com/segmentA/{paramA}/*
method: GET
diagnosis:
- name: "API /segmentA/{paramA}/ path param declaration"
enabled: false
config:
void: {}
export: file
- url: api.com/segmentB/{paramB}/*
method: GET
diagnosis:
- name: "API /segmentB/{paramB}/ path param declaration"
enabled: false
config:
void: {}
export: file
- url: api.com/segmentC/{paramC}/*
method: GET
diagnosis:
- name: "API /segmentC/{paramC}/ path param declaration"
enabled: false
config:
void: {}
export: file
Remedy and Diagnose Plugins
The main purpose of the policies.yaml
file is to define remedy and diagnose plugins, which can be applied on a specific endpoint or globally to all endpoints.
The structure of a remedy or diagnose plugin is as follows:
Field | Type | Description | Required? |
---|---|---|---|
name | String | The name of the plugin. | Yes |
enabled | Boolean | Whether the plugin is enabled or not. | Yes |
config | Object | The configuration of the plugin. | Yes |
export (only for diagnose plugins) | String | The name of the exporter to use. | Yes, only for diagnose plugins |
Only one export
field can be specified for each diagnose plugin.
The configuration of each plugin is described in detail in the documentation of the specific plugin. For a full list of remedy and diagnose plugins see Remedy Plugins and Diagnose.
Example:
global:
remedies:
- name: Response-Based Throttling
enabled: true
config:
response_based_throttling:
retry_after_header: Retry-After
retry_after_type: relative_seconds
quota_group: 1
relevant_statuses:
- 429
diagnosis:
- name: Metrics Collector
enabled: true
config:
metrics_collector: {}
export: prometheus
exporters:
prometheus: {}
In this example, a response-based throttling remedy plugin is enabled and configured to apply to all endpoints (because it is defined under the global section). The Metrics Collector diagnose plugin is enabled and configured to apply to all endpoints. And export the collected metrics to the prometheus exporter, which is defined in the exporters section.
mTLS Configuration
Mutual Transport Layer Security (mTLS) is a protocol that provides both authentication and encryption for communication between two parties. It ensures that only authorized entities can communicate and that their data is protected from eavesdropping and tampering.