Commit Graph

45 Commits

Author SHA1 Message Date
Rafael Weingärtner 14ac08431f Keystone to honor the "domain" attribute mapping rules.
We propose to extend Keystone identity provider (IdP) attribute mapping
schema to make Keystone honor the `domain` configuration that we have
on it.

Currently, that configuration is only used to define a default domain
for groups (and then each group there, could override it). It is
interesting to expand this configuration (as long as it is in the root
of the attribute mapping) to be also applied for users and projects.

Moreover, to facilitate the development and extension concerning
attribute mappings for IdPs, we changed the way the attribute mapping
schema is handled. We introduce a new configuration
`federation_attribute_mapping_schema_version`, which defaults to "1.0".
This attribute mapping schema version will then be used to control the
validation of attribute mapping, and also the rule processors used to
process the attributes that come from the IdP. So far, with this PR,
we introduce the attribute mapping schema "2.0", which enables
operators to also define a domain for the projects they want to assign
users. If no domain is defined either in the project or in the global
domain definition for the attribute mapping, we take the IdP domain
as the default.

Change-Id: Ia9583a254336fad7b302430a38b538c84338d13d
Implements: https://bugs.launchpad.net/keystone/+bug/1887515
Closes-Bug: #1887515
2024-01-16 08:54:56 -03: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
Lance Bragstad 112fa29a74 Only validate tokens once per request
Keystone actually validates each token twice for every API request.
Regardless of caching being configured, we have an opportunity to try
and spend less time doing something we've already done.

The first the token is validated is actually done through a
keystonemiddleware hook. The second time is to populate a context
object that we can use for things like policy decisions.

Closes-Bug: 1819036
Change-Id: Ifd7f6f0a1dcd33ad17646cae383132cfc2462f03
2019-03-20 19:17:33 +00:00
Zuul 09bc0b5b0f Merge "populate request context with X.509 tokenless cred information" 2019-02-16 07:43:45 +00:00
Zuul f770e29829 Merge "Fixes incorrect params" 2019-02-15 23:06:20 +00:00
Guang Yee 1b261e8bec populate request context with X.509 tokenless cred information
Fixes X.509 tokenless auth by properly populating the request context
with the necessary credential information. Since Stein release, RBAC
has been using the credential information from the Keystone request
context instead of the authentication context. Therefore, we'll need
to populate the request context with the necessary credential
information from the X.509 tokenless authentication context.

Closes-Bug: 1811605
Change-Id: I170a91e9ac36990d1e7ec4165dd0337b8f06a938
2019-02-11 09:21:15 -08:00
Guang Yee 505fe20479 Fixes incorrect params
Fixes incorrect parameters passed into
keystone.federation.utils.transform_to_group_ids() which resulted
in HTTP 500 internal error.

Added an additional test case to test mapping with group domain name
in it as this scenario was never tested before.

Change-Id: I4112e5968cd0d52444b686a3777da56203ae95ad
Closes-Bug: 1814589
2019-02-08 17:12:21 -08:00
Vishakha Agarwal 4c84739e26 Replace 'tenant_id' with 'project_id'
Since 'tenant_id' is deprecated in openstack.
Thus replacing it with 'project_id'.

Change-Id: I77e4222623eb3c91fd7d10c2cbb4d212af736814
2019-02-04 16:17:52 +01:00
Morgan Fainberg 184c84ae76 Remove pre-flask legacy code
This removes common.controller, common.extension, common.router, and
common.wsgi. Relevant code from common.wsgi (used by AuthContext) was
moved into keystone.server.flask.request_processing.middleware.auth_context.

keystone.api.discovery now uses keystone.flask.base_url

test_middleware and test_exception were modified to reflect the changes
to the remaining code from keystone.common.wsgi

keystone.common.authorization only holds a couple constants for auth
work now.

Routes is removed from requirements.txt

Release-Note for migration to flask added.

Change-Id: I81563b6a49c8f12ecade058a9483f3b6f070dc72
Closes-Bug: #1776504
2018-10-15 10:56:26 -07:00
Morgan Fainberg 595967bba6 Move AuthContextMiddleware
Move AuthContextMiddleware to keystone.server.flask.request_processing
to be more in line with the other internally defined middleware.

Change-Id: I25b6a88f4b0dc3af306360ee4e5ec0abfe3cf812
Partial-Bug: #1776504
2018-10-11 15:27:46 -07:00
Morgan Fainberg ee9b035cf1 Replace JSON Body middleware with flask-native func
Replace the JSON Body middleware with flask-native before-request
function.

The body filtering and storing data in
request.environ['openstack.params'] was not used in the code base and
has been dropped.

Test Changes:

* JSON Body middleware has been removed, no testing of the removed code

* JSON Body Before Request Method has been implemented and associated
  testing (mirroring the JSON Body middleware code).

* Test entry points no longer looks for JSON Body middleware.

Change-Id: I84491865870b6bf2b8f094b524ee8b77510f0054
Partial-Bug: #1776504
2018-10-11 15:27:46 -07:00
Jamie Lennox b39132daa0 Remove the TokenAuth middleware
The entire purpose of this confusingly named middleware is to take token
values out of headers and put them into a dictionary. There's no point
in this, we have a request class that can abstract this for us.

