Skip to content

Commit

Permalink
Validate settings before running Pulp instance
Browse files Browse the repository at this point in the history
When token authentization is enabled, 4 additional variables have to be
set. The state of these variables is now checked, while properly
informing the user, instead of relying on exceptions raised later during
the instance's run.

closes pulp#1550
  • Loading branch information
MichalPysik committed Jun 27, 2024
1 parent 05c2f1c commit 838f607
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 0 additions & 1 deletion .ci/ansible/settings.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ ANSIBLE_CONTENT_HOSTNAME = "{{ pulp_scheme }}://pulp:{{ 443 if pulp_scheme == 'h
PRIVATE_KEY_PATH = "/etc/pulp/certs/token_private_key.pem"
PUBLIC_KEY_PATH = "/etc/pulp/certs/token_public_key.pem"
TOKEN_SERVER = "{{ pulp_scheme }}://pulp:{{ 443 if pulp_scheme == 'https' else 80 }}/token/"
TOKEN_SIGNATURE_ALGORITHM = "ES256"
CACHE_ENABLED = True
REDIS_HOST = "localhost"
REDIS_PORT = 6379
Expand Down
1 change: 1 addition & 0 deletions CHANGES/1550.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pulp Container specific settings are now properly validated at startup of a Pulp instance.
1 change: 1 addition & 0 deletions pulp_container/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ class PulpContainerPluginAppConfig(PulpPluginAppConfig):

def ready(self):
super().ready()
from . import checks
41 changes: 41 additions & 0 deletions pulp_container/app/checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from django.conf import settings
from django.core.checks import Error as CheckError, register


@register(deploy=True)
def container_settings_check(app_configs, **kwargs):
errors = []

# Other checks only apply if token auth is enabled
if str(getattr(settings, "TOKEN_AUTH_DISABLED", False)).lower() == "true":
return errors

if getattr(settings, "TOKEN_SERVER", None) is None:
errors.append(
CheckError("TOKEN_SERVER variable has to be set when token authentification is enabled"),
id="pulp_container.E001",
)
if getattr(settings, "TOKEN_SIGNATURE_ALGORITHM", None) is None:
errors.append(
CheckError(
"TOKEN_SIGNATURE_ALGORITHM variable has to be set when token authentification"
" is enabled",
id="pulp_container.E002",
)
)
if getattr(settings, "PUBLIC_KEY_PATH", None) is None:
errors.append(
CheckError(
"PUBLIC_KEY_PATH variable has to be set when token authentification is enabled",
id="pulp_container.E003",
)
)
if getattr(settings, "PRIVATE_KEY_PATH", None) is None:
errors.append(
CheckError(
"PRIVATE_KEY_PATH variable has to be set when token authentification is enabled",
id="pulp_container.E004",
)
)

return errors

0 comments on commit 838f607

Please sign in to comment.