-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #36273 - Use proper permission for editing Ansible variable #633
Fixes #36273 - Use proper permission for editing Ansible variable #633
Conversation
Hey @pmoravec, I agree with the change you made in this PR. However, the fix only applies to the API. We also need to address the problem in the web UI. |
That's true, there are two other places where arguably wrong permission (
I'd be willing to let this slide. We can reason whether the permission used is the right one or not, but the whole authorization framework is thoroughly tested in Foreman itself. |
I see. Sadly I dont have bandwidth to complete the fix as requested - please let somebody else adds a fix for WebUI "variant" and add some tests. |
1fa573b
to
c6850cd
Compare
Agree on that it should be using foreman_ansible/lib/foreman_ansible/register.rb Lines 119 to 124 in 5b44890
The only thing that bothers me, I didn't find any defined permissions on LookupValue model in Foreman itself :/ |
I see the LookupValue is defined in foreman core. Would it solve the issue if I add the permissions for the LookupValue resource there? |
It should 🤷 |
c6850cd
to
9ddbe72
Compare
How to test:
Note:
|
The tests are not passing due to the dependency on the merge of theforeman/foreman#9803. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @nofaralfasi and @pmoravec, can be merged once theforeman/foreman#9803 is in.
9ddbe72
to
8dfedc2
Compare
In my opinion, it seems necessary to include the lookup_values permissions (view, create, edit and destroy) in the |
8dfedc2
to
99e68de
Compare
lib/foreman_ansible/register.rb
Outdated
permission :view_lookup_values, {}, :resource_type => 'LookupValue' | ||
permission :create_lookup_values, {}, :resource_type => 'LookupValue' | ||
permission :edit_lookup_values, {}, :resource_type => 'LookupValue' | ||
permission :destroy_lookup_values, {}, :resource_type => 'LookupValue' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? I mean, I've removed those lines and it still works...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you first remove these permissions from the DB?
From the rails console: Permission.where("name LIKE '%_lookup_values%'").destroy_all
And then re-run the rails server to test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done this and it looks... not quite good.
I've destroyed permissions, but we still need to create them, to use here. Thus, I needed to run db:seed
to re-create them (we have defined them in core), but due to Ansible plugin needing these perms to create ARM role, it failed. Thus, after I removed Ansible plugin from loading, I've re-created the permissions, then enabled the plugin and run the server. I was able to change variable values even without this block.
I mean, we already create these perms in the core, why would we try to re-create them here? Seems weird. I've checked what we do with e.g. create_job_invocations
, since this permission is used for ARM role as well: it seems REX plugin creates it and Ansible plugin then simply uses it to define a role. As you can see, Ansible plugin doesn't call permission :create_job_invocations
, which is right.
Since I'm not so well familiar with the internals of permission logic, @adamruzicka, maybe you can help us out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot I need to make a change in the db/seeds.d/020-permissions_list.rb
file for the db:seed
command to include that file. That's why it didn't work as expected for me.
Therefore, as long as we run the db:seed
command, there's no requirement to additionally include these permissions in the register.rb
file, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷 that's what I hoped for...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we shouldn't redefine permissions. Let's get rid of it, it seemed to work for me when I did it locally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the test failures now show what I was facing as well :/ Not sure why it complains about perms that are being created in DB by Foreman itself, isn't here some issues with load ordering?
99e68de
to
54b8e3f
Compare
54b8e3f
to
ee61573
Compare
Add LookupValue permissions to allow editing of Ansible variables, for non-admin users. Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
ee61573
to
6b73038
Compare
Requires: