Actions
Bug #10366
openForeman allows to create invalid hosts upon facts upload
Status:
New
Priority:
Normal
Assignee:
-
Category:
Facts
Target version:
-
Description
I just saw following scenario:
- User creates a new host a.example.com with IP 192.168.0.1
- Provisioning setups puppet on this host, so puppet uploads facts to Foreman
- Unfortunately the host hostname is different than user created (e.g. b.example.net) so it gets successfully created in Foreman
- User tries to edit a.example.com but he sees validation error that IP address is already taken, which is true because b.example.net has the very same IP
When organizations are in use it's even more complicated to find out the reason, because newly created hosts ends up in global context by default so the user does not see conflicting host. DNS orchestration seems to be set correctly. While the DNS misconfiguration might not be Foreman issue, the bug is that Foreman does not run validations when saving the host. This makes DB in inconsistent state. During fixing this maybe we could refactor multiple save calls during one action, one ought to be enough for anybody. The hostname resolution issue seems to be caused by wrong DHCP configuration that sets the provisioned host domain to example.net instead of example.com.
Saves that should be fixed:- https://github.com/theforeman/foreman/blob/develop/app/models/host/base.rb#L121
- https://github.com/theforeman/foreman/blob/develop/app/models/host/base.rb#L130
- https://github.com/theforeman/foreman/blob/develop/app/models/host/managed.rb#L418
- https://github.com/theforeman/foreman/blob/develop/app/models/host/managed.rb#L435
Actions