# Configuration

---

## Setting Configuration Values

Fides can be configured in two different ways: either via a `toml` file or via environment variables.
Both methods can be used simultaneously, with environment variables taking precedence over the `toml` file values.

### Using a Configuration File

Fides will use the first config file it can read from the following locations. Listed in order of precedence they are:

1. At the path specified using the config file argument passed through the CLI, i.e. `fides -f <config_path>`
1. At the path specified by the `FIDES__CONFIG_PATH` environment variable
1. In the current working directory it will check for a subdir `.fides` and a file within named `fides.toml`, i.e. `./.fides/fides.toml`

### Generating a Config File

If you'd like to generate a new config file automatically using default values, run `fides init`.
This will create the file at the default location of `./.fides/fides.toml`

### Setting Values Via Environment Variables

Fides follows a set pattern for configuration via environment variables.
It looks for environment variables that start with `FIDES` followed by the config subsection name, followed by the key name, all separated with double underscores.
In practice this would look like `FIDES__<SUBSECTION>__<KEY>`

As a `toml` configuration value:

```toml
[database]
host = config_example
```

As an environment variable:

```sh
EXPORT FIDES__DATABASE__HOST=config_example
```

---

## Viewing your configuration

You can view the current configuration of your application via either the CLI or API.

### CLI

To view your application configuration via the CLI, run:

```sh
fides view config
```

This will show _all_ configuration variables, including sensitive ones.
It is printed to the console as valid `toml`, so this can be copy/pasted as needed.

### API

To view your application configuration in the API, run:

```sh
GET /api/v1/config
```

For security reasons, sensitive configuration values will not be shown here.

## Special Sections

There are a few "special" configuration sections that behave in unique ways compared to the other sections. These sections will be addressed in the following documentation.

### Celery

Fides uses [Celery](https://docs.celeryq.dev/en/stable/index.html) for asynchronous task management.

To simplify deployments and remove the need for two different toml configuration files, it is possible to configure Celery via the Fides configuration file. Any valid configuration key/value pair for Celery can instead be added to the Fides toml configuration file and will automatically be passed through to the Celery deployment. Note that Fides will not validate any of these key/value pairs. See the above configuration file reference for an example of using celery configuration pass-through.

For a full list of possible variable overrides, see the [Celery configuration documentation](https://docs.celeryq.dev/en/stable/userguide/configuration.html).

```toml title="Example Celery Section"
[celery]
event_queue_prefix = "fides_worker"
task_default_queue = "fides"
task_always_eager = true
```

### Credentials

The credentials section uses custom keys which can be referenced in specific commands that take the --credentials-id option. For example, a command that uses a credential might look like `fides scan dataset db --credentials-id app_postgres`. The credential object itself will be validated at the time of use depending on what type of credential is required. For instance if `fides scan system okta` is used, it will expect the object to contain orgUrl, clientId, and privateKey key/value pairs for OAuth2 authentication. In the case of a typical database like postgres, it will only expect a connection_string. The following is an example of what a credentials section might look like in a given deployment with various applications:

```toml title="Example Credentials Section"
[credentials]
app_postgres = {connection_string="postgresql+psycopg2://postgres:fides@fides-db:5432/fides"}
```

## Configuration File Reference

This following file is an autogenerated configuration reference file. It shows application defaults and is a valid `toml` file that can be used for configuration of Fides.

```toml title="fides.toml"
-8<- "fides.toml"
```
