You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Upstream domain-scoping for the domain list API to OpenStack #446
CommunityIssues or pull requests relevant for SIG CommunityIAMIssues or pull requests relevant for SIG IAMIaaSIssues or pull requests relevant for Team1: IaaSSCS-VP10Related to tender lot SCS-VP10enhancementNew feature or request
To prevent the identity of customers/tenants getting exposed to each other, as a SCS provider I want my users with the "domain-manager" role to only see the domain they are authenticated in being listed when they use Keystone's domain list API.
A patch that provides proper domain scoping for this endpoint should be upstreamed.
Background:
Some OpenStackClient and OpenStack SDK functions use the list_domains API to discover domain names by id and vice-versa. In order for the domain-manager role to function properly, access to this API is necessary (they need to be able to resolve domains when creating domain-soped IDM resources such as users, projects etc.). However, in its current implementation, OpenStack Keystone will return a list of all existing domains via its API with no ability to limit the list to the authenticated domain only using RBAC policies.
I'm copy-and-pasting here what I've documented in the original ticket regarding the lack of proper domain-scoping of list_domains.
When a command specifying an object per name is used, e.g. the domain in "openstack user create --domain my-domain ..." then openstackclient will attempt to resolve the domain name into the domain ID by internally retrieving the domain list via "GET /v3/domains?name=my-domain" before attempting to create the user object. That means, that even if the domain admin only needs their own domain, they need access to the domain list API to resolve the name to ID of their very own domain.
The same goes for the roles API: resolving a role name to ID is done via the roles list API in the client.
For "openstack project list" there is proper domain-scoping implemented:
"identity:list_projects": "(rule:is_domain_admin and token.domain.id:%(target.domain_id)s) or rule:admin_required"
This policy does not work for domains:
"identity:list_domains": "(rule:is_domain_admin and token.domain.id:%(target.domain.id)s) or rule:admin_required"
and leads to the following error upon "openstack domain list":
You are not authorized to perform the requested action: identity:list_domains. (HTTP 403) (Request-ID: req-224b577d-c428-4720-a03e-cb195471afba)
This is why the policy has to be configured to allow domain admins to list all domains in order to enable them to manage user, projects and role assignments within their domain properly.
Deep-dive analysis of domain scoping for other identity:list_* APIs
To understand how other API endpoints such as identity:list_groups or identity:list_projects implement domain scoping, I had a closer look at the implementation, its behavior and purpose.
Part A is actually not contributing to the filtering at all.
The core of the filtering is part B.
The self.oslo_context object stores information about the authentication of the user making the request, i.e. the scope of the Keystone token. This includes information like in which project or domain the user is authenticated in and with what role.
So part B is checking whether the user is authenticated in a domain-scoped fashion and if so, the result list of projects will be filtered for projects that match this domain.
Thus, the returned project list only contains projects from the same domain as the user.
If an administrator authenticated in system-scope makes the same request, the else branch of part B will trigger since there is no domain scope in the self.oslo_context object and the returned list will contain all projects instead.
Now for part A. The purpose of this part is not obvious at first.
The enforce_call() will check the Keystone policy definition (identity:list_projects in this case) against the authenticated user and will make the RBAC check if the user is allowed to execute this action.
When writing RBAC rules for the policy.yaml of an OpenStack component, the author can usually access attributes of the target resource. For example the policy rule:
... would check if the API response being targeted contains a project object whose name attribute matches "special-project" and only allows the request if that is the case. For this purpose, the Keystone code often fills a target_attr object for the enforcer which contains details about the resource that Keystone would return so that the policy checks can validate beforehand if it violates any RBAC definitions.
Now, for API endpoints that return a list, there is no single object returned. Hence, there normally would not be any specific attributes to check against. However since part B hardcodes that only objects matching the authenticated domain id will be returned, part A has one simply purpose: to reflect the hardcoded behavior of part B in the RBAC checks - namely the returned objects' domain.
Simply speaking it adds the information that the method will return only objects of this specific domain back to the RBAC layer, which would normally not be available there.
As a result, part A enables checks in the policy.yaml definitions that reference the domain id, for example:
With this rule, listing projects would only work from within the domain with that id and nowhere else (it doesn't make sense and is just for demonstration purposes).
Summary
To summarize, part B implements a hardcoded behavior that automatically limits the resources returned in the list_projects to the domain the user making the request is authenticated in, if the user is authenticated in a domain-scoped fashion.
In case the request is domain-scoped, part A adds the information about the domain id membership of all returned objects (as implemented by part B) back to the RBAC policy checking layer, so that the additional information resulting from B can be used in policy definitions and checks.
With this patch, only the domain the user is authenticated in is returned in the list, if the authentication is domain-scoped. If it is a system-scoped authentication by an administrator, the full list of domains is returned.
Someone suggested in the comments of the patch, that it might break API for those who do not enforce scope. As fas as I have tested it again, it does not. But I asked dmendiza from upstream for a review, because he is also involved in the secure RBAC developlement and has a better overview about the scopes.
@berendt I would say yes, but we should discuss this in the IaaS meeting. There is a little bit of difficulty added, because the patch relies on a recent update of the policies which happened within this OpenStack cycle.
@berendt I would say yes, but we should discuss this in the IaaS meeting. There is a little bit of difficulty added, because the patch relies on a recent update of the policies which happened within this OpenStack cycle.
Ok, we'll discuss this on Wednesday. But I think we'd rather not have a backport as we're already at the RCs and SCS probably won't be able to make any major adjustments at such short notice.
@markus-hentsch I noticed today, that the patch does not include the zuul.yaml, that excluded some tempest tests. However, the pipeline was green, otherwise it would not have been merged.
CommunityIssues or pull requests relevant for SIG CommunityIAMIssues or pull requests relevant for SIG IAMIaaSIssues or pull requests relevant for Team1: IaaSSCS-VP10Related to tender lot SCS-VP10enhancementNew feature or request
Activity
markus-hentsch commentedon Oct 23, 2023
I'm copy-and-pasting here what I've documented in the original ticket regarding the lack of proper domain-scoping of
list_domains.When a command specifying an object per name is used, e.g. the domain in "
openstack user create --domain my-domain ..." thenopenstackclientwill attempt to resolve the domain name into the domain ID by internally retrieving the domain list via "GET /v3/domains?name=my-domain" before attempting to create the user object. That means, that even if the domain admin only needs their own domain, they need access to the domain list API to resolve the name to ID of their very own domain.The same goes for the roles API: resolving a role name to ID is done via the roles list API in the client.
For "
openstack project list" there is proper domain-scoping implemented:This is currently not implemented for "
openstack domain list":This policy works for projects:
This policy does not work for domains:
and leads to the following error upon "
openstack domain list":This is why the policy has to be configured to allow domain admins to list all domains in order to enable them to manage user, projects and role assignments within their domain properly.
markus-hentsch commentedon Oct 23, 2023
Deep-dive analysis of domain scoping for other
identity:list_*APIsTo understand how other API endpoints such as
identity:list_groupsoridentity:list_projectsimplement domain scoping, I had a closer look at the implementation, its behavior and purpose.Let's take for example the domain filtering for
identity:list_projectswhich happens inkeystone/api/projects.py:_list_projects():(code slightly abridged at the
# ...parts for readability)There are two crucial parts of the domain-scoping:
Part A: Policy enforcement check sync
Part B: Response content filtering
Here is my interpretation of the code:
Part A is actually not contributing to the filtering at all.
The core of the filtering is part B.
The
self.oslo_contextobject stores information about the authentication of the user making the request, i.e. the scope of the Keystone token. This includes information like in which project or domain the user is authenticated in and with what role.So part B is checking whether the user is authenticated in a domain-scoped fashion and if so, the result list of projects will be filtered for projects that match this domain.
Thus, the returned project list only contains projects from the same domain as the user.
If an administrator authenticated in system-scope makes the same request, the
elsebranch of part B will trigger since there is no domain scope in theself.oslo_contextobject and the returned list will contain all projects instead.Now for part A. The purpose of this part is not obvious at first.
The
enforce_call()will check the Keystone policy definition (identity:list_projectsin this case) against the authenticated user and will make the RBAC check if the user is allowed to execute this action.When writing RBAC rules for the
policy.yamlof an OpenStack component, the author can usually access attributes of the target resource. For example the policy rule:... would check if the API response being targeted contains a
projectobject whosenameattribute matches "special-project" and only allows the request if that is the case. For this purpose, the Keystone code often fills atarget_attrobject for the enforcer which contains details about the resource that Keystone would return so that the policy checks can validate beforehand if it violates any RBAC definitions.Now, for API endpoints that return a list, there is no single object returned. Hence, there normally would not be any specific attributes to check against. However since part B hardcodes that only objects matching the authenticated domain id will be returned, part A has one simply purpose: to reflect the hardcoded behavior of part B in the RBAC checks - namely the returned objects' domain.
Simply speaking it adds the information that the method will return only objects of this specific domain back to the RBAC layer, which would normally not be available there.
As a result, part A enables checks in the
policy.yamldefinitions that reference the domain id, for example:With this rule, listing projects would only work from within the domain with that id and nowhere else (it doesn't make sense and is just for demonstration purposes).
Summary
To summarize, part B implements a hardcoded behavior that automatically limits the resources returned in the
list_projectsto the domain the user making the request is authenticated in, if the user is authenticated in a domain-scoped fashion.In case the request is domain-scoped, part A adds the information about the domain id membership of all returned objects (as implemented by part B) back to the RBAC policy checking layer, so that the additional information resulting from B can be used in policy definitions and checks.
markus-hentsch commentedon Oct 23, 2023
Keystone patch for domain lists that could be upstreamed
The same behavior as researched above for the
identity:list_projectsrelated endpoint can be replicated foridentity:list_domains:With this patch, only the domain the user is authenticated in is returned in the list, if the authentication is domain-scoped. If it is a system-scoped authentication by an administrator, the full list of domains is returned.
berendt commentedon Oct 23, 2023
@markus-hentsch I will add this as a patch to latest OSISM Keystone images. I think it makes sense to have this already there.
Can you please add the pending review request here as will.
2023.1: add scs-domain-scoping-for-domain-list.patch
12 remaining items
josephineSei commentedon Feb 8, 2024
I am on it fixing the Errors in tox and will align the keystone patch with the tempest plugin patch, because the Policy names had to be changed.
josephineSei commentedon Feb 9, 2024
My fixes were successful, I additionally asked for reviews in the IRC-channel.
josephineSei commentedon Feb 12, 2024
Someone suggested in the comments of the patch, that it might break API for those who do not enforce scope. As fas as I have tested it again, it does not. But I asked dmendiza from upstream for a review, because he is also involved in the secure RBAC developlement and has a better overview about the scopes.
josephineSei commentedon Feb 22, 2024
I asked for reviews again and got a +2 from Dave, he want to also bring this topic up to the other cores.
josephineSei commentedon Mar 4, 2024
our patch was merged upstream: https://review.opendev.org/c/openstack/keystone/+/900028
So I close this issue
berendt commentedon Mar 4, 2024
@josephineSei Should a (downstream) backport be made for 2023.2 so that the patch is included in the next SCS release?
josephineSei commentedon Mar 4, 2024
@berendt I would say yes, but we should discuss this in the IaaS meeting. There is a little bit of difficulty added, because the patch relies on a recent update of the policies which happened within this OpenStack cycle.
berendt commentedon Mar 4, 2024
Ok, we'll discuss this on Wednesday. But I think we'd rather not have a backport as we're already at the RCs and SCS probably won't be able to make any major adjustments at such short notice.
fkr commentedon Mar 4, 2024
I added it to the agenda for wednesday.
One idea would be to bring it in a subsequent release to R6 such as a 7.1.0.
josephineSei commentedon Mar 5, 2024
@markus-hentsch I noticed today, that the patch does not include the zuul.yaml, that excluded some tempest tests. However, the pipeline was green, otherwise it would not have been merged.
So I don't know, whether this: https://review.opendev.org/c/openstack/keystone-tempest-plugin/+/900545?tab=change-view-tab-header-zuul-results-summary is still required or not upstream.
Maybe we should ask upstream, what was done with the keystone pipeline and tests.
markus-hentsch commentedon Apr 30, 2024
A patchset was still lingering concerning Keystone's tempest tests: https://review.opendev.org/c/openstack/keystone-tempest-plugin/+/900545/comments/c4d5de73_063eda62
I rebased this now, since in the meantime the upstream code about tests has changed a bit (as referenced in the review comment).
markus-hentsch commentedon Jun 4, 2024
The fix for the domain-scoping has now been backported to the 2023.2 release:
https://bugs.launchpad.net/keystone/+bug/2041611/comments/5
fkr commentedon Jun 4, 2024
thanks @markus-hentsch for your work and effort