Deprecate the middleware, it's unnecessary.

bp: deprecated-as-of-rocky
Change-Id: I09310bab6bd728127288ba4c3cf8f884a31e2b98
2018-05-10 14:40:39 +00: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
Jamie Lennox f5bd968a97 Move auth header definitions into authorization
common/authorization.py seems to be the canonical local for all our
information relating to auth parameters. The header definitions should
really be there as well.

Change-Id: I20d5cc94a55dd8936b5fe376ebbabd69909bb4dd
2017-09-30 07:26:18 +10:00
Jamie Lennox a98fca3bd0 Remove middleware reference to PARAMS_ENV and CONTEXT_ENV
I'm guessing these two links were maintained as part of a larger
refactor some time ago, however there's really no reason to maintain
these references in multiple places. Remove them.

Change-Id: I9a3a6a3b59e0591a47d52512742995d56958e6bf
2017-09-29 15:42:54 +10:00
Gage Hugo cdee7e6ebf Remove assertRaisesRegexp testing function
This change removes the function assertRaisesRegexp from within
keystone to help reduce any confusion about what is really being
called within the appropriate test. The test was changed to use
assertRaisesRegex() which is aliased in six for python 2 and 3.

assertRaisesRegexp in this change was a part of keystone itself
rather than the function of the same name from python 2, and was
causing confusion with recent changed regarding deprecation
and python 3 changing the name to assertRaisesRegex.

Change-Id: I63c84ff432e08866253cfb14ad3bb8db4a665589
2017-06-02 12:40:48 -05:00
David Stanek 9cbcc47205 Remove orphaned _create_context test helper
The last reference to this method was removed in
I37c0b48a8d564dcd4aee59b86e50f374f5b60531

Change-Id: I7b731dbb3105085a147d5a64e732f86d701ae660
2017-03-28 23:34:01 +00:00
Adam Young 4981da8fb0 Deprecate (and emit message) AdminTokenAuthMiddleware
Officially deprecate the admin_token_auth in the paste-ini. The
functionality has been merged into auth_context_middleware. This allows
for a smoother removal of the admin-token functionality down the line.

The AdminTokenAuthMiddleware now does nothing if in the pipeline
except emitting a log.error.

This also removes the ADMIN token from the paste-pipeline itself

implements bp: removed-as-of-pike
Co-authored-by: Morgan Fainberg <morgan.fainberg@gmail.com>
Change-Id: I57586ccfa0ad1309cc806d95377dc1ecad015914
2017-02-09 18:16:48 +00:00
Colleen Murphy e420b16c22 Skip middleware request processing for admin token
In be558717 the request handling was refactored and more of the token
handling was left to keystonemiddleware. However, when using the
deprecated admin_token, the token needs to be handled differently.
Specifically, there may be no 'token' or 'access' key in the body of
the request, which keystoneauth expects to have keystonemiddleware pass
to it[1][2]. Luckily the admin_token doesn't need a lot of special
processing, so we can just skip that step and move on to fill_context.

[1] http://git.openstack.org/cgit/openstack/keystonemiddleware/tree/keystonemiddleware/auth_token/__init__.py#n399
[2] http://git.openstack.org/cgit/openstack/keystoneauth/tree/keystoneauth1/access/access.py#n41

Closes-bug: #1603038

Change-Id: Iac4a5769072925fe2f36768c8f31816e6866f2f6
2016-08-02 19:47:32 -07: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
Jenkins d21edb4715 Merge "Make AuthContext depend on auth_token middleware" 2016-05-19 02:38:10 +00:00
Navid Pustchi aabc213040 Fix D401 PEP8 violation.
Currently tox ignores D401 (401: First line should be in imperative mood).
This change removes it and make keystoneauth docstring compliantwith it.

Change-Id: I136cf810f47c4c19f29216907a63f226930b5082
Partial-Bug: 1570049
2016-04-14 20:08:52 +00:00
Jamie Lennox be558717ed Make AuthContext depend on auth_token middleware
Reuse the validation logic that is already present in auth_token
middleware. Once this is present keystone can start to reuse the same
helpers that are created from auth_token middleware that the other
services rely on.

For now there is still some redundancy, like for example bind checking
is now enforced in auth_token middleware and in keystone. These can be
removed in later commits because they will require test changes.

My intention after this is to start to more directly integrate this with
oslo.policy and start to standardize the way auth is handled from
auth_token middleware to enforcement. Doing this work here means that we
get keystone to try out policy changes first.

Change-Id: I6592ea2865863c9ace1304b06d73a917c3a1b114
2016-04-06 15:49:22 +10: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
Adam Young 37e9d6bbf1 Disable Admin tokens set to None
Partial-Bug: 1545761

Change-Id: Ie292f447f2fe1357824b322817b1585c82d0c552
2016-02-16 20:00:34 +00:00
Morgan Fainberg 64a5a8d7df Remove PostParams middleware
This middleware has not been used/is not used for quite a while.
Remove it.

