Bug in logrotate module when shorthand configuration used
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
Bug in logrotate module when shorthand configuration used
Setup
(Please provide relevant configs and/or SLS files (be sure to remove sensitive info. There is no general set-up of Salt.)
Please be as specific as possible and give set-up details.
- on-prem machine
- VM (Virtualbox, KVM, etc. please specify)
- VM running on a cloud service, please be explicit and add details
- container (Kubernetes, Docker, containerd, etc. please specify)
- or a combination, please be explicit
- jails if it is FreeBSD
- classic packaging
- onedir packaging
- used bootstrap to install
Steps to Reproduce the behavior
While looking into a diskspace / syslog issue yesterday I executed salt 'COMPUTERNAME' logrotate.get /var/log/auth.log rotate /etc/logrotate.d/syslog-ng to see how logrotate was configured for the auth.log file and it failed.
Here's what /etc/logrotate.d/syslog-ng looks like
# cat /etc/logrotate.d/syslog-ng
/var/log/syslog
{
rotate 7
daily
missingok
notifempty
delaycompress
compress
postrotate
invoke-rc.d syslog-ng reload > /dev/null
endscript
}
/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
/var/log/error
{
rotate 4
weekly
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
invoke-rc.d syslog-ng reload > /dev/null
endscript
}
salt 'COMPUTERNAME' logrotate.get /var/log/auth.log rotate /etc/logrotate.d/syslog-ng
It failed with
[ERROR ] An un-handled exception was caught by Salt's global exception handler:
AttributeError: 'bool' object has no attribute 'get'
If I try again, but for syslog or error files it works.
salt 'COMPUTERNAME' logrotate.get /var/log/syslog rotate /etc/logrotate.d/syslog-ng
COMPUTERNAME:
7
salt 'COMPUTERNAME' logrotate.get /var/log/error rotate /etc/logrotate.d/syslog-ng
COMPUTERNAME:
4
But not for messages...
salt 'COMPUTERNAME' logrotate.get /var/log/messages rotate /etc/logrotate.d/syslog-ng
COMPUTERNAME:
The minion function caused an exception: Traceback (most recent call last):
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/minion.py", line 1969, in _thread_return
return_data = minion_instance._execute_job_function(
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/minion.py", line 1925, in _execute_job_function
return_data = self.executors[fname](opts, data, func, args, kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 160, in __call__
ret = self.loader.run(run_func, *args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1269, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1284, in _run_as
return _func_or_method(*args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/executors/direct_call.py", line 10, in execute
return func(*args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 160, in __call__
ret = self.loader.run(run_func, *args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1269, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1284, in _run_as
return _func_or_method(*args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/logrotate.py", line 161, in get
return stanza.get(value, False)
AttributeError: 'bool' object has no attribute 'get'
ERROR: Minions returned with non-zero exit code
This leads me to think the module doesn't like the shorthand logrotate configuration of stacking multiple files before the opening curly brace.
I believe my suspicions are confirmed by reviewing the output from the logrotate.show_conf function. You can see the output for the files not immediately before the curly brace.
Slightly redacted output, to remove any files not mentioned in /etc/logrotate.d/syslog-ng to make things clearer.
# salt 'COMPUTERNAME' logrotate.show_conf
COMPUTERNAME :
----------
...
/var/log/auth.log:
True
/var/log/cron.log:
True
/var/log/daemon.log:
True
/var/log/debug:
True
/var/log/error:
----------
compress:
True
delaycompress:
True
endscript:
True
invoke-rc.d:
syslog-ng reload > /dev/null
missingok:
True
notifempty:
True
postrotate:
True
rotate:
4
sharedscripts:
True
weekly:
True
/var/log/kern.log:
True
/var/log/lpr.log:
True
/var/log/mail.err:
True
/var/log/mail.info:
True
/var/log/mail.log:
True
/var/log/mail.warn:
True
/var/log/messages:
True
/var/log/syslog:
----------
compress:
True
daily:
True
delaycompress:
True
endscript:
True
invoke-rc.d:
syslog-ng reload > /dev/null
missingok:
True
notifempty:
True
postrotate:
True
rotate:
7
/var/log/user.log:
True
...
include:
/etc/logrotate.d
include files:
----------
...
syslog-ng:
- /var/log/syslog
- /var/log/mail.info
- /var/log/mail.warn
- /var/log/mail.err
- /var/log/mail.log
- /var/log/daemon.log
- /var/log/kern.log
- /var/log/auth.log
- /var/log/user.log
- /var/log/lpr.log
- /var/log/cron.log
- /var/log/debug
- /var/log/messages
- /var/log/error
...
rotate:
4
su:
root adm
weekly:
True
Expected behavior
Expected the module to return the logrotate configuration for any file configured in logrotate's config, not just the files which immediately proceed the opening curly brace.
Versions Report
salt --versions-report
Salt Version:
Salt: 3007.1
Python Version:
Python: 3.10.14 (main, Apr 3 2024, 21:30:09) [GCC 11.2.0]
Dependency Versions:
cffi: 1.16.0
cherrypy: 18.8.0
dateutil: 2.8.2
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 3.1.4
libgit2: Not Installed
looseversion: 1.3.0
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 1.0.7
msgpack-pure: Not Installed
mysql-python: Not Installed
packaging: 23.1
pycparser: 2.21
pycrypto: Not Installed
pycryptodome: 3.19.1
pygit2: Not Installed
python-gnupg: 0.5.2
PyYAML: 6.0.1
PyZMQ: 25.1.2
relenv: 0.16.0
smmap: Not Installed
timelib: 0.3.0
Tornado: 6.3.3
ZMQ: 4.3.4
Salt Package Information:
Package Type: onedir
System Versions:
dist: debian 12.7 bookworm
locale: utf-8
machine: x86_64
release: 6.1.0-26-amd64
system: Linux
version: Debian GNU/Linux 12.7 bookworm
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in salt/modules/logrotate.py, especially get, and reproduce the failure with a logrotate configuration that lists multiple files before the opening brace. Compare the parsed output from logrotate.show_conf for the grouped paths with the paths immediately before the brace. Done means logrotate.get returns the requested configuration for every file in the shorthand group without raising the AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100