keystone/keystone
Colleen Murphy a405e4b71d Fix security issues with EC2 credentials
This change addresses several issues in the creation and use of EC2/S3
credentials with keystone tokens.

1. Disable altering credential owner attributes or metadata

Without this patch, an authenticated user can create an EC2 credential
for themself for a project they have a role on, then update the
credential to target a user and project completely unrelated to them. In
the worst case, this could be the admin user and a project the admin
user has a role assignment on. A token granted for an altered credential
like this would allow the user to masquerade as the victim user. This
patch ensures that when updating a credential, the new form of the
credential is one the acting user has access to: if the system admin
user is changing the credential, the new user ID or project ID could be
anything, but regular users may only change the credential to be one
that they still own.

Relatedly, when a user uses an application credential or a trust to
create an EC2 credential, keystone automatically adds the trust ID or
application credential ID as metadata in the EC2 access blob so that it
knows how the token can be scoped when it is used. Without this patch, a
user who has created a credential in this way can update the access blob
to remove or alter this metadata and escalate their privileges to be
fully authorized for the trustor's, application credential creator's, or
OAuth1 access token authorizor's privileges on the project. This patch
fixes the issue by simply disallowing updates to keystone-controlled
metadata in the credential.

2. Respect token roles when creating EC2 credentials

Without this patch, a trustee, an application credential user, or an
OAuth1 access token holder could create an EC2 credential or an
application credential using any roles the trustor, application
credential creator, or access token authorizor had on the project,
regardless of whether the creator had delegated only a limited subset of
roles. This was because the trust_id attribute of the EC2 access blob
was ignored, and no metadata for the application credential or access
token was recorded either. This change ensures that the access
delegation resource is recorded in the metadata of the EC2 credential
when created and passed to the token provider when used for
authentication so that the token provider can look up the correct roles
for the request.

Conflicts (six removal in  e2d83ae9, pep8 fixes in e2d83ae9):
      keystone/api/credentials.py
      keystone/tests/unit/test_v3_application_credential.py
      keystone/tests/unit/test_v3_credential.py

Conflicts due to flask reorg:
	keystone/api/_shared/EC2_S3_Resource.py
	keystone/api/credentials.py
	keystone/api/users.py
	keystone/tests/unit/test_v3_credential.py

Moved the test_update_credential_non_owner unit test to
CredentialSelfServiceTestCase since in this branch the default policies
are not affected by #1872733.

NOTE: the application credential functional changes, along with its
tests were removed from the stable/pike backport as stable/pike does not
support application credentials.

Change-Id: I39d0d705839fbe31ac518ac9a82959e108cb7c1d
Closes-bug: #1872733
Closes-bug: #1872755
Closes-bug: #1872735
(cherry picked from commit 37e9907a17)
(cherry picked from commit 2f2736ebb2)
(cherry picked from commit 27caafe3daa552663719954f2cd6713dd4493178)
(cherry picked from commit bfba75fc3c5c8f119f74dbf31347e008824a2134)
(cherry picked from commit 53d1ccb8a1)
(cherry picked from commit 6db1bb09a0)
2020-06-03 09:54:00 -07:00
..
assignment Cache list projects and domains for user 2017-08-09 14:45:58 +00:00
auth Merge "Add annotation about token authenticate" 2017-06-23 21:31:03 +00:00
catalog Ensure the endpoint filter API supports HEAD 2017-06-13 14:03:14 +00:00
cmd Remove deprecation of domain_config_upload 2017-08-16 14:45:55 +00:00
common Fix json schema nullable to add None to ENUM 2018-04-19 13:25:02 +00:00
conf Check timestamp of signed EC2 token request 2020-05-31 22:16:05 -07:00
contrib Fix security issues with EC2 credentials 2020-06-03 09:54:00 -07:00
credential Fix security issues with EC2 credentials 2020-06-03 09:54:00 -07:00
endpoint_policy Ensure the endpoint policy API supports HEAD 2017-06-20 19:44:43 +00:00
federation Mapped Groups don't exist breaks WebSSO 2018-09-24 14:50:31 -03:00
identity Delete shadow users when domain is deleted 2019-04-05 09:16:25 -07:00
locale Imported Translations from Zanata 2017-08-02 07:49:09 +00:00
middleware Make an error state message more explicit 2017-08-08 14:53:20 -07:00
models Revert change 438035 is_admin_project default 2017-05-11 10:46:03 -04:00
oauth1 Ensure oauth API supports HEAD 2017-06-21 15:00:38 +00:00
policy Remove unused CONF 2017-04-22 15:22:05 +08:00
resource Delete SQL users before deleting domain 2018-02-09 00:19:33 +01:00
revoke Remove unused revoke_by_domain_role_assignment 2017-03-24 15:22:04 +00:00
server Merge "Remove log translations in keystone" 2017-03-27 17:35:03 +00:00
tests Fix security issues with EC2 credentials 2020-06-03 09:54:00 -07:00
token Fix security issues with EC2 credentials 2020-06-03 09:54:00 -07:00
trust Merge "Ensure the trust API supports HEAD requests" 2017-06-23 05:23:13 +00:00
v2_crud Use https for docs.openstack.org references 2017-01-30 16:05:08 -08:00
version Remove log translations in keystone 2017-03-25 18:17:15 +00:00
__init__.py Revert "Disable eventlet monkey-patching of DNS" 2013-05-10 10:24:48 -04:00
exception.py Handle ldap size limit exeeded exception 2017-10-25 02:06:08 +00:00
i18n.py Remove log translations in keystone 2017-03-25 18:17:15 +00:00
notifications.py Delete SQL users before deleting domain 2018-02-09 00:19:33 +01:00