Skip to content

Commit

Permalink
feat!: the general.secret_key configuration field is now required (#…
Browse files Browse the repository at this point in the history
…2841)

BREAKING CHANGE: The `general.secret_key` configuration field is now
required. Make sure to update your configuration file and add a secret
key.

Closes #2426
  • Loading branch information
jooola committed Dec 27, 2023
1 parent 24ee383 commit 0d2d1a2
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 26 deletions.
11 changes: 1 addition & 10 deletions api/libretime_api/settings/prod.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from os import getenv
from warnings import warn

# pylint: disable=unused-import
from ._internal import (
Expand All @@ -25,15 +24,7 @@

CONFIG = Config(LIBRETIME_CONFIG_FILEPATH) # type: ignore[arg-type, misc]

if CONFIG.general.secret_key is None:
warn(
"The [general.secret_key] configuration field is not set but will be required "
"in the next major release. Using [general.api_key] as fallback.",
FutureWarning,
)
SECRET_KEY = CONFIG.general.api_key
else:
SECRET_KEY = CONFIG.general.secret_key
SECRET_KEY = CONFIG.general.secret_key

ALLOWED_HOSTS = ["*"]

Expand Down
5 changes: 2 additions & 3 deletions docker/config.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ general:
# The internal API authentication key.
# > this field is REQUIRED
api_key:
# The Django API secret key. If not defined, the value of [general.api_key] will be
# used as fallback.
# > this field will be REQUIRED starting with LibreTime 4.0.0
# The Django API secret key.
# > this field is REQUIRED
secret_key:

# List of origins allowed to access resources on the server, the public url
Expand Down
5 changes: 2 additions & 3 deletions docker/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ general:
# The internal API authentication key.
# > this field is REQUIRED
api_key:
# The Django API secret key. If not defined, the value of [general.api_key] will be
# used as fallback.
# > this field will be REQUIRED starting with LibreTime 4.0.0
# The Django API secret key.
# > this field is REQUIRED
secret_key:

# List of origins allowed to access resources on the server, the public url
Expand Down
5 changes: 2 additions & 3 deletions docker/example/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ general:
# The internal API authentication key.
# > this field is REQUIRED
api_key: some_secret_api_key
# The Django API secret key. If not defined, the value of [general.api_key] will be
# used as fallback.
# > this field will be REQUIRED starting with LibreTime 4.0.0
# The Django API secret key.
# > this field is REQUIRED
secret_key:

# List of origins allowed to access resources on the server, the public url
Expand Down
4 changes: 2 additions & 2 deletions docs/admin-manual/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ general:
# The internal API authentication key.
# > this field is REQUIRED
api_key: "some_random_generated_secret!"
# The Django API secret key. If not defined, the value of [general.api_key] will be
# used as fallback.
# The Django API secret key.
# > this field is REQUIRED
secret_key: "some_random_generated_secret!"

# List of origins allowed to access resources on the server,
Expand Down
4 changes: 4 additions & 0 deletions docs/releases/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Please follow this **before the upgrade procedure**.

## :arrow_up: Upgrading

### The `general.secret_key` configuration field is required

The `general.secret_key` field in the [configuration file](../admin-manual/configuration.md#general) is now **required**, to prevent reusing the `general.api_key` for cryptographic usage.

## :warning: Known issues

The following issues may need a workaround for the time being. Please search the [issues](https://github.com/libretime/libretime/issues) before reporting problems not listed below.
Expand Down
5 changes: 2 additions & 3 deletions installer/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ general:
# The internal API authentication key.
# > this field is REQUIRED
api_key:
# The Django API secret key. If not defined, the value of [general.api_key] will be
# used as fallback.
# > this field will be REQUIRED starting with LibreTime 4.0.0
# The Django API secret key.
# > this field is REQUIRED
secret_key:

# List of origins allowed to access resources on the server, the public url
Expand Down
2 changes: 1 addition & 1 deletion legacy/application/configs/conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getConfigTreeBuilder()
->arrayNode('general')->addDefaultsIfNotSet()->children()
/**/->scalarNode('public_url')->cannotBeEmpty()->end()
/**/->scalarNode('api_key')->cannotBeEmpty()->end()
/**/->scalarNode('secret_key')->end()
/**/->scalarNode('secret_key')->cannotBeEmpty()->end()
/**/->arrayNode('allowed_cors_origins')->scalarPrototype()->defaultValue([])->end()->end()
/**/->scalarNode('timezone')->cannotBeEmpty()->defaultValue("UTC")
/* */->validate()->ifNotInArray(DateTimeZone::listIdentifiers())
Expand Down
1 change: 1 addition & 0 deletions playout/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def config():
"general": {
"public_url": "http://localhost:8080",
"api_key": "some_api_key",
"secret_key": "some_secret_key",
},
"stream": {
"outputs": {
Expand Down
1 change: 1 addition & 0 deletions playout/tests/liquidsoap/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def make_config(**kwargs) -> Config:
"general": {
"public_url": "http://localhost:8080",
"api_key": "some_api_key",
"secret_key": "some_secret_key",
},
**kwargs,
}
Expand Down
2 changes: 1 addition & 1 deletion shared/libretime_shared/config/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class GeneralConfig(BaseModel):
public_url: AnyHttpUrlStr
api_key: str
secret_key: Optional[str] = None
secret_key: str

timezone: str = "UTC"

Expand Down
1 change: 1 addition & 0 deletions shared/tests/config/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_general_config_timezone():
defaults = {
"public_url": "http://localhost:8080",
"api_key": "api_key",
"secret_key": "secret_key",
}
GeneralConfig(**defaults, timezone="UTC")
GeneralConfig(**defaults, timezone="Europe/Berlin")
Expand Down

0 comments on commit 0d2d1a2

Please sign in to comment.