Commit Graph

131 Commits

Author SHA1 Message Date
Pete Zaitcev 1544c7fc0a Don't forget to check if authorization fails
The fix is to copy the missing check from class AuthProtocol
of keystonemiddleware.

Closes-bug: 1999068
Change-Id: I4fd7bf6b194c38815c2a9cdbab92a07315397eab
2023-03-17 16:54:41 -05:00
Yi Feng b554576f62 OAuth2.0 Client Credentials Grant Flow Support
The OAuth2.0 Access Token API is added, support to get an OAuth2.0
access token from the keystone identity server with application
credentials.

Change-Id: I4c54649a51534637be831450afc32d3ef8644ee5
2022-06-14 09:09:33 +00:00
Takashi Kajinami d9cd6b7347 Replace deprecated assertDictContainsSubset
The method is deprecated since Python 3.2[1] and shows the following
DeprecationWarning.

/usr/lib/python3.9/unittest/case.py:1134: DeprecationWarning:
assertDictContainsSubset is deprecated
  warnings.warn('assertDictContainsSubset is deprecated',

[1] https://docs.python.org/3/whatsnew/3.2.html#unittest

Closes-Bug: #1938103
Change-Id: I2372c6f1c748a5cb1c3fcf0566684f49bc5ef715
2021-09-01 08:13:48 +09:00
Ghanshyam Mann 256160b849 [goal] Deprecate the JSON formatted policy file
As per the community goal of migrating the policy file
the format from JSON to YAML[1], we need to do two things:

1. Change the default value of '[oslo_policy] policy_file''
config option from 'policy.json' to 'policy.yaml' with
upgrade checks.

2. Deprecate the JSON formatted policy file on the project side
via warning in doc and releasenotes.

Also replace policy.json to policy.yaml ref from doc and tests.

[1]https://governance.openstack.org/tc/goals/selected/wallaby/migrate-policy-format-from-json-to-yaml.html

Change-Id: Ic65d2fd6ce7215b4a47a6fb41b9cbf991f27773b
2021-02-01 17:36:29 +00: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
Colleen Murphy c2d8830662 Fix role_assignments role.id filter
Without this patch, if there are multiple role assignments on the system
and they are not all the same role, querying for role assignments with
/v3/role_assignments?role.id={role_id} may leak some role assignments
that don't match the role_id, making the returned results incorrect.
This patch fixes the issue by using a list comprehension instead of a
for loop over a list that was being modified within the loop.

Change-Id: Icfce3b14abb55c6fef3de1b314cee22fc8b1d08c
Closes-bug: #1858012
2020-01-02 09:24:54 -08:00
morgan fainberg b31ff3f991 Implement resource options for roles and projects
Add in support for resource options for roles and projects (including
domains). No options are currently implemented for roles or projects.
Scaffolding has been implemented so that adding options should be
straight forward. This will allow for implementing options such
as an immutable flag.

As a mechanism to isolate SQL Models from the Driver implementation
especially when adding in complexity of the resource options, the
models for the Resource backend and the Role Backend (SQL) have been
move to their own module.

Partial-Bug: #1807751
Depends-On:  https://review.opendev.org/678379
Required-By: https://review.opendev.org/678380
Change-Id: I456a7c19506d28d5846534f884b8abe0d3079c96
2019-09-09 22:07:30 +00:00
Vishakha Agarwal 0931f08cd3 Correcting tests with project_id
This change replace tenant_id to project_id
in test cases.

Change-Id: I6285d8e4f1b90a8c3f299f4b1d186f2453a3f9b7
2019-02-13 14:32:19 +05:30
Vishakha Agarwal df982016dd Remove deprecated "bind" in token
The 'bind' option was deprecated and is
in no use now, thus removing it. Also
removing its rst file.

bp:removed-as-of-stein
Change-Id: Ie355733dc031b3c4908fdc4e44f8f1220cff456c
2018-11-09 07:22:52 +05:30
Zuul 5814da527b Merge "Move AuthContextMiddleware" 2018-10-22 03:33:22 +00:00
Lance Bragstad 6d7cfdb4ba Add test case for expanding implied roles in system tokens
If a user has a role assignment on the system, which implies another
role assignment, the system-scoped token response should include
both role assignments.

This patch exposes a bug in the system-scoped token implementation
where implied roles aren't expanded out before returning the
token response to the user.

Change-Id: I176bbbda9658a54f6873a4009938f140a5b1a33e
Related-Bug: 1788694
2018-10-12 16:53:25 +00: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 d97832e8e8 Convert auth to flask native dispatching
Convert the /auth paths to flask native dispatching.

A minor change to additional_urls was implemented to ensure all
urls are added at once instead of individually (causing an over-
write issue within flask as a single resource may only have a
single set of URL mappings).

Alternate URLs now support adding alternate JSON Home rel links.
This is to support the case of OS-FEDERATION auth routes moving
to /auth. The old JSON Home entries must exist but reference
the new paths.

This port includes the following test changes (needed due to the
way flask handles requests and the way requests are passed through
the auth system):

* Implemented keystone.common.render_token (module)
  containing render_token_response_from_model and use it instead
  of keystone.common.controller.render_token_response_from_model.

  Minor differences occur in render_token_response_from_model in
  the keystone.common.render_token module, this is simply
  for referencing data from flask instead of the request object.

* Test cases have been modified to no longer rely on the auth
  controller(s) directly

* Test cases now use "make_request" as a context manager
  since authenticate/authenticate_for_token directly
  reference the flask contexts and must have an explicit
  context pushed.

* Test cases no longer pass request objects into methods
  such as authenticate/authenticate_for_token or similar
  methods on the auth plugins

* Test cases for federation reference the token model now
  where possible instead of the rendered token response.
  Rendered token responses are generated where needed.

* Auth Plugin Configuration is done in test core as well.
  This is because Auth controller does not exist.

NOTE: This is a massive change, but must of these changes
were now easily uncoupled because of how far reaching auth
is.

Change-Id: I636928102875760726cc3493775a2be48e774fd7
Partial-Bug: #1776504
2018-10-09 23:23:03 -07:00
wangxiyuan 012dac29b8 Enable foreign keys for unit test
The unit test uses sqlite for test which closes db foreign keys
function by default. This patch enabled the sqlite foreign keys
function for unit test by default.

The "project" table is a self referencing FK table(id <-> domain_id
column). So when the FK is enabled, there must exists a root record
before insert data to this table. It's <<keystone.domain.root>>.

Usually, the <<keystone.domain.root>> recored is inserted into the
table once operators run "keystone-manage db_sync" command when
deploy Keystone. But the unit test code doesn't run this command,
it initialise the db schema by reading sqlalchemy object model, so
the <<keystone.domain.root>> record is missed. Then we can't create
any project record, it'll raise FK error.

So in this patch, before creating any projects in the test, we must
ensure the <<keystone.domain.root>> record exists first.

Change-Id: I565d12395ca39a58ba90faf8641a9e02d986aeb9
Closes-Bug: #1744195
2018-10-09 09:50:21 +08:00
Vishakha Agarwal 84e1b9ac15 Avoid using dict.get() in assertions
The method dict.get(key) will return None
in the following two cases:

A. if there is no key in the dictionary.
B. if the real value of the key is just None.

The above two cases will results in passing
the assertion which is not the expected
behaviour of the test.

Change-Id: Ib4a7f2d5beb1e4e9b4d8d9dd90de3f52a5c29e74
2018-10-05 00:12:06 +00:00
Zuul 785ec01833 Merge "Added support for a ``description`` attribute for Identity Roles" 2018-09-12 17:56:20 +00:00
M V P Nitesh 430d7f765a Added support for a ``description`` attribute for Identity Roles
Now user can add the description to the role when user creates the role.
Added support for a ``description`` attribute for V3 Identity Roles.

Co-Authored-By: wangxiyuan<wangxiyuan@huawei.com>
Co-Authored-By: Deepak Mourya<deepakmoriya7@gmail.com>
Change-Id: I230af9cc833af13064636b5d9a7ce6334c3f6e9a
Closes-Bug: #1669080
2018-09-06 05:09:10 +00:00
Lance Bragstad 25a5d48d1c Trivial: Remove app_conf kwarg from testing setup
The RestfulTestCase classes in both rest.py and test_v3.py both
defined an app_conf kwarg in their setUp() method signatures that
was never used. This commit removes app_conf since it doesn't make
sense to define it if it's not used.

Change-Id: Ide8303363c662747e1527f7de553dba40606986e
2018-08-22 17:34:32 +00:00
wangxiyuan 203787c37f Clean up token extra code
Originally, the "extra" in token data is generated by auth plugin
and then will be return to users within token data.

In Kilo, the "extra" in token data was deprecated[1], after that
if the auth plugin generate the "extra", a warning log will be
raised. To stop the warning, the auth plugins should stop
generating "extra" field.

After two releases, in Mitaka, the "extra" in token data was
removed[2], but the "extra" was still created by default as an
empty dict {}. Actually, "extra" should not be created any more
in Mitaka because Keystone has warned the auth plugins for two
releases.

Now in Rocky, it's safe enough to remove the "extra" from token
issue flow at all since it has never been used from Mitaka. The
only concern for the out tree plugins about the removal is that
if they still put "extra" into auth_context, Keystone will raise
KeyError. But can it be happened? Only if the out tree plugins
ignore the warning in Kilo, and still contain "extra" but never
use them from Mitaka. For most auth plugins which follow the
Keystone deprecation step, this patch is a silent change.

[1]: https://review.openstack.org/#/c/162662
[2]: https://review.openstack.org/#/c/249480

Change-Id: I828cc0ad3ac265abdfea2e1571806add128ae51e
2018-08-02 11:52:10 +08:00
Morgan Fainberg 6dbd005842 Remove direct calls to auth.controllers in some tests
Tests in keystone.tests.unit.test_v3 and kestone.tests.unit.test_v3_auth
no longer directly instantiate or calls to the auth controllers. The
only exception are test classes that are not used, those have had a
TODO note added to them. This is being done for the conversion to flask
where the auth controllers will no longer exist. All test changes are
done outside of the conversion of webob controller -> flask restful
api.

Change-Id: Ib668ca18faf42b41bc63558c6634fca96224d195
Partial-Bug: #1776504
2018-08-01 16:57:23 +00:00
Morgan Fainberg 142b224920 Mirror self-link trust check from tempest
To ensure the self-link for trusts is sane, mirror the check tempest
does. This change closes a gap on a possibly changing self-link
that would only be caught in tempest making for easier local testing.

Change-Id: I1ede6dcafdeb75b94732efe0d4c80ccfef2a40f0
Partial-Bug: #1776504
2018-07-20 14:57:12 -07:00
Lance Bragstad b0cc66e2a8 Remove unused assertions from test_v3.py
These assertions are not used anywhere in keystone's tests. The
assertion for service providers was added but never used:

  I62ec9619d8b187cda80100e383d40b158550b71f

The token assertion was no longer used when we removed the v2.0
token API as noted in the commit message of:

  I4c3e35f3565b4b60ae4d00cc2490bd04aba1a800

Change-Id: If28273c88518df0ba6b75a98f13f123bee574fb5
2018-05-03 21:13:08 +00:00
Brant Knudson 96a883a5ad Use consistent role schema in token response validation
The tests used a different schema for the roles in the token
response schema for different token scopes. The role information
shouldn't change depending on the scope, so let's make the test
more DRY by not redefining the role schema in multiple places.

Related-Bug: 1763510
Change-Id: I58d3dc2a3306994890688d5ff40a62cdaedf378e
2018-04-12 21:23:40 +00:00
David Stanek ed2b65a5dd Force SQLite to properly deal with foreign keys
This will help with testing since SQLite will start enforcing the
foreign key relationships.

We will still have a problem with migrations for tables that refer to
each other. SQLite can't alter tables and sqlalchemy-migrates tmp table
strategy for migrations fails in this situation.

This patch did:
1. Add FK support for the tests. Disable it by default.
2. Make sure the Fk is disabled for test_sql_upgrade and
identity.backens.test_sql

Partial-Bug: #1744195

Co-Authored-By: wangxiyuan<wangxiyuan@huawei.com>
Change-Id: I276af7c0125dc2cb2c54215d54491665db1caa22
2018-02-14 16:54:15 +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
Lance Bragstad 19a2ccb51e Introduce assertions for system-scoped token testing
This commit consists of some utilities that we can use when testing
system-scoped tokens. A subsequent patch will use them when
implementing the tests.

bp system-scope

Change-Id: If011ff7630cda1f7330a7657dd8e6249f0af5442
2018-01-23 13:50:20 +00:00
Lance Bragstad 086dd2738b Implement controller logic for system group assignments
This commit wires up the remaining bits to expose system role
assignments for groups via the assignment API.

bp system-scope

Change-Id: I5051aa97dbecb88ee706749b26a4140f9798e084
2018-01-12 16:25:03 +00:00
Lance Bragstad 410a8f691f Implement controller logic for system user assignments
This commit wires up the remaining bits to expose system role
assignments via the assignment API.

bp system-scope

Change-Id: Ie17a473c12c9a67bbc5b26f18d8b29e8ad4529d2
2018-01-10 21:54:56 +00:00
Zuul 6a1136cc60 Merge "Replace parse_strtime with datetime.strptime" 2017-12-26 21:48:29 +00:00
Gage Hugo 7e102514c7 Replace parse_strtime with datetime.strptime
This change switches the use of parse_strtime to datetime.strptime since
oslo.utils parse_strtime simply calls strptime from the datetime library[0],
which keystone already uses.

[0] https://github.com/openstack/oslo.utils/blob/master/oslo_utils/timeutils.py#L97

Change-Id: I9d428d16bfe5ed83a9ff441725c293576a11e09d
2017-12-21 12:14:28 -06:00
wangqiangbj 4fc045f820 remove "admin_token_auth" related content"
as "admin_token_auth" is removed from paste file. some related contents
are useless and shoud be removed also.

Change-Id: Ia2263eda93559603a31d9a492e5501424613188e
bp: removed-as-of-queens
2017-12-18 17:02:34 +08:00
Adam Young f71a78db86 Enforce policy on oslo-context
Up to now, middleware/auth.py was overwriting the oslo
context generated from keystonemiddleware with a
dictionary that simulated the values of
oslo-context directly pulled out of the token.

As oslo-context gains logic, Keystone has started
to diverge from the rest of the projects that use
oslo-context.

Change-Id: Ie93392f8aabddf8c963b9cb08aaa006d28d37e22
2017-12-05 03:37:32 +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
David Stanek 3432685a1e Remove orphaned AuthTestMixin from test_v3
The code was moved to keystone.tests.common.auth and later
modified. The class in keystone.tests.unit.test_v3 is no
longer being used.

Change-Id: Ib89046b4c991d319c03ecd7dddf452dd315e1aad
2017-03-28 21:18:01 +00:00
Tim Burke 3ec1aa4c19 Fix the s3tokens endpoint
This was broken when issue_v2_token was removed, and no one noticed
because there are no tests.

The good news is, Swift3 is content to move toward supporting the
v3 format, so just start inheriting from the v3 controller.

Change-Id: I5d0c18121ba4bf8e33209daa48b9d87864951362
Related-Change: I7d3b583cbec9a095ab8cc20c5d6c0a6127e37068
Related-Change: I747de516ab69a47622eecbf8ab3faa34444b3ad5
2017-02-22 16:16:06 +00:00
Morgan Fainberg 29951be748 Cleanup TODO, AuthContext and AuthInfo to auth.core
Moved AuthContext and AuthInfo to keystone.auth.core as they are shared
code bits and not exclusively controller specific.

Change-Id: I649690d9e39057249e674500d85a053e0c28b30e
2017-01-31 16:52:41 +00:00
David Stanek dce8a2c11e Fixes deprecations caused by latest oslo.context
In oslo.context 2.12.0 a number of things used by keystone
were deprecated. This causes the keystone tests to fail
since we treat deprecation as errors.

Change-Id: I885431ba957909e709648e03a05bc280441ffbf5
2017-01-27 22:37:51 +00:00
Morgan Fainberg 0f3f08c3df Force use of AuthContext object in .authentcate()
Force the keystone.auth.controllers.Auth.authenticate method to
require the use of an AuthContext object instead of something
duck-typed (dictionary). This is done to ensure the security and
integrity of IDENTITY_KEYS are covered and values are not changed
by a plugin due to the security built into AuthContext being
circumvented since it was not used. This is not pythonic, this
is being done for hardening purposes.

Change-Id: I013846af59587d17b15ca4cf546e6372231f576e
Closes-Bug: #1656076
2017-01-13 17:29:23 +00:00
Samuel Pilla 812982a45f Domain included for role in list_role_assignment
When calling list_role_assignment and including the "include_names"
parameter, it would return the domain name and ID for each party
except for roles.

This will return the domain name and id for roles when the parameter
is included, if the role has a domain.

Added tests for roles with domains at manager and API level.

Co-Authored-By: Samuel de Medeiros Queiroz <samueldmq@gmail.com>

Closes-Bug: #1607114

Change-Id: I5dae9299522b5116f8530455dd3d3376e9597b52
2016-12-06 10:26:13 -06:00
Brant Knudson 8002025375 Correct minor issues in test schema
The JSONSchema used to validate the token response had a couple of
issues:

- The domain property schema was wrapped in a domain property
- 'bind' in optional was always present already so no need to add it
  again.

Change-Id: I512e5a041c6ba96fbff71fac1bfdde02f888a582
2016-12-05 17:24:31 -06:00
David Stanek 4f12020e0e Removed unused EXTENSION_TO_ADD test declarations
The last use of the declaration was removed in
If38e8cc496cc1c3909bbb7fe4da89fa85bdc02f5, but those functions were
removed because they were not being used.

Change-Id: I76397ca655342403805ce655db8b722cc3f6878c
2016-11-29 17:06:34 +00:00
Ronald De Rose 02452d02c4 Return password_expires_at during auth
The new user attribute, password_expires_at, is not being returned
during auth; this patch adds it.

bp password-expires-validation
Change-Id: I1f17a849d9da4067d6be7d612c5a561bcb247ebb
2016-10-14 00:25:57 -04:00
Dave Chen ae0d189b13 Remove the check for admin token in build_auth_context middleware
The check has been deprecated since Mitaka release and the use of
admin token has been covered by admin_token_auth middleware.

bp removed-as-of-ocata

Change-Id: I24bddc942482288b85070a89b4c84084e6a5b337
2016-09-28 20:39:28 +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
Jenkins d082fb29ce Merge "PCI-DSS Password expires validation" 2016-08-09 10:40:20 +00:00
Steve Martinelli 6c408a0607 remove test utilities related to adding extensions
these functions are not used by any test, no need to keep them
around.

Change-Id: If38e8cc496cc1c3909bbb7fe4da89fa85bdc02f5
2016-08-05 21:16:17 -07:00
Ronald De Rose 041f53f2f6 PCI-DSS Password expires validation
This patch implements the following PCI-DSS requirements:

* PCI-DSS 8.2.4: Change user passwords/passphrases at least once every
90 days.

Once a user's password is expired, they will not be able to authenticate
and be required to reset their password. This patch adds a new
password_expires_at attribute to the user response.

Depends-On: I07c10de627898d6ac79578dc24292ded4a2190f1
Partially-implements: blueprint pci-dss
Change-Id: If8979dbfc202bc354b1537a5962143bb7b3be28e
2016-08-05 13:21:42 +00:00
Béla Vancsics ffd2fea754 Use more specific asserts in tests
Instead of assertTrue and assertFalse use more specific asserts.
They are compatible with Python 2.7[1] and 3.4[2]

[1]: https://docs.python.org/2.7/library/unittest.html
[2]: https://docs.python.org/3.4/library/unittest.html

Change-Id: Id9f73e90f0786ef7576edd2f97aa31b1503c14dd
2016-08-04 12:48:08 +02:00
Jamie Lennox e39486a15e Remove unused context from AuthInfo
The AuthInfo.context attribute is not used anywhere and all the testing
therefore just passes a None value rather than even try and provide real
values. Let's get rid of it.

Change-Id: I7b69b53915def44f531cbda80c875c7b9b114169
2016-07-15 10:07:36 +10:00