feat!: the `general.secret_key` configuration field is now required (#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
This commit is contained in:
Jonas L 2023-12-27 18:15:47 +01:00 committed by GitHub
parent 24ee3830c2
commit 0d2d1a2673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 20 additions and 26 deletions

View File

@ -1,5 +1,4 @@
from os import getenv
from warnings import warn
# pylint: disable=unused-import
from ._internal import (
@ -25,14 +24,6 @@ LIBRETIME_CONFIG_FILEPATH = getenv("LIBRETIME_CONFIG_FILEPATH")
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
ALLOWED_HOSTS = ["*"]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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.

View File

@ -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

View File

@ -35,7 +35,7 @@ class Schema implements ConfigurationInterface
->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())

View File

@ -10,6 +10,7 @@ def config():
"general": {
"public_url": "http://localhost:8080",
"api_key": "some_api_key",
"secret_key": "some_secret_key",
},
"stream": {
"outputs": {

View File

@ -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,
}

View File

@ -21,7 +21,7 @@ else:
class GeneralConfig(BaseModel):
public_url: AnyHttpUrlStr
api_key: str
secret_key: Optional[str] = None
secret_key: str
timezone: str = "UTC"

View File

@ -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")