Bug #32832
openHost auto provisioning allows an existing host to be inserted again
Description
Hello,
We are operating a foreman instance with a few thousand hosts and relying on puppet/foreman for automation.
We observe a rare and seemingly extremely random behavior where puppet masters end up (once every few months or so) pushing for a single host strange facts to foreman. That triggers a "re-subscribe" of the host with mostly the same characteristics.
We are aware of the "Create new hosts when facts are uploaded" option and we have set it to "no" following this investigation.
However, we believe that in any case, allowing an existing host to be "re-entered" in the database on top of an existing record creates a very dangerous and unpredictable behavior especially considering that foreman is a pivot for the automation stack (values fed for puppet for example will depend on which entry will be returned by queries on the hosts table out of the two present values).
As such, I would propose either:
1/ enforcing unicity on the column name (that contains the FQDN) in the host table in order to maintain consistency no matter what (dynamic recording or not) directly in the database as such:
CREATE UNIQUE INDEX host_name_unique_idx ON hosts(name);
2/ alternatively ensure that the automatic registration/creation of hosts is validating unicity even when automatically called on new facts or reports creation.
Best Regards,
-Jean