Commit Graph

201 Commits

Author SHA1 Message Date
sunyonggen f6a0cce440 OAuth 2.0 Mutual-TLS Support
The OAuth2.0 Access Token API is modified, support to get an OAuth2.0
certificate-bound access token from the keystone identity server with
OAuth 2.0 credentials and Mutual-TLS certificates.

Co-Authored-By: Hiromu Asahina <hiromu.asahina.az@hco.ntt.co.jp>
Change-Id: I885527bec61429b1437a046097a16491848b5a0a
Implements: blueprint support-oauth2-mtls
2023-03-03 11:28:05 +09:00
Zuul 2c10eff409 Merge "using standard library secrets function token_bytes to replace os.urandom" 2022-02-11 18:43:39 +00:00
Stephen Finucane 36f2ee58d5 Add 'StandardLogging' fixture
Another fixture taken wholesale from nova. This configures our logging
to ensure we trigger but don't capture DEBUG-level logs. It also lowers
the level of some less important logs like sqlalchemy-migrate.

Change-Id: Ia1090f1810d6cddda724a8a048647b4ffeaa733e
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2022-01-10 18:31:09 +00:00
Stephen Finucane 771c943ad2 Add 'WarningsFixture'
This duplicates what exists in nova and various other projects. The
important difference between this and what we're doing currently is that
it *restores*, rather than reset, the warning filters. There are more
various warning filters pre-configured in a typical Python environment,
including a few from third-party libraries such as requests [1][2] and
urllib3 [3] as well as stdlib [4]. By calling 'warnings.resetwarnings', we
*reset* all the warning filters [5]. This is clearly not something we want to
do, and resulted in tests puking warnings after the initial test run.

[1] https://github.com/psf/requests/blob/v2.26.0/requests/__init__.py#L127
[2] https://github.com/psf/requests/blob/v2.26.0/requests/__init__.py#L152
[3] https://github.com/urllib3/urllib3/blob/1.26.7/src/urllib3/__init__.py#L68-L78
[4] https://docs.python.org/3.8/library/warnings.html#default-warning-filter
[5] https://docs.python.org/3.8/library/warnings.html#warnings.resetwarnings

Change-Id: Ia2046dc32e3ac270b1dbcf2fe540104c1a8d95d8
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2022-01-05 18:29:43 +00:00
linjiang 0b64050e6b using standard library secrets function token_bytes to replace os.urandom
token_bytes is an standard library secrets function ,we can get the information from link https://www.python.org/dev/peps/pep-0506/

Change-Id: I7e6b1df5eac59bac33674934d7b3e8cdd16cea27
2022-01-03 19:16:29 +08:00
Zuul 52e3b92da7 Merge "fix E741 ambiguous variable name" 2021-09-30 20:07:31 +00:00
Mike Bayer 11cfc38df1 Ignore oslo.db deprecating sqlalchemy-migrate warning
In I59335b4f318bae2e29ab139cdea089a4d6e14305, oslo.db
is now emitting deprecation warnings for SQLAlchemy-migrate
functions.  This breaks Keystone tests which raise on
DeprecationWarning, so add to the filters.

Change-Id: I42f0abc2ddf8c53239d5098d5f32b667314b942d
2021-01-26 12:33:56 -05:00
Maurice Escher ddd06618ac
fix E741 ambiguous variable name
Change-Id: I8bf3fcc764542783a792ef3b691c71df9beeda18
2021-01-06 15:45:39 +01:00
Hervé Beraud 2844a38f7f Stop to use the __future__ module.
The __future__ module [1] was used in this context to ensure compatibility
between python 2 and python 3.

We previously dropped the support of python 2.7 [2] and now we only support
python 3 so we don't need to continue to use this module and the imports
listed below.

Imports commonly used and their related PEPs:
- `division` is related to PEP 238 [3]
- `print_function` is related to PEP 3105 [4]
- `unicode_literals` is related to PEP 3112 [5]
- `with_statement` is related to PEP 343 [6]
- `absolute_import` is related to PEP 328 [7]

