-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Related to torrust/torrust-index-gui#664
Current Situation
Torrust Index loads a read-only configuration upon startup; this configuration is static over the lifetime of the program.
Details
The Torrust Index reads its settings in TOML format from two places:
- A file:
/etc/torrust/index/index.toml, or a path overridden by theTORRUST_INDEX_CONFIG_TOML_PATHenvironment variable. - From the environment variable:
TORRUST_INDEX_CONFIG_TOML.
If both configurations are present, the configuration supplied by the environment variable takes precedence.
The TOML format is overridden by configuration options supplied by the TORRUST_INDEX_CONFIG_OVERRIDE__ environment variable prefix.
This merged configuration is read-only for the lifetime of a torrust-index instance.
Configuration Types
There is a matrix of different types of configuration that the Torrust Index uses, for example:
| Immutable (Cannot be changed after initialization) | Mutable (Can be changed during runtime) | |
|---|---|---|
| Startup-Defined | Startup-Immutable: Values known at startup, fixed for app lifetime (e.g., DB Connection String) | Startup-Mutable: Values known at startup, but can be modified later (e.g., Logging Level) |
| Runtime-Defined | Runtime-Immutable: Values determined during execution, fixed once set (e.g., API Socket) | Runtime-Mutable: Values determined during execution, can be changed dynamically (e.g., Index Policy) |
There is also a matrix of different administration levels for the configuration:
| Private | Public | General | |
|---|---|---|---|
| System Admin | Only System Admin can set and view | Only the System Admin can set; others may see | Override value by default or Service Admin |
| Service Admin | Cannot access | Can view | Can set |
| Application Defaults | Not applicable | Default value | Default value |
Proposal
Split the Configuration into Four Separate Files Controlled by the System Administrator
The same settings can be supplied via environment variables, similar to the current implementation. If both a configuration file and the corresponding environment variable are present, the environment variable takes precedence.
1. Immutable-Private Configuration
/etc/torrust/index/private.toml or TORRUST_INDEX_CONFIG_PRIVATE
This file will contain settings that are set by the system administrator and should only be known by the system administrator.
Example: the DB Connection String.
2. Immutable-Public Configuration
/etc/torrust/index/public.toml or TORRUST_INDEX_CONFIG_PUBLIC
This file will contain settings that are set by the system administrator and may be shared with the service administrator (or more).
Examples:
- Public socket of the service
- Initial logging level of the service
3. General Forced
/etc/torrust/index/forced.toml or TORRUST_INDEX_CONFIG_FORCED
This file will contain settings that are overridden by the system administrator.
Examples:
- Obligatory Privacy Policy
- Runtime logging level of the service
4. General Default
/etc/torrust/index/default.toml or TORRUST_INDEX_CONFIG_DEFAULT
This file will contain default settings that are set by the system administrator.
Examples:
- Default logo
- Welcome message
Create an In-Database Settings File
As a record inside the database:
This record will contain a json_utf8 formatted entry with the settings supplied by the service administrator.
The following endpoints and actions will be created:
| Endpoint | Action | Response |
|---|---|---|
/admin/current |
GET | 200 OK: Returns the current configuration as supplied by the service administrator, or 204 No Content |
/admin/current |
PUT | 200 OK: Sets new configuration; 400 Bad Request if the configuration is invalid |
/admin/merged |
GET | 200 OK: Returns the current active configuration, including the public, overridden, current, and default settings, merged |
/admin/default |
GET | 200 OK: Returns the default configuration, or 204 No Content |
/admin/override |
GET | 200 OK: Returns any overrides for the configuration, or 204 No Content |