8000 feature: added config file permissions check · postgrespro/mamonsu@19c9a7a · GitHub
[go: up one dir, main page]

Skip to content

Commit 19c9a7a

Browse files
committed
feature: added config file permissions check
1 parent fcc55d9 commit 19c9a7a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

github-actions-tests/mamonsu_build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ elif [ "${OS%:*}" = "ubuntu" ]; then
7676
sudo touch /etc/mamonsu/agent.conf
7777
cat /mamonsu/github-actions-tests/sources/agent_3.4.0.conf > /etc/mamonsu/agent.conf
7878
chmod -R 777 /etc/mamonsu/
79+
sudo chmod 600 /etc/mamonsu/agent.conf
80+
sudo chown mamonsu:mamonsu /etc/mamonsu/agent.conf
7981
sudo apt-get -y install ./mamonsu*.deb
8082
service mamonsu restart
8183
sleep 5

mamonsu/lib/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import pwd
23
import socket
34
import os
45
import logging
@@ -79,6 +80,17 @@ def __init__(self, cfg_file=None, plugin_directories=None):
7980
sys.stderr.write('Config file is empty: {0}\n'.format(cfg_file))
8081
sys.exit(1)
8182
if cfg_file is not None:
83+
if platform.LINUX:
84+
config_status = int(repr(oct(os.stat(cfg_file).st_mode))[:-1][-3:])
85+
config_owner = pwd.getpwuid(os.stat(cfg_file).st_uid).pw_name
86+
if not (config_status == 600 and config_owner == "mamonsu"):
87+
logging.info(
88+
"Shut down because of incorrect config file {0} permissions. It must be r/w for mamonsu user only (600).".format(
89+
cfg_file))
90+
sys.stderr.write(
91+
"Please, check your config file {0} permissions. It must be r/w for mamonsu user only (600).\n".format(
92+
cfg_file))
93+
sys.exit(1)
8294
self.config.read_file(open(cfg_file))
8395

8496
plugins = self.fetch('plugins', 'directory', str)

0 commit comments

Comments
 (0)
0