Commit Graph

34 Commits

Author SHA1 Message Date
Vishakha Agarwal 252c23b1b8 Disable EC2 credentials access_id update
Without this patch user can alter EC2 credential access_id and user
cannot use it anymore as an ec2 auth token since EC2 credential
access ID is used to calculate an ID of the "credential" [1] and it
doesn't update the EC2 credential ID with new access ID. This leads
to unwanted EC2 credentials stored in database.

As per the discussion of keystone team [2] we decided to block patching
of "access_id" attribute.

[1] 7bb6314e40/keystone/api/users.py (L363)
[2]http://eavesdrop.openstack.org/irclogs/%23openstack-meeting-alt/%23openstack-meeting-alt.2020-05-12.log.html#t2020-05-12T17:45:20

Closes-Bug: #1872753
Change-Id: I1f6ce3927c2881d9a2d7dcda3ccd29e0a82e45a9
2020-05-19 17:35:05 +05:30
Colleen Murphy 37e9907a17 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.

Change-Id: I39d0d705839fbe31ac518ac9a82959e108cb7c1d
Closes-bug: #1872733
Closes-bug: #1872755
Closes-bug: #1872735
2020-05-02 12:34:20 -07:00
Sean McGinnis 8c99a90f36 Switch from mock to unittest.mock use
The mock library is a third party lib that attempted to bridge the gap
between Python 2 and Python 3 mocking. Now that we have moved to py3
only, there is no need to use a third party lib and we can use the
standard built-in mocking support.

Change-Id: I8bbcedb7ad3f0bc2e06dfa13878a97411ee1dc6d
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-03-02 13:40:40 -06:00
Vishakha Agarwal 4530041931 Remove six usage
This repo does not support Python 2 anymore, so we don't need
six for compatibility between Python2 and 3, convert six usage to Python
3 code.

Change-Id: Icba56808f38277b27af2ae5aac4b8507dee71b3b
2020-01-30 06:06:51 +00:00
Rabi Mishra e989bd0637 Add retry for DBDeadlock in credential delete
Adds oslo.db retry wrapper to delete_credential_for_user method.

Change-Id: Ib9e161411f0985785eec46c51d721ef7421ee090
Closes-Bug: #1840291
2019-08-19 21:06:40 +05:30
Lance Bragstad 239bed09a9 Implement scope_type checking for credentials
This change adds tests cases for the default roles keystone
supports at install time. It also modifies the policies for the
credentials API to be more self-service by properly checking
for various scopes.

Closes-Bug: 1788415
Partial-Bug: 968696

Change-Id: Ifedb7798c96930b6cc0f91159a14a21ac4b02f9f
2018-10-29 15:01:29 +00:00
Morgan Fainberg 35c9bb7eff Convert S3 and EC2 auth to flask native dispatching
Convert S3 and EC2 auth to flask native dispatching.

Test changes required:

* Eliminate direct reference of the EC2 / S3 controllers, originally
  this direct reference was to verify signature checking. Since
  signature checking is an @staticmethod now, direct reference of
  the API resources covers everything.

* Direct import of keystone.common.controller - due to an oddity in
  how our WSGI code work(s) in test, if nothing imports the common
  controller module, the tests fail using the oslo import_class
  mechanism.

Change-Id: I06e95957b3ea3a55b0da28959548bd5eb628c70b
Partial-Bug: #1776504
2018-10-11 15:27:46 -07:00
wangxiyuan 59e1d211a6 Remove enable config option of trust feature
Then `enable` config option of trust feature is depreacted in
Queens. Remove it in Rocky now.

Change-Id: I186b49471cb774e161ff4c35c9879a0a4fa9538f
bp: removed-as-of-rocky.
2018-07-09 16:13:55 +08:00
Lance Bragstad 8761066260 Finish refactoring self.*_api out of tests
A previous change started remove the self magic:

  Ic2094dca56158d8e4cd843eadff837f3a17ea38f

This commit finishes that work. A subsequent patch will remove the
self manager logic all together and we'll fix up any trivial test
infrastructure then.

Change-Id: Iedbde34ef5aa84905fd6b5f2297bf7f46dd7d278
2018-02-05 23:26:08 +00:00
Gábor Antal c812f53629 Removed unnecessary setUp() calls from unit tests
TrivialFix

Change-Id: I4d4349f70f58b1bb464fcb9b7adf324991b73530
2017-08-01 18:24:03 +02:00
Feng Shengqin 19559b69c0 Remove unused CONF
Change-Id: Ie748beb4236b13508f66b396efbeca4965d3da14
2017-04-22 15:22:05 +08:00
Lance Bragstad 0edf1fe46c Implement encryption of credentials at rest
This commit implements credential encryption through the following changes:

 - additive schema change to store key hashes for credentials
 - database migration to encrypt all pre-existing credentials
 - contractive schema change to remove unencrypted credential column
 - added code to the credential Manager to handle credential encryption

