Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow whitespace and comments in db key file #4516

Merged
merged 1 commit into from Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/4542.feature
@@ -0,0 +1 @@
Parsing of the db encryption key was made resiliant to whitespace and to allow comments.
14 changes: 9 additions & 5 deletions pulpcore/app/models/fields.py
@@ -1,17 +1,15 @@
import json
import logging
import os
from gettext import gettext as _
from functools import lru_cache
from gettext import gettext as _

from cryptography.fernet import Fernet, MultiFernet
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db.models import Lookup, FileField, JSONField
from django.db.models import FileField, JSONField, Lookup
from django.db.models.fields import Field, TextField
from django.utils.encoding import force_bytes, force_str


from pulpcore.app.files import TemporaryDownloadedFile
from pulpcore.app.loggers import deprecation_logger

Expand All @@ -23,7 +21,13 @@ def _fernet():
# Cache the enryption keys once per application.
_logger.debug(f"Loading encryption key from {settings.DB_ENCRYPTION_KEY}")
with open(settings.DB_ENCRYPTION_KEY, "rb") as key_file:
return MultiFernet([Fernet(key) for key in key_file.readlines()])
return MultiFernet(
[
Fernet(key.strip())
for key in key_file.readlines()
if not key.startswith(b"#") and key.strip() != b""
]
)


class ArtifactFileField(FileField):
Expand Down