Salt state import crashes completely if non-ascii-environments are present

Problem:
The state import routine queries a proxy for all available environments, which when read from git-branches could contain non-ascii-characters (which are perfectly valid in git, and also salt understands these).
These environment names are then used to craft internal URLs and fail the ASCII checks, which in turn aborts the whole process. (Which is understandable, but very inconvenient)
The presence of a single non-conformant git-branch thus prevents any state imports or env updates until the incriminating branch is renamed/deleted.

Expected outcome:

States for valid environments can still be imported, invalid env names will be ignored (but maybe reported on the import page.)

Foreman and Proxy versions:

3.10

Foreman and Proxy plugin versions:

3.10

Distribution and version:

AlmaLinux 9.4

Other relevant data:

production.log

2024-06-18T08:50:39 [I|app|1d1d4223] Backtrace for 'ProxyAPI operation FAILED' error (ProxyAPI::ProxyException): ERF12-4701 [ProxyAPI::ProxyException]: Unable to fetch Salt states list ([URI::InvalidURIError]: URI must be ascii only "https://myforeman:9090/salt/environments/branch-f\u00FCr-support") for proxy https://myforeman:9090/salt/
 1d1d4223 | /usr/share/gems/gems/foreman_salt-16.0.2/app/lib/proxy_api/salt.rb:57:in `rescue in states_list'
 1d1d4223 | /usr/share/gems/gems/foreman_salt-16.0.2/app/lib/proxy_api/salt.rb:48:in `states_list'
 1d1d4223 | /usr/share/gems/gems/foreman_salt-16.0.2/app/controllers/foreman_salt/state_importer.rb:16:in `fetch_states_from_proxy'
 1d1d4223 | /usr/share/gems/gems/foreman_salt-16.0.2/app/controllers/foreman_salt/salt_modules_controller.rb:61:in `import'
 1d1d4223 | /usr/share/gems/gems/actionpack-6.1.7.7/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'

So, seems like a patch here foreman_salt/app/lib/proxy_api/salt.rb at 8fac27fa84affd4a6ec98c29344dedb7a3a38520 · theforeman/foreman_salt · GitHub could filter all non-conforming environments and resolve this.
How would I do that? (having very limited experience with ruby and Foreman’s internals … but would be willing to give it a shot)

Can you try the patch from escape the environment name, as it can contain non-ASCII characters by evgeni · Pull Request #203 · theforeman/foreman_salt · GitHub?
It should apply cleanly to /usr/share/gems/gems/foreman_salt-16.0.2/app/lib/proxy_api/salt.rb

You can also use the Packit build by doing dnf copr enable packit/theforeman-foreman_salt-203 rhel-9-x86_64 followed by a dnf upgrade rubygem-foreman_salt. (In retrospect, the packit build might not work on 3.10, so the patch is safer)

In both cases you have to restart foreman afterwards (systemctl restart foreman) and then see if the import works.

CC @nadjaheitmann as the Foreman Salt maintainer

1 Like

Thanks @evgeni ! I had that one on my list but got distracted, so very happy that you already had a look at this.

1 Like

Guys you are amazing!
Thanks for the speedy responses and hard work, again!
Patch confirmed to be working, state import no longer crashes (if non-ascii-environments are simply ignored, that is).

1 Like