1919
2020app = Flask (__name__ )
2121
22+ # Setup logging (stdout only - journald will capture it)
23+ logging .basicConfig (
24+ level = logging .INFO ,
25+ format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' ,
26+ handlers = [logging .StreamHandler (sys .stdout )]
27+ )
28+ logger = logging .getLogger (__name__ )
29+
2230# Configuration
2331CONFIG_FILE = os .environ .get ('CHELON_CONFIG' , '/etc/chelon/chelon.conf' )
2432DATA_DIR = '/var/lib/chelon'
@@ -28,6 +36,19 @@ def load_config(path):
2836 config = {}
2937 if not os .path .exists (path ):
3038 return config
39+
40+ # Security check using stat
41+ try :
42+ st = os .stat (path )
43+ # Check for world access (read/write/execute)
44+ if st .st_mode & 0o007 :
45+ logger .critical (f"Config file { path } is world-accessible ({ oct (st .st_mode & 0o777 )} )." )
46+ logger .critical ("Please secure it: chmod 600 or 640 " + path )
47+ sys .exit (1 )
48+ except OSError as e :
49+ logger .error (f"Error checking config permissions: { e } " )
50+ sys .exit (1 )
51+
3152 try :
3253 with open (path , 'r' ) as f :
3354 for line in f :
@@ -38,28 +59,18 @@ def load_config(path):
3859 k , v = line .split ('=' , 1 )
3960 config [k .strip ()] = v .strip ()
4061 except Exception as e :
41- print (f"Error loading config: { e } " )
62+ logger . error (f"Error loading config: { e } " )
4263 return config
4364
4465# Initialize components
4566config = load_config (CONFIG_FILE )
4667# Log config status
47- lp = config .get ('LEGACY_PASSPHRASE' )
48- mp = config .get ('MODERN_PASSPHRASE' )
49- print (f"DEBUG: Config loaded. Legacy PP len: { len (lp ) if lp else 0 } , Modern PP len: { len (mp ) if mp else 0 } " )
68+ logger .info ("Configuration loaded successfully" )
5069
5170signing_engine = SigningEngine ()
5271token_auth = TokenAuth (config_file = CONFIG_FILE )
5372audit_logger = AuditLogger ()
5473
55- # Setup logging (stdout only - journald will capture it)
56- logging .basicConfig (
57- level = logging .INFO ,
58- format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' ,
59- handlers = [logging .StreamHandler (sys .stdout )]
60- )
61- logger = logging .getLogger (__name__ )
62-
6374
6475def _handle_signing (operation ):
6576 """Common signing logic for both RPMs and repodata"""
@@ -88,6 +99,11 @@ def _handle_signing(operation):
8899 return jsonify ({'error' : 'Invalid JSON' }), 400
89100
90101 raw_data_b64 = data .get ('data' )
102+
103+ # DoS Protection: Limit payload size
104+ if raw_data_b64 and len (raw_data_b64 ) > 10 * 1024 * 1024 : # 10MB limit
105+ return jsonify ({'error' : 'Payload too large (limit 10MB)' }), 413
106+
91107 package_hash = data .get ('package_hash' )
92108 repodata_hash = data .get ('repodata_hash' )
93109 key_type = data .get ('key_type' , 'legacy' )
0 commit comments