Organization admin cannot provision discovered hosts

Hello,
Faced this issue.
User has multiple organizations and has admin rights to some of them.
I can’t provisioned discovered machines with this error:
2018-06-08 17:40:06 ef49230f [app] [E] Auto provisioning failed: Owner There is no owner with id 1 and type User
2018-06-08 17:40:06 ef49230f [app] [W] Failed to auto provision host host.example.com

Host owner is empty in settings:
host_owner | | Default owner on provisioned hosts, if empty Foreman will use current user

If I grant admin rights to my user I’m able to provision discovered machines.
Other functionality work as expected.

Any thoughts?

Thanks

Can you create a dummy host with this user and assign it the same hostgroup?

Discovery does not set owner, only taxonomy.

It appears if at least one host discovered in Foreman I can’t create hosts either unless user has full admin rights. I opened. Bug on this.
If I delete discovered host I can create unattended host

The issues seems to be caused by the fact a host owner is set to user with id 1, IIRC that’s default admin, based on your first Foreman version it’s either internal admin or admin account. The org admin probably can’t see this user and hence it thinks the discovered host has invalid owner and it prevents the update. I’m not sure what options are there in discovery to properly set the host owner, but if there’s a way to have some user group that user can see as a default owner for newly discovered hosts, it should help.

1 Like

Yeah it looks like all discovered hosts are currently “owned” by user no 1. No way of setting this. If we need to set it, the question is how. It’s currently not very transparent how we set taxonomy (explicitly, by setting or by subnet). Perhaps we need new flag for subnet - discovered hosts default owner?

Def user in settings - current user.
I just installed a fresh install and see the same error.
Easy to reproduce per steps above.
I was able to fix this by commenting out this line in this file:
app/models/concerns/hostext/ownership.rb

def set_default_user
  #return if self.owner_type.present? && (!OWNER_TYPES.include?(self.owner_type) || self.owner.nil?)
  self.owner = owner_suggestion
end

Even though another problems persists related to host creation by non admin user when at least one host is discovered, it comes from this file: /usr/share/foreman/app/services/authorizer_cache.rb, As far as I understand some roles caches not found.

https://projects.theforeman.org/issues/23869