ForbiddenAttributesError using hammer salt-minion update

Hi,

I have been playing with foreman-salt on my test instance and I believe I
have worked through most of the issues. However, the hammer salt-minion
update is not working for me. I included the relevant parts of the hammer
–debug and the /var/log/foreman/production.log. However, I can edit salt
states using the web interface. Also, I get the same error when I try to
do salt-minon update for the environment or the proxy id.

My questions are:

  1. Has anyone used tfm-rubygem-hammer_cli_foreman_salt 0.0.5 with foreman
    1.13.1 and tfm-rubygem-foreman_salt 7.0.0?

  2. Looking at the foreman_salt route.rb I can see a
    foreman_salt/api/v2/salt_minions controller defined. However the API
    mentioned below does not have a version number. Is that part of the issue?

  3. Does anyone have any suggestions on how to debug this issue?

  4. Is there a way to set salt master, environment, and state for hostgroups
    using hammer?

Thanks,
David

$ hammer --debug salt-minion update --id 6 --salt-states logs.server

[ INFO 2016-11-04 20:45:01 API] Server: https://test6.rexden.us
[ INFO 2016-11-04 20:45:01 API] PUT /salt/api/salt_minions/6
[DEBUG 2016-11-04 20:45:01 API] Params: {
"minion" => {
"salt_state_ids" => [
[0] 45
]
}
}
[DEBUG 2016-11-04 20:45:01 API] Headers: {}
[ERROR 2016-11-04 20:45:01 API] 500 Internal Server Error
[DEBUG 2016-11-04 20:45:01 API] {
"error" => {
"message" => "ActiveModel::ForbiddenAttributesError"
}
}

/var/log/foreman/production.log:

