Blame SOURCES/0003-logging-remove-option-to-log-into-separate-file.patch

956895
From eb5112dd597336b566378b3a157e76fe3cbbbfee Mon Sep 17 00:00:00 2001
956895
From: Thore Sommer <mail@thson.de>
956895
Date: Mon, 16 Jan 2023 07:26:08 -0300
956895
Subject: [PATCH 3/3] logging: remove option to log into separate file
956895
956895
The implementation had the issue that only the main loggers were added and that
956895
the permissions were not set strict enough. Users should use the logging
956895
provided by systemd instead.
956895
956895
Signed-off-by: Thore Sommer <mail@thson.de>
956895
---
956895
 keylime.conf                       | 10 ----------
956895
 keylime/keylime_logging.py         | 31 ------------------------------
956895
 scripts/templates/2.0/registrar.j2 |  9 ---------
956895
 scripts/templates/2.0/verifier.j2  |  9 ---------
956895
 4 files changed, 59 deletions(-)
956895
956895
diff --git a/keylime.conf b/keylime.conf
956895
index d896f9f..043b6a8 100644
956895
--- a/keylime.conf
956895
+++ b/keylime.conf
956895
@@ -342,11 +342,6 @@ tomtou_errors = False
956895
 # signature check before storing them in the database.
956895
 require_allow_list_signatures = False
956895
 
956895
-# Destination for log output, in addition to console. Values can be 'file', 
956895
-# with the file being named after the "service" - cloud_verifier - created under 
956895
-# /var/log/keylime), 'stream' or it can be left empty (which results in 
956895
-# logging to console only, recommended when running inside a container)
956895
-log_destination = file
956895
 
956895
 #=============================================================================
956895
 [tenant]
956895
@@ -595,11 +590,6 @@ auto_migrate_db = True
956895
 # The file to use for SQLite persistence of provider hypervisor data.
956895
 prov_db_filename = provider_reg_data.sqlite
956895
 
956895
-# Destination for log output, in addition to console. Values can be 'file',
956895
-# with the file being named after the "service" - registrar - created under
956895
-# /var/log/keylime), 'stream' or it can be left empty (which results in
956895
-# logging to console only, recommended when running inside a container)
956895
-log_destination = file
956895
 
956895
 #=============================================================================
956895
 [ca]
956895
diff --git a/keylime/keylime_logging.py b/keylime/keylime_logging.py
956895
index bc8a11d..f7c7a8f 100644
956895
--- a/keylime/keylime_logging.py
956895
+++ b/keylime/keylime_logging.py
956895
@@ -1,17 +1,10 @@
956895
 import logging
956895
-import os
956895
 from logging import Logger
956895
 from logging import config as logging_config
956895
 from typing import Any, Callable, Dict
956895
 
956895
 from keylime import config
956895
 
956895
-LOG_TO_FILE = set()
956895
-LOG_TO_STREAM = set()
956895
-LOGDIR = os.getenv("KEYLIME_LOGDIR", "/var/log/keylime")
956895
-# not clear that this works right.  console logging may not work
956895
-LOGSTREAM = os.path.join(LOGDIR, "keylime-stream.log")
956895
-
956895
 logging_config.fileConfig(config.get_config("logging"))
956895
 
956895
 
956895
@@ -50,31 +43,7 @@ def log_http_response(logger: Logger, loglevel: int, response_body: Dict[str, An
956895
 
956895
 
956895
 def init_logging(loggername: str) -> Logger:
956895
-
956895
-    if loggername in ("verifier", "registrar"):
956895
-        logdest = config.get(loggername, "log_destination", fallback="")
956895
-        if logdest == "file":
956895
-            LOG_TO_FILE.add(loggername)
956895
-        if logdest == "stream":
956895
-            LOG_TO_STREAM.add(loggername)
956895
-
956895
     logger = logging.getLogger(f"keylime.{loggername}")
956895
     logging.getLogger("requests").setLevel(logging.WARNING)
956895
-    mainlogger = logging.getLogger("keylime")
956895
-    basic_formatter = logging.Formatter("%(asctime)s %(name)s %(levelname)s %(message)s")
956895
-    if loggername in LOG_TO_FILE:
956895
-        logfilename = os.path.join(LOGDIR, f"{loggername}.log")
956895
-        if not os.path.exists(LOGDIR):
956895
-            os.makedirs(LOGDIR, 0o750)
956895
-        fh = logging.FileHandler(logfilename)
956895
-        fh.setLevel(logger.getEffectiveLevel())
956895
-        fh.setFormatter(basic_formatter)
956895
-        mainlogger.addHandler(fh)
956895
-
956895
-    if loggername in LOG_TO_STREAM:
956895
-        fh = logging.FileHandler(filename=LOGSTREAM, mode="w")
956895
-        fh.setLevel(logger.getEffectiveLevel())
956895
-        fh.setFormatter(basic_formatter)
956895
-        mainlogger.addHandler(fh)
956895
 
956895
     return logger
956895
diff --git a/scripts/templates/2.0/registrar.j2 b/scripts/templates/2.0/registrar.j2
956895
index 3d92303..8de7a50 100644
956895
--- a/scripts/templates/2.0/registrar.j2
956895
+++ b/scripts/templates/2.0/registrar.j2
956895
@@ -71,12 +71,3 @@ auto_migrate_db = {{ registrar.auto_migrate_db }}
956895
 
956895
 # The file to use for SQLite persistence of provider hypervisor data.
956895
 prov_db_filename: {{ registrar.prov_db_filename }}
956895
-
956895
-# Destination for log output, in addition to console. If left empty, the log
956895
-# output will only be printed to console (recommended for containers to avoid
956895
-# filling data storage). The accepted values are:
956895
-# 'file': The log output will also be written to a file named after the
956895
-#         component in '/var/log/keylime/registrar.log'
956895
-# 'stream': The log output will be written to a common file in
956895
-#           'var/log/keylime/keylime-stream.log'
956895
-log_destination = {{ registrar.log_destination }}
956895
diff --git a/scripts/templates/2.0/verifier.j2 b/scripts/templates/2.0/verifier.j2
956895
index d1584df..7a66cb1 100644
956895
--- a/scripts/templates/2.0/verifier.j2
956895
+++ b/scripts/templates/2.0/verifier.j2
956895
@@ -196,12 +196,3 @@ zmq_port = {{ verifier.zmq_port }}
956895
 
956895
 # Webhook url for revocation notifications.
956895
 webhook_url = {{ verifier.webhook_url }}
956895
-
956895
-# Destination for log output, in addition to console. If left empty, the log
956895
-# output will only be printed to console (recommended for containers to avoid
956895
-# filling data storage). The accepted values are:
956895
-# 'file': The log output will also be written to a file named after the
956895
-#         component in '/var/log/keylime/verifier.log'
956895
-# 'stream': The log output will be written to a common file in
956895
-#           'var/log/keylime/keylime-stream.log'
956895
-log_destination = {{ verifier.log_destination }}
956895
-- 
956895
2.38.1
956895