All credentials will be encrypted by default. There will not be a way to store
unencrypted credentials in keystone from this point forward.

Note that this implementation uses database triggers in the migration process.
If operators use the traditional offline migration method, it would be more
reliable if we didn't try to setup and tear down triggers, as they'll never be
used anyway. This makes it so that expand and contract migrations can skip
anything related to triggers.

Co-Authored-By: Werner Mendizabal <nonameentername@gmail.com>

bp credential-encryption

Depends-On: I433da9a257daa21ec3b5996b2bca571211f1fbba
Depends-On: Id3e8922adc154cfec5f7a36613e22eb0b49eeffe
Change-Id: I31b7539db436ad270462cfaa3b14213e0ed1fc04
2016-09-02 04:25:49 +00:00
Rodrigo Duarte Sousa 8144e28336 Fix credential update to ec2 type
It was possible to create a credential without providing a project_id
and later updating it to the ec2 type.

This patch fixes the issue by adding a manual checking in the
manager layer since it needs to check the old credential contents
prior failing the request.

Change-Id: I1eb28a46c89e17d9c990cc798867d1a59714fe5f
Closes-Bug: #1613466
2016-08-23 06:58:03 +00:00
Dolph Mathews d9c6b50a3a Replace keystone.common.config with keystone.conf package
keystone.common.config is 1200+ lines of super dense, merge-conflict
prone, difficult to navigate, and finicky to maintain code. Let's follow
nova's lead and break it down into more manageable modules.

This patch creates a new Python package, keystone.conf, and moves all of
our configuration options into it, mirroring nova's nova.conf package.

There are a couple special modules in keystone.conf introduced here as
well:

- keystone.conf.__init__: This causes all of Keystone options to be
  registered on import, so consumers of keystone.conf don't have
  races with config initialization code while trying to use
  oslo_config.cfg.CONF directly (keystone.conf replaces all uses for
  oslo_config.cfg.CONF in keystone).

- keystone.conf.base: Keystone's [DEFAULT] group options. I'd prefer
  this to be called 'default.py', but I'm just copying nova's lead here.

- keystone.conf.opts: The entry point for oslo.config itself.

- keystone.conf.constants: There are a few constants (deprecation
  messages, default paths, etc) that are used by multiple configuration
  modules, so they need to live in a common place.

Change-Id: Ia3daffe3fef111b42de203762e966cd14d8927e2
2016-06-24 17:02:15 +00:00
Tin Lam 2bad130bf4 Removing H405 violations from keystone
Keystone's tox.ini contains an "ignore" entry for H405 violations:
multi line docstring summary not separated with an empty line.
All violations of H405 should be fixed so that H405 can be removed
from the ignore list.

Change-Id: I1b2aae0cabc20909cf3b0a405d5e31c5d91148b2
Closes-Bug: #1482773
2016-02-21 03:47:55 -05:00
Morgan Fainberg 5286b4a297 Deprecate admin_token_auth
Deprecate the admin_token_auth middleware in favor of using
keystone-manage bootstrap

Change-Id: Ib4ca153af2855911f9261081e7e442dfbc28f652
bp: deprecated-as-of-mitaka
bp: bootstrap
2016-02-11 17:07:00 -03:00
Lance Bragstad 0d7e29f436 Reuse project scoped token check for trusts
After some refactoring [1][2][3], the
assertValidProjectTrustScopedTokenResponse method was just a wrapper around
assertValidProjectScopedTokenResponse. This commit makes it so that tests just
use the later directly.

[1] https://review.openstack.org/#/c/254258
[2] https://review.openstack.org/#/c/253671
[3] https://review.openstack.org/#/c/253670

