Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1464137 - API - non-admin user can't create entities within org and loc he belongs to
Summary: API - non-admin user can't create entities within org and loc he belongs to
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Organizations and Locations
Version: 6.3.0
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: Unspecified
Assignee: Marek Hulan
QA Contact: Sanket Jagtap
URL:
Whiteboard:
: 1462388 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-06-22 13:45 UTC by Stanislav Tkachenko
Modified: 2021-06-10 12:29 UTC (History)
8 users (show)

Fixed In Version: foreman-1.16.0
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-02-21 16:54:17 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 20165 0 Normal Closed API - non-admin user can't create entities within org and loc he belongs to 2020-06-11 16:35:08 UTC

Description Stanislav Tkachenko 2017-06-22 13:45:39 UTC
Description of problem:
Newly created non-admin user with create permissions can't create entity within organization and location he belongs to (in example below it is Subnet and 'create_subnets'). Other entities affected as well (tested with Subnet, Host and Domain).

> Making HTTP POST request to https://sat6.com/api/v2/users with options... and data {"user": {..., "location_ids": [491], "organization_ids": [490]}}.

> Received HTTP 201 response: {"default_location":null,"locations":[{"id":491,"name":"OgyTrUojzLM","title":"OgyTrUojzLM","description":null}],"default_organization":null,"organizations":[{"id":490,"name":"hfspaJbBY","title":"hfspaJbBY","description":null}],...}

> Making HTTP POST request to https://sat6.com/api/v2/subnets with options ... and data {"subnet": {..., "location_ids": [491], "organization_ids": [490]}}.

> Received HTTP 422 response: {
>  "error": {"id":null,"errors":{"organization_ids":["Invalid organizations selection, you must select at least one of yours"],"location_ids":["Invalid locations selection, you must select at least one of yours"]},"full_messages":["Organization ids Invalid organizations selection, you must select at least one of yours","Location ids Invalid locations selection, you must select at least one of yours"]}

Version-Release number of selected component (if applicable):
Satellite 6.3 Snap 3.0:
* satellite-6.3.0-15.0.beta.el7sat.noarch
* foreman-1.15.0-1.el7sat.noarch
* katello-3.4.1-1.el7sat.noarch

How reproducible:
Always

Steps to Reproduce:
1. Create non-admin user with org and loc and grant create permissions (e.g. create_domains)
2. Try to create entity (e.g. Domain)
3. Check whether it was created or error is raised

Actual results:
422 error

Expected results:
Entity should be created

Additional info:

Comment 2 Marek Hulan 2017-06-26 11:43:24 UTC
Could you please provide the full reproducer? Ideally curl/wget commands you're using ideally also for user creation and permission setup. I can't reproduce the behavior.

Following hammer commands did the trick for me

    hammer user create --login orgtest --mail ares --password changeme --organization-ids 1 --location-ids 2 --auth-source-id 1

    hammer user add-role --login orgtest --role Manager

    hammer -u orgtest -p changeme subnet create --organization-ids 1 --location-ids 2 --name Test --network 192.168.0.1 --mask 255.255.255.0

Also please list all roles and their configuration that the user is assigned.

Comment 5 Marek Hulan 2017-06-28 15:01:54 UTC
Thanks Stanislav, now I see what's going on. Your user does not have permissions "assign_location" and "assign_organization" which are required to create resources assigned to orgs and locs. I think the validation message could be more descriptive, e.g. 'Organization ids Invalid organizations selection, you must select at least one of yours for which you have permission to `assign_organization`'. Would that be a good solution? Also if you agree, I think this is not a 6.3 blocker so I'd move it to sat-backlog even though I'd provide the fix right away.

Comment 7 Stanislav Tkachenko 2017-06-29 05:15:45 UTC
(In reply to Marek Hulan from comment #5)
I've checked with additional permissions, now tests are passing :)

> I think the validation
> message could be more descriptive, e.g. 'Organization ids Invalid
> organizations selection, you must select at least one of yours for which you
> have permission to `assign_organization`'. Would that be a good solution?
Yes, more descriptive message would be great.

> Also if you agree, I think this is not a 6.3 blocker so I'd move it to
> sat-backlog even though I'd provide the fix right away.
Agree.

Comment 8 Marek Hulan 2017-06-29 13:31:07 UTC
Created redmine issue http://projects.theforeman.org/issues/20165 from this bug

Comment 9 Satellite Program 2017-06-29 14:14:51 UTC
Upstream bug assigned to mhulan

Comment 10 Satellite Program 2017-06-29 14:14:54 UTC
Upstream bug assigned to mhulan

Comment 11 Marek Hulan 2017-06-30 14:00:28 UTC
*** Bug 1462388 has been marked as a duplicate of this bug. ***

Comment 12 Satellite Program 2017-06-30 18:14:41 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/20165 has been resolved.

Comment 13 Sanket Jagtap 2017-12-01 07:22:03 UTC
Build: Satellite 6.3.0 snap 26

Using the reproducer steps

The new error generated is more detailed and the require permission are display in error 

curl -s -H "Content-Type: application/json" -H "Accept:application/json" -k -u "apple:apple" -X POST -d '{"domain": {"name": "apple", "location_ids": [8], "organization_ids": [7]}}'  https://sathost/api/v2/domains
{
  "error": {"id":null,"errors":{"organization_ids":["Invalid organizations selection, you must select at least one of yours and have 'assign_organizations' permission."],"location_ids":["Invalid locations selection, you must select at least one of yours and have 'assign_locations' permission."]},"full_messages":["Organization ids Invalid organizations selection, you must select at least one of yours and have 'assign_organizations' permission.","Location ids Invalid locations selection, you must select at least one of yours and have 'assign_locations' permission."]}
}

Comment 14 Satellite Program 2018-02-21 16:54:17 UTC
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA.
> 
> For information on the advisory, and where to find the updated files, follow the link below.
> 
> If the solution does not work for you, open a new bug report.
> 
> https://access.redhat.com/errata/RHSA-2018:0336


Note You need to log in before you can comment on or make changes to this bug.