[1] https://docs.python.org/3/library/__future__.html
[2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html
[3] https://www.python.org/dev/peps/pep-0238
[4] https://www.python.org/dev/peps/pep-3105
[5] https://www.python.org/dev/peps/pep-3112
[6] https://www.python.org/dev/peps/pep-0343
[7] https://www.python.org/dev/peps/pep-0328

Change-Id: I2f9d2114b2c5eb66f241646f1896ea17a160e3f3
2020-06-02 20:20:37 +02:00
Vishakha Agarwal 51ecd5e959 Removes info about deleted function should_cache_fn
should_cache_fn function is removed from keystone when oslo_cache
was adopted. A function still mentions about it. This patch updates
the doc string mentioning about should_cache_fn.

Change-Id: Ib9693f1c020e0ed251d4119c0fbf8ffef693102a
2020-04-28 17:35:58 +00:00
Andreas Jaeger f36111954b Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Fix problems found.

Update local hacking checks for new flake8.

Change-Id: Ic440219814ee0c2b98217e9a821f38f5baf482ec
2020-04-15 07:17:58 +02:00
Mike Bayer a183badaa4 Ignore SQLAlchemy RemovedIn20Warning
SQLAlchemy 1.4 will be introducing a new warning
class called RemovedIn20Warning, which will indicate behaviors
and APIs that are planned on being changed for the
SQLAlchemy 2.0 release [1].  As SQLAlchemy 2.0 is planned on
being a more major API break, applications will normally need
to wait until they are fully on SQLAlchemy 1.4 only as well as
Python 3 only in order to begin using new APIs that will allow
migration to 2.0.

For now, Keystone and others don't have a need to be raising
for this warning as there are not yet clear upgrade paths
established.

[1] https://docs.sqlalchemy.org/en/14/changelog/migration_20.html#sqlalchemy-1-x-to-2-0-transition

Change-Id: Icb005b2e7b9d851f5a3e8677599b32a6e3edddc2
2020-03-03 13:32:19 -05: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
Zuul 4bebe75a1e Merge "Implement resource options for roles and projects" 2019-09-13 13:49:57 +00:00
Vishakha Agarwal cc40014ec8 Implement system reader & member for domain config API
This change modifies the policies for domain config
API to be more self-service by properly checking for
system scopes. It also includes the test cases.

Subsequent patches will -

 - add functionality for system admin for domain config API
 - domains user test coverage for domain config API
 - project user test coverage for domain config API
 - Removing obsolete policies in policy.v3cloudsample.json file

Change-Id: I3c0a00d3fb77485f3e303f4ce5f90a7ea4301563
Partial-Bug: #1805366
2019-09-11 15:23:22 +05:30
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 e4fb1e1fdd Implement system reader and member for endpoint_groups
This change modifies the policies for endpoint_groups
API to be more self-service by properly checking for
system scopes. It also includes the test cases.

Subsequent patches will -

 - add functionality for system admin
 - domains user test coverage
 - project user test coverage
Change-Id: Ie13fd2296f2836466d38544c4f672ee95c4156b0
Partial-Bug: #1818734
2019-08-19 17:00:15 -07:00
Zuul db3264e81f Merge "Remove [signing] config" 2019-07-26 18:41:19 +00:00
Vishakha Agarwal b836aa221c Remove [signing] config
Since pki-setup was removed in pike.This
patch removes the config options that were
left for backward compatibility, as PKI is
not supported.

Partial-Bug: #1829453
Change-Id: I83cd08e57fbc046ad69bd42eb2e5fa1ace6e8a28
2019-07-23 12:45:43 +00:00
Guang Yee 52da4d0e12 implement system scope for application credential
Implement system scopes, namely 'admin', 'reader', and 'member' for
the application credential API. Thus, making it consistent with other
system-scoped policy definitions.

For the application credential API, the follow policies will be enforced:

- system admin can fetch, list, lookup, and delete user's application
  credentials.
- system member and reader can only fetch, list, and lookup user's application
  credentials. Deleting a user's application credential other their own is
  strictly prohibitted.
- domain and project admins can no longer touch user's application credentials
  other their own.
- domain and project readers cannot touch user's application credentials
  other their own.
- domain and project members cannot touch user's application credentials
  other their own.
- create an application credential can only be done by the owner. No one else
  can create an application credential on behalf of another user.

Test cases are added to guard the above policy changes.

Change-Id: I26ee11571b6d0f700a5fe3a62ad2e8fc7f5316fe
Closes-Bug: 1818725
Closes-Bug: 1750615
2019-07-19 17:53:16 -07:00
Zuul a0f31d14bb Merge "Add domain level limit support - API" 2019-03-01 12:28:18 +00:00
wangxiyuan df173c7c90 Add domain level limit support - API
Add domain_id parameter for limit creation API

bp: domain-level-limit
Change-Id: I9f3d999f5f07fbb6bdbaf9410e15efefae19d262
2019-02-19 11:09:13 +08:00
Colleen Murphy 431e5a81b3 Fix mock for v2 test
In 7eec2c5d we removed the _VERSIONS constant from the api discovery
module. By a quirk of the way the unit tests are ordered, the mock to
patch this constant continued to work if the whole test suite was run,
but it doesn't work if we just run that test alone or the test_versions
suite alone. This patch cleans up the unneeded mock.

Change-Id: If88db5b8f4cb3425fd7a568213aa094fe7800c38
2019-02-17 16:56:33 +01: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
Lance Bragstad cb5a1fe036 Move test utility to common location
Several of the test clases for testing the service provider API were
duplicating a method to build a request body. Instead of duplicating
a common and useful utility, we can move it to a generic place and
share it.

This commit creates a new method in keystone.tests.unit.core for
building service provider entities to be used in API and backend
tests. A subsequent patch will rely on this for testing policy
protection of the service provider API.

Change-Id: I78e697f9f5fb975b4694ab1a61f608a6dce0fd3b
2018-11-28 14:53:30 +00:00
wangxiyuan 4e9f223874 Remove "crypt_strength" option
This option was deprecated in Pike. It's used no where now. Safe
to remove it.

Change-Id: I48a962488e25c07aea3a53f6aaa9b5f4a4218e4a
bp: removed-as-of-stein
2018-11-12 10:37:22 +08:00
Adrian Turjak d9e6c1d4dd Implement auth receipts spec
Adds a new model and provider for receipts which are
very similar to tokens (fernet based), and share the
same fernet mechanisms.

Adds changes to the auth layer to handle the creation,
validation, and consumptions of receipts as part of
the auth process.

Change-Id: Iccb6e6fc7aee57c58a53f90c1d671402b8efcdbb
bp: mfa-auth-receipt
2018-11-02 15:06:19 +01:00
Lance Bragstad 8543dbbc2c Move loadapp to a generic place
This commit moves loadapp to BaseTestCase so that it can be
used by test classes inheriting from BaseTestCase without having
to invoke all the extra stuff from TestCase.

Change-Id: Ida1e7b65a5d88e03701fe0334155f1eb5d03ae86
2018-10-12 16:53:02 +00:00
Lance Bragstad a394558dc4 Make policy file support in fixture optional
The ksfixtures.Policy object used to accept two arguments. One was
the path of the policy file and the other was the test fixture. Since
policy is now kept in code and the default policy file has been
removed from keystone source, we can simplify the fixture to
optionally deal with a file path, instead of passing a non-existant
file to it all the time.

Change-Id: I9d8c4cbf963099fe73e39dbf46e03f66f9a79f43
2018-10-12 16:39:24 +00: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
Zuul 31333131e0 Merge "Properly replace flask view args in links" 2018-10-02 22:16:35 +00:00
Morgan Fainberg 1efecc92c0 Properly replace flask view args in links
When the API Prefix is used in a Flask API, it is possible the flask
view argument specification will bleed through to the self link instead
of a properly formated url.

The add_self_reference_links mechanism in keystone.server.flask.common
now substitutes out the self link to the {} substitution and applies
a .format() utilizing the view args to the URI in the self link.

Change-Id: Ic5c89c285ed964de7411b273567bb97fcf43da06
closes-bug: #1794552
2018-09-28 13:42:24 -07:00
wangxiyuan 46a28313fc Enable Foreign keys for sql backend unit test
Enable the sqlite foreign keys function for unit test.

This patch is the first part to solve sql backend test issues.

Change-Id: I5d29d05e64b76ff6530c9af5ee39a2df1b26aa03
Partial-Bug: #1744195
2018-09-26 17:36:01 +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
Zuul 9ee900e892 Merge "Move Credentials API to Flask Native" 2018-07-20 06:51:07 +00:00
Morgan Fainberg cb130ffae8 Move Credentials API to Flask Native
Move the Credentials API to Flask Native dispatching.

This change fixes some circular importing in the
conversion.

Change-Id: I5e2485ba471d09c3454e78ca2c9dfa19aaf0e4e2
Partial-Bug: #1776504
2018-07-16 21:58:21 -07:00
Zuul 19e28d0cd3 Merge "Flesh out and add testing for flask_RESTful scaffolding" 2018-07-16 21:44:19 +00:00
Morgan Fainberg 16be22b428 Flesh out and add testing for flask_RESTful scaffolding
Add in support for JSON Home documents, a ResourceBase implementing
basic functionality, and full testing of the new flask_RESTful
scaffolding.

Change-Id: I5bcc8660b68c0b39a2110089f6c67531769d14ef
Parital-Bug: #1776504
2018-07-12 15:08:19 -07:00
Morgan Fainberg b77b5845d5 Address minor comments to 404 error detection
Addressing minor comments to the 404 detection mechanism.

Change-Id: Id8e2b5d5f811495694965d75a32eebb2a59779f2
Partial-Bug: #1776504
2018-06-29 14:24:45 +00:00
Morgan Fainberg 1bcc8a11c8 Make it easy to identify a 404 from Flask
This change makes (for test purposes) the Flask app return a 418
instead of a 404 if the path is unrouted. This allows easy
identification (programmatically) if the 404 is issued from Flask
or is a handled 404 such as "UserNotFound"

Parital-Bug: #1776504
Change-Id: I0475d9b6315250d9c3384be63c14a81fbd1c7b7c
2018-06-27 09:58:35 -07:00
Morgan Fainberg 3e3ba18bfa Convert json_home and version discovery to Flask
Move the JSON Home Document and Version Discovery Documents out of
the webob-based mapper and into Flask.

This change removes the keystone.version.controller and
keystone.version.router modules as they have been moved into
keystone.api.discovery.

The keystone.api.discovery module is somewhat specialized as there
are no "resources" and it must handle multiple types of responses
based upon the ACCEPTS header (JSON Home or JSON). In lieu of the
flask-RESTful mechanisms, keystone.api.discovery utilizes bare
flask blueprint and functions. Minor scaffolding work has been done
to ensure the discovery blueprint can be loaded via the loader loop
in keystone.server.flask.application (a stub object in
keystone.api.discovery).

Partial-Bug: #1776504
Change-Id: Ib25380cefdbb7147661bb9853de7872a837322e0
2018-06-27 09:58:35 -07:00
Morgan Fainberg f18d54fe16 Store JSON Home Resources off the composing router
JSON Home Resources must be stored in a location other
than the router for Flask as we are not composing routers
in the same way as we used to with the home-grown webob
based WSGI setup.

Partial-Bug: #1776504
Closes-Bug: #1776506
Change-Id: I292ea9e923ff2f49041dfd417994bcdd797d0520
2018-06-14 10:18:57 -07:00
Morgan Fainberg 8bf335bb01 Remove pastedeploy
This patchset removes the lingering code that supported paste.deploy
that is obsolted by the loader wrapped around keystone's use of Flask.

 * The keystone-paste.ini file has been removed.

 * All options have been removed (without deprecation) as they are no
   longer referenced.

 * The TokenAuthMiddleware code (with deprecation warning) has been
   removed as it was only provided to ensure compatibility with paste.ini
   files that were not updated (ensuring not breaking a deployer that
   did not update paste.ini file to remove it from the pipeline).

 * Paste deploy entrypoints have been removed.

Change-Id: I35064a440ef718f50c7e644e8b2d56a99c3ec74f
2018-06-06 19:30:26 +00:00
Morgan Fainberg 4ec6bc5a44 Convert Keystone to use Flask
Basic conversion of Keystone's core application to flask framework.

This doesn't add much in the way of flask-specific-isms but should
get keystone running directly under flask. This implementation does
not use paste-deploy.

Change-Id: Ib4c1ed3f645dd55fbfb76395263ecdaf605caae7
2018-06-04 20:14:41 -07:00
Zuul a611f4803f Merge "Limit description support" 2018-05-17 04:44:36 +00:00
wangxiyuan 0ebe420b68 Remove token driver configuration
The "driver" configuration should be removed with the removal of
uuid token. Keystone now doesn't support persistence token.

Change-Id: Ibea6660cd85c07abc9c4bc011180c08dd5017ced
bp: removed-as-of-rocky
2018-05-10 11:28:16 +08:00
wangxiyuan 9d7ffbc89e Limit description support
This patch added description support for registered
limit and project limit.

Closes-Bug: #1754185
Change-Id: Ia2023ca809b8c2f58af648cb7377f41cd220725b
2018-05-08 10:59:41 +08: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