Change-Id: I97a4c4b578403c8dfcd93b821964ed36b8b168ab
2016-01-28 19:43:00 +00:00
Tony Wang 9fc1cc67d9 Add `type' filter for list_credentials_for_user
When getting, or operating on a credential, EC2 controller needs to
specify it's a ec2 credential, avoiding conflicts with other type of
credentials.

Closes-Bug: #1506473
Change-Id: Id92fc87bf1be5448aa929224bbce4d3f7f4359b6
2015-12-11 01:02:38 -05:00
Sean Perry 44d0c2f5a5 Clean up new_credential_ref usage and surrounding code
Standardize use of unit.new_credential_ref(). Remove methods in preference
for the common function.

Refactor the credential creation code to simplify and standardize the tests.

Change-Id: I4274ea9ae17ae7b8b18dc0c86c9f9496a0803c71
2015-12-10 12:32:03 -08:00
Sean Perry 2f28b7525e Use new_trust_ref consistently
Replace method with the new_trust_ref function it calls.

Change-Id: I395bf9795a4f56e3e1910266ecfdf2ad211ea5d9
2015-11-18 18:12:44 -08:00
Sean Perry 5784285e9f Use unit.new_user_ref consistently
Replace all hand created user refs with calls to new_user_ref().

Note: LDAP live testing code will be updated in a follow on patch.
They require more testing before submission.

Change-Id: I73b1d869534ac3a1bcd2404ef1dd3a0d5b7ea518
2015-11-17 19:20:33 +00:00
Dolph Mathews 99b4948439 Fix D204: blank line required after class docstring (PEP257)
No other PEP257 violations were addressed in this patch.

Change-Id: I85a16985022e1671a134345880b9b5a5770ce5fa
2015-10-28 07:25:24 +00:00
Dolph Mathews bf08563778 Fix D208: Docstring over indented. (PEP257)
No other PEP257 violations were addressed here.

Change-Id: I567fb5681b043b26bea3d358d7a47d88c02249a0
2015-10-16 17:16:10 +00:00
Lance Bragstad ce293f68ed Refactor: Don't hard code 409 Conflict error codes
This patch replaces hard coded HTTP codes with constants.

Change-Id: I5b314c250d2e891ed8af1d3878b57461075c68f1
2015-10-12 19:00:21 +00:00
Dolph Mathews 0dbedfa532 Rename RestfulTestCase.v3_authenticate_token() to v3_create_token()
The name of this method has plagued me for years, so I figured I would
finally propose a fix. The reason v3_authenticate_token() is a terrible
name is that it implies that a token is being authenticated (in other
words: validated). As it turns out, we have another operation that
validates tokens, and this isn't it.

By renaming the method to v3_create_token() there is absolutely no
confusion about the intended outcome. This also more closely reflects
how we colloquially refer to operation.

v3_authenticate() might have also have been an improvement, but could
lead to the same confusion we have today (whether or not the user is
authenticating with keystone or whether a service is authenticating a
token).

Change-Id: I2bfebf1b48de07e81eadc2782d4e975b920f2a6a
2015-10-02 14:05:21 +00:00
Rajesh Tailor 3f74823fb8 Fix order of arguments in assertEqual
Some tests used incorrect order assertEqual(observed, expected).

The correct order expected by testtools is
assertEqual(expected, observed).

At some places, corrected argument order for assertNotEqual method as well.

Change-Id: I6d63e77620b8dd9d6415424783b99a7e2e381a22
Partial-Bug: #1259292
2015-09-25 02:06:55 -07:00
Dave Chen f661325667 Refactor: Don't hard code the error code
This patch replace the hard coded HTTP error code (200~226)
in unittest with the constants, and remove part of them which
has the same value with the default value.

Change-Id: I184adc72772a030b3a316b1e3f9676d0efc807b5
2015-09-24 10:15:21 +08:00
Dave Chen a50e23b9b7 Refactor: Don't hard code the error code
This patch replace the hard coded HTTP error code (400~410)
with the constants.

Change-Id: I952cac73a9713bde4ad757371ca8b4ded93f207e
2015-09-13 19:21:56 -05:00
mari-linhares 4c9a5353ef List credentials by type
Currently the only attribute that you can filter a credential list by is
user_id. I want to be able to list by user_id and credential type (a
required field) so that I only get back my EC2 credentials (for example)
when I do a list.

Change-Id: I91f8fb15a2e9a8326059d7a60d2bf1b4c4aa6daa
Closes-bug: #1460492
bp list-credentials-by-type
2015-09-02 21:51:57 -05:00
Jenkins ce6bbedb93 Merge "add missing links for v3 OS-EC2 API response" 2015-03-25 20:45:29 +00:00
lin-hua-cheng a9f257dc05 Made project_id required for ec2 credential
ec2 tokens cannot be created without the user and project
associated with the credentials. The project_id must be
required when creating ec2 credentials.

Updating json schema to check:
- if ec2 type, project_id is required
- else, project_id is optional

 Closes-Bug: #1268977

Change-Id: Id7118e028d8c3ff607ac24cd9ecba90a905ce91f
2015-03-06 10:30:18 -08:00
wanghong e6c67148fe add missing links for v3 OS-EC2 API response
Change-Id: Ic83109f65fc7ba077a74865a7b5c630a01203edb
Closes-Bug: #1416303
2015-02-25 14:53:19 +08:00
Brant Knudson feb279d1dc Consistently use oslo_config.cfg.CONF
Keystone modules used different sources of the CONF global so were
inconsistent. All modules should use CONF from oslo_config.cfg.

Change-Id: I60c8d2c577d37b9b8a367b46596154ce6c49fff4
2015-02-18 09:04:05 -06:00
Brant Knudson 115d9660de Move existing tests to unit
The existing test files are all moved under keystone.tests.unit,
except the existing keystone.tests.unit are left in place.

The .testr.conf is updated so that unit tests are run by default
in tox envs, and a tox env can override the tests to run by
setting OS_TEST_PATH.

This is so functional tests can sit in keystone.tests.functional.

Change-Id: I065d3f56e22f344abdadd92b3b384b002b02d989
2015-02-13 15:54:29 -06:00