SaltMaster is crippled with Minion Re-Authentication
I have been facing a problem with Salt Minions, where the minion fails to decrypt the payload on a salt master poll event; raises an exception, and then re-authenticates with the master.
This has the effect that CPU usage on the saltmaster is 100% utilised as almost all the minions are periodically re-authenticating on each and every command.
Chain of events:
1. minion gets a poll or command
2. decrypt fails
3. Minion re-authenticates
4. command fails or times out
5. minion gets a new command
6. Command2 succeeds
7. Goto 1
Here is the traceback:
2015-07-15 14:34:05,505 [salt.minion ][CRITICAL][18584] An exception occurred while polling the minion
Traceback (most recent call last):
File "/opt/blue-python/2.7/lib/python2.7/site-packages/salt/minion.py", line 1880, in tune_in
self._do_socket_recv(socks)
File "/opt/blue-python/2.7/lib/python2.7/site-packages/salt/minion.py", line 1975, in _do_socket_recv
self._handle_payload(payload)
File "/opt/blue-python/2.7/lib/python2.7/site-packages/salt/minion.py", line 1006, in _handle_payload
payload['sig'] if 'sig' in payload else None)
File "/opt/blue-python/2.7/lib/python2.7/site-packages/salt/minion.py", line 1025, in _handle_aes
data = self.crypticle.loads(load)
File "/opt/blue-python/2.7/lib/python2.7/site-packages/salt/crypt.py", line 841, in loads
data = self.decrypt(data)
File "/opt/blue-python/2.7/lib/python2.7/site-packages/salt/crypt.py", line 824, in decrypt
raise AuthenticationError('message authentication failed')
AuthenticationError: message authentication failed
Relevant code from minion.py
1008 def _handle_aes(self, load, sig=None):
1009 '''
1010 Takes the AES encrypted load, checks the signature if pub signatures
1011 are turned on, decrypts it, and runs the encapsulated instructions
1012 '''
1013 # Verify that the signature is valid
1014 master_pubkey_path = os.path.join(self.opts['pki_dir'], 'minion_master.pub')
1015
1016 if sig and self.functions['config.get']('sign_pub_messages'):
1017 if not salt.crypt.verify_signature(master_pubkey_path, load, sig):
1018 raise AuthenticationError('Message signature failed to validate.')
1019
1020 try:
1021 data = self.crypticle.loads(load)
1022 except AuthenticationError:
1023 # decryption of the payload failed, try to re-auth
1024 self.authenticate()
1025 data = self.crypticle.loads(load)
1026
1027 # Verify that the publication is valid
1028 if 'tgt' not in data or 'jid' not in data or 'fun' not in data \
1029 or 'arg' not in data:
Here are the versions we are running:
saltmaster$ sudo salt-call --versions
Salt: 2015.5.0
Python: 2.7.9 (default, Dec 30 2014, 13:07:54)
Jinja2: 2.7.3
M2Crypto: 0.22
msgpack-python: 0.4.6
msgpack-pure: Not Installed
pycrypto: 2.6.1
libnacl: Not Installed
PyYAML: 3.11
ioflo: Not Installed
PyZMQ: 14.7.0
RAET: Not Installed
ZMQ: 4.1.2
Mako: Not Installed
Tornado: 4.0.2
minion$$ sudo salt-call --versions
Salt: 2015.5.0
Python: 2.7.9 (default, Dec 30 2014, 13:07:54)
Jinja2: 2.7.3
M2Crypto: 0.22
msgpack-python: 0.4.2
msgpack-pure: Not Installed
pycrypto: 2.6.1
libnacl: Not Installed
PyYAML: 3.11
ioflo: Not Installed
PyZMQ: 14.7.0
RAET: Not Installed
ZMQ: 4.1.2
Mako: Not Installed
Tornado: Not Installed
Please feel free to ask for any information. This is a really big issue, making the salt system essentially useless.
@spo0nman, thanks for the report. Can you post your master and minion configs and also the debug logs of the master and minion when this happens?
Hi,
While looking for the data I requested, I noticed that the problem is not just that the minion that you run the command on re-auths. for every command I run on any given host, all the minions that are connected to the master do a re-auth.
for example, if i run a test.ping to hostname foo
Debug log on the minion:
2015-07-20 15:02:04,566 [salt.crypt ][DEBUG ][11809] Failed to authenticate message
2015-07-20 15:02:04,567 [salt.minion ][DEBUG ][11809] Attempting to authenticate with the Salt Master at 10.197.X.X
2015-07-20 15:02:04,567 [salt.crypt ][DEBUG ][11809] Re-using SAuth for ('/etc/salt/pki/minion', 'hostname', 'tcp://10.197.145.38:4506')
2015-07-20 15:02:04,772 [salt.crypt ][DEBUG ][11809] Decrypting the current master AES key
2015-07-20 15:02:04,773 [salt.crypt ][DEBUG ][11809] Loaded minion key: /etc/salt/pki/minion/minion.pem
2015-07-20 15:02:04,914 [salt.crypt ][DEBUG ][11809] Loaded minion key: /etc/salt/pki/minion/minion.pem
2015-07-20 15:02:04,955 [salt.minion ][INFO ][11809] User sudo_pkaushal Executing command test.ping with jid 20150720150235541887
2015-07-20 15:02:04,955 [salt.minion ][DEBUG ][11809] Command details {'tgt_type': 'glob', 'jid': '20150720150235541887', 'tgt': 'foo', 'ret': 'redis', 'to': 15, 'user': 'ssss', 'groups': ['users', 'sss', 'ss', 'cvs'], 'arg': [], 'fun': 'test.ping'}
2015-07-20 15:02:04,967 [salt.minion ][INFO ][17098] Starting a new job with PID 17098
2015-07-20 15:02:05,062 [salt.utils.lazy ][DEBUG ][17098] LazyLoaded test.ping
2015-07-20 15:02:05,063 [salt.minion ][INFO ][17098] Returning information for job: 20150720150235541887
Debug log on the master
Jul 20 15:02:04 [INFO ] Clear payload received with command _auth
Jul 20 15:02:04 [INFO ] Authentication request from fobbarbaz-01
Jul 20 15:02:04 [INFO ] Clear payload received with command _auth
Jul 20 15:02:04 [INFO ] Clear payload received with command _auth
Jul 20 15:02:04 [INFO ] Authentication accepted from fobbarbaz-02
Jul 20 15:02:04 [INFO ] Authentication request from fobbarbaz-03
Jul 20 15:02:04 [INFO ] Authentication request from fobbarbaz-04
Jul 20 15:02:04 [INFO ] Authentication request from fobbarbaz-05
Jul 20 15:02:04 [INFO ] Clear payload received with command _auth
Jul 20 15:02:04 [INFO ] Authentication request from fobbarbaz-32
Jul 20 15:02:04 [INFO ] Authentication request from fobbarbaz-31
Jul 20 15:02:04 [INFO ] Authentication accepted from fobbarbaz-23
Jul 20 15:02:04 [INFO ] Authentication accepted from fobbarbaz-43
Jul 20 15:02:04 [INFO ] Authentication accepted from fobbarbaz-24
Jul 20 15:02:04 [INFO ] Authentication accepted from fobbarbaz-55
Jul 20 15:02:04 [INFO ] Authentication accepted from fobbarbaz-52
Jul 20 15:02:04 [INFO ] Clear payload received with command _auth
Jul 20 15:02:04 [INFO ] Authentication request from fobbarbaz-51
Jul 20 15:02:04 [INFO ] Clear payload received with command _auth
Jul 20 15:02:04 [INFO ] Clear payload received with command _auth
Jul 20 15:02:04 [INFO ] Clear payload received with command _auth
Jul 20 15:02:04 [INFO ] Clear payload received with command _auth
... Thousands more lines like this
All the minions connected to the master do a re auth
$ grep ' 15:02' salt-master.debug.log | grep 'Authentication request' |wc -l
2057
$ sudo salt-key -L| wc -l
2488
master.conf
order_masters: True
max_open_files: 100000
worker_threads: 24
auto_accept: True
file_roots:
base:
- /srv/salt
- /var/cache/salt/minion/files/base
pillar_roots:
base:
- /srv/pillar
pillar_opts: False
token_expire: 3600
show_timeout: True
timeout: 15
log_level: warning
module_dirs:
- /srv/salt/_modules
runner_dirs:
- /srv/salt/runner
extension_modules: /srv/salt/modules
keep_jobs: 1
con_cache: True
master_sign_pubkey: False
master_use_pubkey_signature: False
sudo_acl: True
extension_modules: /srv/salt/modules
ext_job_cache:
Minion.conf
id: hostname
master: saltmaster
file_roots:
base:
- /srv/salt
pillar_roots:
base:
- /srv/pillar
log_level: info
module_dirs:
- /srv/salt/_modules
grains_refresh_every: 10
grains_cache: True
grains_cache_expiration: 300
ret_port: 4506
publish_port: 4505
# testing caching jobs locally on minions
cache_jobs: True
verify_master_pubkey_sign: False
recon_default: 1000
recon_max: 59000
recon_randomize: True
acceptance_wait_time: 90
random_reauth_delay: 60
auth_timeout: 60
@spo0nman, that is very strange. Some obvious things to try if you have the time: creating a test environment with a single master and a single minion, vanilla configs, upgrading to 2015.5.3 or 2015.8.0rc1.
I see that you have order_masters: True in your master config. Could you also post your syndic config if you are using that as well? Are all the problem minions going through syndics? Are all minions going through syndics? Thanks.
@jfindlay Thanks for looking into this. The syndic config is not too fancy. However, I see the problem if I run the command either from the saltmaster or master of masters, so I guess it couldn't be syndic.
syndic.conf
syndic_master: saltmaster
syndic_master_port: 4506
syndic_log_file: /var/log/salt/syndic
syndic_pidfile: /var/run/salt-syndic.pid
I have done some digging and I think found the root cause. This was probably happening because salt-key -D rotates the AES key and we were aggressively running this command to get rid of the dead minions.
@spo0nman, that makes sense. Were you able to find a salt-key -D time interval that works? Do you consider this issue resolved? Can we improve the documentation? It seems that this is an exceptional case, but documentation might help someone else.
Yes. The issue is resolved once salt-key -D is run less frequently.
To clarify; we were running cleanups (salt-key -D cron jobs) with an interval of minutes in an environment with thousands of minions. This caused crippling auth floods.
salt-key has an option called --rotate-aes-key=ROTATE_AES_KEY. This may reduce the auth floods, but be certain that you understand the security implications of using this option before doing so.
We should probably add some documentation about salt master scalability concerns and advice if we don't have something like this already.
http://docs.saltstack.com/en/latest/topics/tutorials/intro_scale.html
With #25856 created, I am going to consider this issue closed. Thank you for tracking this down, @spo0nman and @wimtie.
Thankyou guys.