Change-Id: I4ba12033ea1586a6b527c9d021907e942ffe2ef7
2016-02-10 23:58:45 -05:00
Jenkins d124969fc2 Merge "Replace unicode with six.text_type" 2016-02-01 23:54:31 +00:00
Ankit Agrawal 6b349d9ca5 Replace unicode with six.text_type
The Unicode type is 'unicode' in Python 2 and 'str' on Python 3.
This patch replaces unicode with six.text_type to make Keystone
compatible with Python 2 and Python 3. To protect against regression
two py34 problems were fixed and test_middleware.py was added
to tox.ini.

Co-Authored-By: Tom Cocozzello <tjcocozz@us.ibm.com>
bp python3
Change-Id: I4a5cf86ca1aa5f4d305696c2b39cdbc7e2cbc71e
2016-01-08 23:06:47 +00:00
Jamie Lennox 270ca6897b Perform middleware tests with webtest
Currently the middleware tests are performed by creating a fake request
object and then running the perform_request method. This doesn't take
into account if we were to use a more complex request class than the one
that is stubbed out.

By using webtest to make these requests we allow them to perform the
full webob traversal that they would in a real web request situation.

Change-Id: I37c0b48a8d564dcd4aee59b86e50f374f5b60531
2016-01-08 15:03:20 +11:00
Brant Knudson 1757f5b0e4 Use assertIn to check if collection contains value
The output in the case of failure will be more usable.

Change-Id: If21627493fc2bfc7d0c2407be4110224b0f8e810
2016-01-08 11:01:37 -06:00
april b31c09d500 Wrong usage of "an"
Wrong usage of "an" in the message:
"backend DB for mapping an user or a group"
Should be :
"backend DB for mapping a user or a group"

Change-Id: I3934b2749481cb9adab2bc460991f00ef32ac9fa
2015-12-31 01:36:00 +08:00
Sean Perry df360b8ca0 Use unit.new_project_ref consistently
Replace all hand created project refs with calls to new_project_ref().
In unit tests, rename 'tenant' variables to 'project' where appropriate.
Change-Id: Id6d0462ba527c6950db1d25f19cb25dfaf01a002
2015-11-30 19:31:50 +00:00
Steve Martinelli cbefe7c7b8 Move federation extension into keystone core
Remove federation as an extension and move it to a core resource.
For now we leave the database migrations in the extension directory
until we have a general policy for merging these into core.

Some instances of federation constants were removed because
they were causing a circular dependency, these can be refactored in
a later patch.

DocImpact: You should no longer run the migrations for this extension
Implements: bp move-extensions

Co-Authored-By: Nithya Renganathan <narengan@us.ibm.com>

Change-Id: If5857a6ee4c7c527929069b25beab40f4c5d87e2
2015-11-18 15:11:30 +00: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
Sean Perry b69f6d728f Use unit.new_group_ref consistently
Replace hand created refs and local class methods with unit.new_group_ref().

Change-Id: I6dd11aac1de55bba3309f9547d8e6f66fe7a792e
2015-11-12 10:15:14 +00:00
Sean Perry 160f943148 Use unit.new_role_ref consistently
Replace all hand created role refs with calls to new_role_ref().

Change-Id: I1392d2ff469a29266f8ede1b9f132756c9ec03c4
2015-11-12 10:15:03 +00:00
Sean Perry 4e4003da5c Use unit.new_domain_ref consistently
Replace all hand created domain refs with calls to new_domain_ref().

Change-Id: I211370cd26339c6218313f44d44f90dbd07478f0
2015-11-12 10:14:50 +00:00
Jamie Lennox f8728a218d Use deepcopy of mapping fixtures in tests
dict.copy() only performs a shallow copy of a dictionary. So by
modifying it after a copy you're still modifying the original dict.
Change this to do a deep copy so we don't mutate the fixtures.

I had not come across anywhere where this caused a problem, just
something I saw.

Change-Id: I9a1284a9bab2a9d0be74abac9931c4a81f583d6d
2015-10-01 12:50:06 +10:00
Jenkins 41f9e16eb7 Merge "Refactor: Don't hard code the error code" 2015-09-14 01:58:49 +00: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
Brant Knudson 93b7f95625 Change tests to use common name for keystone.tests.unit
In several test files, the keystone.tests.unit import was aliased as
tests. This made it difficult to do global renames. 

Change-Id: I1e4798c76d53f265b921ef26e2a0141fc504ce69
2015-09-04 18:21:42 +00:00
chioleong efbc57e593 Tokenless authz with X.509 SSL client certificate
Implemented middleware to map an incoming trusted SSL client certificate
into Keystone auth credential so we can perform authorization without
having to issue a token.

TODO: to submit a separate patch to devstack to enable this feature.

Co-authored-by: guang-yee <guang.yee@hp.com>

SecurityImapct
DocImpact
implements bp keystone-tokenless-authz-with-x509-ssl-client-cert

Change-Id: Icc7305ca9d96f8e9cdc95ccde57de650801c6544
2015-09-02 15:10:31 -07: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