Skip to content

Commit 0de7693

Browse files
committed
ESC step 3: additional cleanup, bugfixes and new unit tests
1 parent 59c4f7c commit 0de7693

File tree

11 files changed

+259
-176
lines changed

11 files changed

+259
-176
lines changed

hubblestack/config.py

+114-93
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ def _gather_buffer_space():
215215
# Location of the files a minion should look for. Set to 'local' to never ask the master.
216216
"file_client": str,
217217
"local": bool,
218+
# other non-salt hubble-specific things
219+
"fileserver_update_frequency": int,
220+
"grains_refresh_frequency": int,
221+
"scheduler_sleep_frequency": float,
222+
"default_include": str,
223+
"logfile_maxbytes": int,
224+
"logfile_backups": int,
225+
"delete_inaccessible_azure_containers": bool,
226+
"enable_globbing_in_nebula_masking": bool,
227+
"osquery_logfile_maxbytes": int,
228+
"osquery_logfile_maxbytes_toparse": int,
229+
"osquery_backuplogs_count": int,
218230
# When using a local file_client, this parameter is used to allow the client to connect to
219231
# a master for remote execution.
220232
"use_master_when_local": bool,
@@ -399,6 +411,10 @@ def _gather_buffer_space():
399411
"event_match_type": str,
400412
# This pidfile to write out to when a daemon starts
401413
"pidfile": str,
414+
# osquery stuff
415+
"osquery_dbpath": str,
416+
"osquerylogpath": str,
417+
"osquerylog_backupdir": str,
402418
# Used with the SECO range master tops system
403419
"range_server": str,
404420
# The tcp keepalive interval to set on TCP ports. This setting can be used to tune Salt
@@ -646,28 +662,30 @@ def _gather_buffer_space():
646662
# used to mitigate a thundering-herd scenario when many minions start up
647663
# at once and attempt to all connect immediately to the master
648664
"random_startup_delay": int,
649-
# The source location for the winrepo sls files
650-
# (used by win_pkg.py, minion only)
651-
"winrepo_source_dir": str,
652-
"winrepo_dir": str,
653-
"winrepo_dir_ng": str,
654-
"winrepo_cachefile": str,
655-
# NOTE: winrepo_branch omitted here because its value could conceivably be
656-
# loaded as a non-string type, which is OK because winrepo will normalize
657-
# them to strings. But rather than include all the possible types it could
658-
# be, we'll just skip type-checking.
659-
"winrepo_cache_expire_max": int,
660-
"winrepo_cache_expire_min": int,
661-
"winrepo_remotes": list,
662-
"winrepo_remotes_ng": list,
663-
"winrepo_ssl_verify": bool,
664-
"winrepo_user": str,
665-
"winrepo_password": str,
666-
"winrepo_insecure_auth": bool,
667-
"winrepo_privkey": str,
668-
"winrepo_pubkey": str,
669-
"winrepo_passphrase": str,
670-
"winrepo_refspecs": list,
665+
666+
# TO REMOVE: see below # # The source location for the winrepo sls files
667+
# TO REMOVE: see below # # (used by win_pkg.py, minion only)
668+
# TO REMOVE: see below # "winrepo_source_dir": str,
669+
# TO REMOVE: see below # "winrepo_dir": str,
670+
# TO REMOVE: see below # "winrepo_dir_ng": str,
671+
# TO REMOVE: see below # "winrepo_cachefile": str,
672+
# TO REMOVE: see below # # NOTE: winrepo_branch omitted here because its value could conceivably be
673+
# TO REMOVE: see below # # loaded as a non-string type, which is OK because winrepo will normalize
674+
# TO REMOVE: see below # # them to strings. But rather than include all the possible types it could
675+
# TO REMOVE: see below # # be, we'll just skip type-checking.
676+
# TO REMOVE: see below # "winrepo_cache_expire_max": int,
677+
# TO REMOVE: see below # "winrepo_cache_expire_min": int,
678+
# TO REMOVE: see below # "winrepo_remotes": list,
679+
# TO REMOVE: see below # "winrepo_remotes_ng": list,
680+
# TO REMOVE: see below # "winrepo_ssl_verify": bool,
681+
# TO REMOVE: see below # "winrepo_user": str,
682+
# TO REMOVE: see below # "winrepo_password": str,
683+
# TO REMOVE: see below # "winrepo_insecure_auth": bool,
684+
# TO REMOVE: see below # "winrepo_privkey": str,
685+
# TO REMOVE: see below # "winrepo_pubkey": str,
686+
# TO REMOVE: see below # "winrepo_passphrase": str,
687+
# TO REMOVE: see below # "winrepo_refspecs": list,
688+
671689
# Set a hard limit for the amount of memory modules can consume on a minion.
672690
"modules_max_memory": int,
673691
# The number of minutes between the minion refreshing its cache of grains
@@ -822,6 +840,14 @@ def _gather_buffer_space():
822840
"netapi_allow_raw_shell": bool,
823841
}
824842