2016-11-04 21:32:46 2057d144 [app] [I] Started PUT
"/salt/api/salt_minions/6" for 192.168.8.236 at 2016-11-04
21:32:46 -0400
2016-11-04 21:32:46 2057d144 [app] [I] Processing by
ForemanSalt::Api::V2::SaltMinionsController#update as JSON
2016-11-04 21:32:46 2057d144 [app] [I] Parameters:
{"minion"=>{"salt_state_ids"=>[45]}, "apiv"=>"v2", "id"=>"6",
"salt_minion"=>{"minion"=>{"salt_state_ids"=>[45]}}}
2016-11-04 21:32:46 2057d144 [app] [I] Authorized user admin(Admin User)
2016-11-04 21:32:46 2057d144 [app] [W] Action failed
> ActiveModel::ForbiddenAttributesError:
ActiveModel::ForbiddenAttributesError
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activemodel-4.2.5.1/lib/active_model/forbidden_attributes_protection.rb:21:in
sanitize_for_mass_assignment' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:33:inassign_attributes'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/persistence.rb:251:in
block in update' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:351:inblock in with_transaction_returning_status'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
block in transaction' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/transaction.rb:184:inwithin_new_transaction'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
transaction' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:220:intransaction'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:348:in
with_transaction_returning_status' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/persistence.rb:250:inupdate'
>
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_salt-7.0.0/app/controllers/foreman_salt/api/v2/salt_minions_controller.rb:32:in
update' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/actionpack-4.2.5.1/lib/action_controller/metal/implicit_render.rb:4:insend_action'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/actionpack-4.2.5.1/lib/abstract_controller/base.rb:198:in
process_action' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/actionpack-4.2.5.1/lib/action_controller/metal/rendering.rb:10:inprocess_action'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/actionpack-4.2.5.1/lib/abstract_controller/callbacks.rb:20:in
block in process_action' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:117:incall'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:117:in
call' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:555:inblock (2 levels) in compile'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:in
call' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:incall'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:498:in
block (2 levels) in around' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:313:incall'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:313:in
block (2 levels) in halting' > /usr/share/foreman/app/controllers/api/v2/base_controller.rb:152:indisable_json_root'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:432:in
block in make_lambda' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:312:incall'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:312:in
block in halting' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:497:incall'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:497:in
block in around' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:incall'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:in
call' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:498:inblock (2 levels) in around'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:313:in
call' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:313:inblock (2 levels) in halting'
>
/opt/theforeman/tfm/root/usr/share/gems/gems/rails-observers-0.1.2/lib/rails/observers/action_controller/caching/sweeping.rb:73:in
around' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:455:inpublic_send'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:455:in
block in make_lambda' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:312:incall'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:312:in
block in halting' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:497:incall'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:497:in
block in around' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:incall'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:in
call' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:498:inblock (2 levels) in around'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:313:in
call' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:313:inblock (2 levels) in halting'
> /usr/share/foreman/app/controllers/concerns/application_shared.rb:14:in
set_timezone' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:432:inblock in make_lambda'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:312:in
call' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:312:inblock in halting'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:497:in
call' > /opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:497:inblock in around'
>
/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:in
`call'

> From: "David King" <david@rexden.us>
> To: foreman-users@googlegroups.com
> Sent: Friday, November 4, 2016 9:37:42 PM
> Subject: [foreman-users] ForbiddenAttributesError using hammer salt-minion update
>
> Hi,
>
> I have been playing with foreman-salt on my test instance and I believe I
> have worked through most of the issues. However, the hammer salt-minion
> update is not working for me. I included the relevant parts of the hammer
> --debug and the /var/log/foreman/production.log. However, I can edit salt
> states using the web interface. Also, I get the same error when I try to
> do salt-minon update for the environment or the proxy id.
>
> My questions are:
>
> 1) Has anyone used tfm-rubygem-hammer_cli_foreman_salt 0.0.5 with foreman
> 1.13.1 and tfm-rubygem-foreman_salt 7.0.0?
>
> 2) Looking at the foreman_salt route.rb I can see a
> foreman_salt/api/v2/salt_minions controller defined. However the API
> mentioned below does not have a version number. Is that part of the issue?

No, the error you're getting is because of Foreman's move to strong parameters.

We added support to foreman_salt in http://projects.theforeman.org/issues/15958.

For some reason it's not working with the salt minions controller. That itself is
because Foreman doesn't allow extension of API controllers.

We do correctly tell Foreman that you can edit salt module id's on a host:
https://github.com/theforeman/foreman_salt/commit/a3e870b7c4db54b7fd6b52eba9d28007c0fb7263#diff-895994c8f6033bd4f9f9a19756790b6bR139

But it's not working.

If you know Rails that might help pinpoint the problem, otherwise I'd
appreciate if you'd file a bug here so we can track it:
http://projects.theforeman.org/projects/salt/issues/new

> 3) Does anyone have any suggestions on how to debug this issue?
>
> 4) Is there a way to set salt master, environment, and state for hostgroups
> using hammer?

Foreman doesn't allow extension of it's API's so I don't think this is really
possible unless we created some special salt host group endpoint, like we
did for minions and that itself seems to be pretty fragile.

··· ----- Original Message -----

Thanks,
David

$ hammer --debug salt-minion update --id 6 --salt-states logs.server

[ INFO 2016-11-04 20:45:01 API] Server: https://test6.rexden.us
[ INFO 2016-11-04 20:45:01 API] PUT /salt/api/salt_minions/6
[DEBUG 2016-11-04 20:45:01 API] Params: {
“minion” => {
“salt_state_ids” => [
[0] 45
]
}
}
[DEBUG 2016-11-04 20:45:01 API] Headers: {}
[ERROR 2016-11-04 20:45:01 API] 500 Internal Server Error
[DEBUG 2016-11-04 20:45:01 API] {
“error” => {
“message” => “ActiveModel::ForbiddenAttributesError”
}
}

/var/log/foreman/production.log:

2016-11-04 21:32:46 2057d144 [app] [I] Started PUT
“/salt/api/salt_minions/6” for 192.168.8.236 at 2016-11-04
21:32:46 -0400
2016-11-04 21:32:46 2057d144 [app] [I] Processing by
ForemanSalt::Api::V2::SaltMinionsController#update as JSON
2016-11-04 21:32:46 2057d144 [app] [I] Parameters:
{“minion”=>{“salt_state_ids”=>[45]}, “apiv”=>“v2”, “id”=>“6”,
“salt_minion”=>{“minion”=>{“salt_state_ids”=>[45]}}}
2016-11-04 21:32:46 2057d144 [app] [I] Authorized user admin(Admin User)
2016-11-04 21:32:46 2057d144 [app] [W] Action failed

ActiveModel::ForbiddenAttributesError:
ActiveModel::ForbiddenAttributesError

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activemodel-4.2.5.1/lib/active_model/forbidden_attributes_protection.rb:21:in
`sanitize_for_mass_assignment’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:33:in
`assign_attributes’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/persistence.rb:251:in
`block in update’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:351:in
`block in with_transaction_returning_status’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
`block in transaction’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/transaction.rb:184:in
`within_new_transaction’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
`transaction’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:220:in
`transaction’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:348:in
`with_transaction_returning_status’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activerecord-4.2.5.1/lib/active_record/persistence.rb:250:in
`update’

/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_salt-7.0.0/app/controllers/foreman_salt/api/v2/salt_minions_controller.rb:32:in
`update’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/actionpack-4.2.5.1/lib/action_controller/metal/implicit_render.rb:4:in
`send_action’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/actionpack-4.2.5.1/lib/abstract_controller/base.rb:198:in
`process_action’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/actionpack-4.2.5.1/lib/action_controller/metal/rendering.rb:10:in
`process_action’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/actionpack-4.2.5.1/lib/abstract_controller/callbacks.rb:20:in
`block in process_action’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:117:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:117:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:555:in
`block (2 levels) in compile’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:498:in
`block (2 levels) in around’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:313:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:313:in
`block (2 levels) in halting’

/usr/share/foreman/app/controllers/api/v2/base_controller.rb:152:in
`disable_json_root’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:432:in
`block in make_lambda’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:312:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:312:in
`block in halting’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:497:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:497:in
`block in around’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:498:in
`block (2 levels) in around’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:313:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:313:in
`block (2 levels) in halting’

/opt/theforeman/tfm/root/usr/share/gems/gems/rails-observers-0.1.2/lib/rails/observers/action_controller/caching/sweeping.rb:73:in
`around’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:455:in
`public_send’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:455:in
`block in make_lambda’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:312:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:312:in
`block in halting’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:497:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:497:in
`block in around’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:498:in
`block (2 levels) in around’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:313:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:313:in
`block (2 levels) in halting’

/usr/share/foreman/app/controllers/concerns/application_shared.rb:14:in
`set_timezone’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:432:in
`block in make_lambda’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:312:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:312:in
`block in halting’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:497:in
`call’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:497:in
`block in around’

/opt/rh/sclo-ror42/root/usr/share/gems/gems/activesupport-4.2.5.1/lib/active_support/callbacks.rb:505:in
`call’


You received this message because you are subscribed to the Google Groups
“Foreman users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.