[SALT] Can't import salt state

Problem:
Hello I have installed a fresh foreman following the documentation.

When I arrive to the step “import states” I have an error :
Screenshot 2023-08-16 at 15-17-31 Salt States

On the /var/log/salt/api logs I have this :

2023-08-16 14:59:11,021 [cherrypy.error   :213 ][ERROR   ][49282] [16/Aug/2023:14:59:11] ENGINE Error in 'start' listener <bound method Server.start of <cherrypy._cpserver.Server object at 0x7fbba019ad10>>
Traceback (most recent call last):
  File "/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/process/wspbus.py", line 230, in publish
    output.append(listener(*args, **kwargs))
  File "/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/_cpserver.py", line 179, in start
    self.httpserver, self.bind_addr = self.httpserver_from_self()
  File "/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/_cpserver.py", line 170, in httpserver_from_self
    httpserver = _cpwsgi_server.CPWSGIServer(self)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/_cpwsgi_server.py", line 99, in __init__
    self.ssl_adapter = adapter_class(
  File "/opt/saltstack/salt/lib/python3.10/site-packages/cheroot/ssl/builtin.py", line 226, in __init__
    self.context.load_cert_chain(certificate, private_key)
PermissionError: [Errno 13] Permission denied

2023-08-16 14:59:11,021 [cherrypy.error   :213 ][ERROR   ][49282] [16/Aug/2023:14:59:11] ENGINE Shutting down due to error in start listener:
Traceback (most recent call last):
  File "/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/process/wspbus.py", line 268, in start
    self.publish('start')
  File "/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/process/wspbus.py", line 248, in publish
    raise exc
cherrypy.process.wspbus.ChannelFailures: PermissionError(13, 'Permission denied')

On the /var/log/foreman-proxy/proxy.log I have this :

023-08-16T15:24:51 381c186e [I] Started GET /salt/environments 
2023-08-16T15:24:51 ec3b87f6 [I] Started POST /run 
2023-08-16T15:24:51 ec3b87f6 [I] Finished POST /run with 404 (0.41 ms)
2023-08-16T15:24:51 381c186e [E] Failed to list environments: Received 404 from Salt API: Requested url was not found
2023-08-16T15:24:51 381c186e [W] Error details for Failed to list environments: Received 404 from Salt API: Requested url was not found: <Exception>: Failed to list environments: Received 404 from Salt API: Requested url was not found
2023-08-16T15:24:51 381c186e [W] Failed to list environments: Received 404 from Salt API: Requested url was not found: <Exception>: Failed to list environments: Received 404 from Salt API: Requested url was not found
2023-08-16T15:24:51 381c186e [I] Finished GET /salt/environments with 406 (9.31 ms)

I have set en environment in the web UI.
I have created a state in /srv/salt (I have tried with owner root or saltuser, same error)

Expected outcome:

I expected to see my states imported in foreman.

Foreman and Proxy versions:

I use foreman 3.8.0 (Nightly)

Foreman and Proxy plugin versions:

Salt 5.0.1
foreman_salt 15.2.1

Distribution and version:

CentOS 8

Other relevant data:

Maybe related, if I register a host using “register host” it doesn’t install nor configure salt on the minion.
Also I can’t approve the minion via the foreman, I have to run salt-key to list and accept the server.


what files do you need to see to troubleshot my problem ?

Solved,

salt-master and salt-api MUST run as root user when using external auth (and also for reading certificates).

This can be done in /etc/salt/master , uncomment line user: root