843+
DEFAULT_CONF_FILE_NAME = DEFAULT_LOG_FILE_NAME = 'hubble'
844+
DEFAULT_OSQUERY_DB_PATH = os.path.join(hubblestack.syspaths.CACHE_DIR, 'osquery')
845+
846+
if hubblestack.utils.platform.is_windows():
847+
DEFAULT_CONF_FILE_NAME = 'hubble.conf'
848+
DEFAULT_LOG_FILE_NAME = "hubble.log"
849+
DEFAULT_OSQUERY_DB_PATH = os.path.join(hubblestack.syspaths.ROOT_DIR, 'var', 'hubble_osquery_db')
850+
825851
# default configurations
826852
DEFAULT_OPTS = {
827853
"interface": "0.0.0.0",
@@ -842,16 +868,16 @@ def _gather_buffer_space():
842868
"master_sign_key_name": "master_sign",
843869
"user": hubblestack.utils.user.get_user(),
844870
"root_dir": hubblestack.syspaths.ROOT_DIR,
845-
"pki_dir": os.path.join(hubblestack.syspaths.CONFIG_DIR, "pki", "minion"),
871+
"pki_dir": os.path.join(hubblestack.syspaths.CONFIG_DIR, "pki"),
846872
"id": "",
847873
"id_function": {},
848-
"cachedir": os.path.join(hubblestack.syspaths.CACHE_DIR, "minion"),
874+
"cachedir": os.path.join(hubblestack.syspaths.CACHE_DIR),
849875
"append_minionid_config_dirs": [],
850876
"cache_jobs": False,
851877
"grains_cache": False,
852878
"grains_cache_expiration": 300,
853879
"grains_deep_merge": False,
854-
"conf_file": os.path.join(hubblestack.syspaths.CONFIG_DIR, "minion"),
880+
"conf_file": os.path.join(hubblestack.syspaths.CONFIG_DIR, DEFAULT_CONF_FILE_NAME),
855881
"sock_pool_size": 1,
856882
"backup_mode": "",
857883
"renderer": "jinja|yaml",
@@ -873,18 +899,27 @@ def _gather_buffer_space():
873899
"pillar_cache": False,
874900
"pillar_cache_ttl": 3600,
875901
"pillar_cache_backend": "disk",
876-
"extension_modules": os.path.join(hubblestack.syspaths.CACHE_DIR, "minion", "extmods"),
902+
"extension_modules": os.path.join(hubblestack.syspaths.CACHE_DIR, "extmods"),
877903
"state_top": "top.sls",
878904
"state_top_saltenv": None,
879905
"startup_states": "",
880906
"sls_list": [],
881907
"top_file": "",
882-
"file_client": "remote",
908+
"file_client": "local",
909+
"fileserver_update_frequency": 43200, # 12 hours
910+
"grains_refresh_frequency": 3600, # 1 hour
911+
"scheduler_sleep_frequency": 0.5, # 500ms
912+
"default_include": 'hubble.d/*.conf',
913+
"logfile_maxbytes": 100000000, # 100MB kindof
914+
"logfile_backups": 1, # max rotated logs
915+
"delete_inaccessible_azure_containers": False,
916+
"enable_globbing_in_nebula_masking": False,
917+
"osquery_logfile_maxbytes": 50000000, # 50MB kindof
918+
"osquery_logfile_maxbytes_toparse": 100000000, # 100MB kindof
919+
"osquery_backuplogs_count": 2,
883920
"local": False,
884921
"use_master_when_local": False,
885-
"file_roots": {
886-
"base": [hubblestack.syspaths.BASE_FILE_ROOTS_DIR]
887-
},
922+
"file_roots": { "base": list() },
888923
"top_file_merging_strategy": "merge",
889924
"env_order": [],
890925
"default_top": "base",
@@ -971,8 +1006,8 @@ def _gather_buffer_space():
9711006
"tcp_pub_port": 4510,
9721007
"tcp_pull_port": 4511,
9731008
"tcp_authentication_retries": 5,
974-
"log_file": os.path.join(hubblestack.syspaths.LOGS_DIR, "minion"),
975-
"log_level": "warning",
1009+
"log_file": os.path.join(hubblestack.syspaths.LOGS_DIR, DEFAULT_LOG_FILE_NAME),
1010+
"log_level": "error",
9761011
"log_level_logfile": None,
9771012
"log_datefmt": _DFLT_LOG_DATEFMT,
9781013
"log_datefmt_logfile": _DFLT_LOG_DATEFMT_LOGFILE,
@@ -1004,7 +1039,7 @@ def _gather_buffer_space():
10041039
"verify_env": True,
10051040
"grains": {},
10061041
"permissive_pki_access": False,
1007-
"default_include": "minion.d/*.conf",
1042+
"default_include": "hubble.d/*.conf",
10081043
"update_url": False,
10091044
"update_restart_services": [],
10101045
"retry_dns": 30,
@@ -1015,24 +1050,29 @@ def _gather_buffer_space():
10151050
"recon_randomize": True,
10161051
"return_retry_timer": 5,
10171052
"return_retry_timer_max": 10,
1018-
"winrepo_source_dir": "salt://win/repo-ng/",
1019-
"winrepo_dir": os.path.join(hubblestack.syspaths.BASE_FILE_ROOTS_DIR, "win", "repo"),
1020-
"winrepo_dir_ng": os.path.join(hubblestack.syspaths.BASE_FILE_ROOTS_DIR, "win", "repo-ng"),
1021-
"winrepo_cachefile": "winrepo.p",
1022-
"winrepo_cache_expire_max": 21600,
1023-
"winrepo_cache_expire_min": 1800,
1024-
"winrepo_remotes": ["https://github.com/saltstack/salt-winrepo.git"],
1025-
"winrepo_remotes_ng": ["https://github.com/saltstack/salt-winrepo-ng.git"],
1026-
"winrepo_branch": "master",
1027-
"winrepo_ssl_verify": True,
1028-
"winrepo_user": "",
1029-
"winrepo_password": "",
1030-
"winrepo_insecure_auth": False,
1031-
"winrepo_privkey": "",
1032-
"winrepo_pubkey": "",
1033-
"winrepo_passphrase": "",
1034-
"winrepo_refspecs": _DFLT_REFSPECS,
1035-
"pidfile": os.path.join(hubblestack.syspaths.PIDFILE_DIR, "salt-minion.pid"),
1053+
# NOTE: keeping this here for reference; but we hoppefully won't need it
1054+
# after the windows phase of the saltless re-work
1055+
# "winrepo_dir": os.path.join(hubblestack.syspaths.BASE_FILE_ROOTS_DIR, "win", "repo"),
1056+
# "winrepo_dir_ng": os.path.join(hubblestack.syspaths.BASE_FILE_ROOTS_DIR, "win", "repo-ng"),
1057+
# "winrepo_source_dir": "salt://win/repo-ng/",
1058+
# "winrepo_cachefile": "winrepo.p",
1059+
# "winrepo_cache_expire_max": 21600,
1060+
# "winrepo_cache_expire_min": 1800,
1061+
# "winrepo_remotes": ["https://github.com/saltstack/salt-winrepo.git"],
1062+
# "winrepo_remotes_ng": ["https://github.com/saltstack/salt-winrepo-ng.git"],
1063+
# "winrepo_branch": "master",
1064+
# "winrepo_ssl_verify": True,
1065+
# "winrepo_user": "",
1066+
# "winrepo_password": "",
1067+
# "winrepo_insecure_auth": False,
1068+
# "winrepo_privkey": "",
1069+
# "winrepo_pubkey": "",
1070+
# "winrepo_passphrase": "",
1071+
# "winrepo_refspecs": _DFLT_REFSPECS,
1072+
"pidfile": os.path.join(hubblestack.syspaths.PIDFILE_DIR, "hubble.pid"),
1073+
"osquery_dbpath": DEFAULT_OSQUERY_DB_PATH,
1074+
"osquerylogpath": os.path.join(hubblestack.syspaths.LOGS_DIR, 'hubble_osquery'),
1075+
"osquerylog_backupdir": os.path.join(hubblestack.syspaths.LOGS_DIR, 'hubble_osquery', 'backuplogs'),
10361076
"range_server": "range:80",
10371077
"reactor_refresh_interval": 60,
10381078
"reactor_worker_threads": 10,
@@ -1293,44 +1333,19 @@ def _absolute_path(path, relative_to=None):
12931333
return path
12941334

12951335

1296-
def load_config(path, env_var, default_path=None, exit_on_config_errors=True):
1336+
def load_config(path, env_var, exit_on_config_errors=True):
12971337
"""
12981338
Returns configuration dict from parsing either the file described by
12991339
``path`` or the environment variable described by ``env_var`` as YAML.
13001340
"""
1341+
1342+
path = env_path = os.environ.get(env_var, path)
1343+
opts = {}
1344+
13011345
if path is None:
13021346
# When the passed path is None, we just want the configuration
13031347
# defaults, not actually loading the whole configuration.
1304-
return {}
1305-
1306-
if default_path is None:
1307-
# This is most likely not being used from salt, i.e., could be salt-cloud
1308-
# or salt-api which have not yet migrated to the new default_path
1309-
# argument. Let's issue a warning message that the environ vars won't
1310-
# work.
1311-
import inspect
1312-
1313-
previous_frame = inspect.getframeinfo(inspect.currentframe().f_back)
1314-
log.warning(
1315-
"The function '%s()' defined in '%s' is not yet using the "
1316-
"new 'default_path' argument to `hubblestack.config.load_config()`. "
1317-
"As such, the '%s' environment variable will be ignored",
1318-
previous_frame.function,
1319-
previous_frame.filename,
1320-
env_var,
1321-
)
1322-
# In this case, maintain old behavior
1323-
default_path = DEFAULT_OPTS["conf_file"]
1324-
1325-
# Default to the environment variable path, if it exists
1326-
env_path = os.environ.get(env_var, path)
1327-
if not env_path or not os.path.isfile(env_path):
1328-
env_path = path
1329-
# If non-default path from `-c`, use that over the env variable
1330-
if path != default_path:
1331-
env_path = path
1332-
1333-
path = env_path
1348+
return opts
13341349

13351350
# If the configuration file is missing, attempt to copy the template,
13361351
# after removing the first header line.
@@ -1343,8 +1358,6 @@ def load_config(path, env_var, default_path=None, exit_on_config_errors=True):
13431358
ifile.readline() # skip first line
13441359
out.write(ifile.read())
13451360

1346-
opts = {}
1347-
13481361
if hubblestack.utils.validate.path.is_readable(path):
13491362
try:
13501363
opts = _read_conf_file(path)
@@ -1479,25 +1492,33 @@ def insert_system_path(opts, paths):
14791492

14801493

14811494
def get_config(
1482-
path,
1495+
path=DEFAULT_OPTS['conf_file'],
14831496
env_var="HUBBLE_CONFIG",
14841497
defaults=None,
14851498
cache_minion_id=False,
14861499
ignore_config_errors=True,
14871500
minion_id=None
14881501
):
14891502
"""
1490-
Reads in the minion configuration file and sets up special options
1491-
1492-
This is useful for Minion-side operations, such as the
1493-
:py:class:`~hubblestack.client.Caller` class, and manually running the loader
1494-
interface.
1503+
Reads in the configuration file
14951504
14961505
.. code-block:: python
14971506
14981507
import hubblestack.config
1499-
minion_opts = hubblestack.config.get_config('/etc/salt/minion')
1508+
__opts__ = hubblestack.config.get_config('/etc/hubble/hubble')
1509+
1510+
1511+
Note that you're probably better off using the daemon loader though. It
1512+
handles a few other things after it uses this get_config function to pull
1513+
the configs from the file.
1514+
1515+
.. code-block:: python
1516+
1517+
import hubblestack.daemon
1518+
__opts__ = hubblestack.daemon.load_config(['-c', '/etc/hubble/hubble'])
1519+
15001520
"""
1521+
15011522
if defaults is None:
15021523
defaults = DEFAULT_OPTS.copy()
15031524

@@ -1506,13 +1527,13 @@ def get_config(
15061527
# Lets see is SALT_CONFIG_DIR is of any use
15071528
salt_config_dir = os.environ.get("SALT_CONFIG_DIR", None)
15081529
if salt_config_dir:
1509-
env_config_file_path = os.path.join(salt_config_dir, "minion")
1530+
env_config_file_path = os.path.join(salt_config_dir, "hubble")
15101531
if salt_config_dir and os.path.isfile(env_config_file_path):
15111532
# We can get a configuration file using SALT_CONFIG_DIR, let's
15121533
# update the environment with this information
15131534
os.environ[env_var] = env_config_file_path
15141535

1515-
overrides = load_config(path, env_var, DEFAULT_OPTS["conf_file"])
1536+
overrides = load_config(path or DEFAULT_OPTS['conf_file'], env_var)
15161537
default_include = overrides.get("default_include", defaults["default_include"])
15171538
include = overrides.get("include", [])
15181539

0 commit comments

Comments
 (0)