Commit Graph

328 Commits

Author SHA1 Message Date
Thomas Goirand b82269621d Python 3.12: do not use utcnow()
The datetime.datetime.utcnow() function is deprecated in Python 3.12,

Change-Id: I52e947e017ad1455c0310fe20fdc63354a254757
2023-12-19 00:45:48 +09:00
Zuul 9ade074c9b Merge "External OAuth2.0 Authorization Server Support" 2023-11-07 16:46:40 +00:00
Zuul e49893e598 Merge "External OAuth2.0 Authorization Server Support" 2023-09-13 18:32:57 +00:00
Yusuke Niimi 53b4cb21ad External OAuth2.0 Authorization Server Support
Added the ability to authenticate using a system-scoped token and the
ability to authenticate using a cached token to the
external_oauth2_token filter.

Implements: blueprint enhance-oauth2-interoperability
Change-Id: I1fb4921faaafd5288d5909762ff5553e5e2475dc
2023-09-07 09:43:14 +00:00
sunyonggen de15a610e1 External OAuth2.0 Authorization Server Support
The external_oauth2_token filter has been added for accepting or denying
incoming requests containing OAuth 2.0 access tokens that are obtained
from an External Authentication Server.

Depends-On: https://review.opendev.org/c/openstack/keystoneauth/+/860614
Implements: blueprint enhance-oauth2-interoperability
Change-Id: I529c5b0c89933395b126e86651ef09368dd7e6b4
2023-08-30 13:30:32 +00:00
Sahid Orentino Ferdjaoui 70337682d9 auth_token: fix issue when data in cache gets corrupted
Previously token cache was not correctly handling the case when data
in memcached is un-decryptable.
The cache process was returning a null value that was not considered
resulting a python exception raised

The commit fixes the issue by adding a condition to validate the value
returned.

Closes-bug: #2023015
Change-Id: Ic48d20569980781febc194083651736bed446953
Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@industrialdiscipline.com>
2023-08-14 14:42:50 +00:00
Stephen Finucane 22408f8da0 Remove six
Change-Id: Ib3edfdd087ed1d954f1ecf72a191138f8f1c46a1
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-06-27 18:03:31 +01:00
Stephen Finucane 0f48ff3e8d Bump hacking to 6.0.x
A note about dependency ordering is removed from the requirements file:
this is no longer true with the dependency resolver introduced with pip
20.3.

Change-Id: I615be3453db37588edf98a46ce484efc5e051f11
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-06-27 18:03:30 +01:00
Stephen Finucane 626df3a5e9 Make tox.ini tox 4.0.0 compatible/fix gate
* Removed skipsdist=True to make sure placement available in the virtual
  env. Without this, our entrypoints are not available.

* Removed basepython = python3 as we assume all developer switched to
  python3 in their env already

* Removed ignore_basepython_conflict = True as without the basepython
  definition generative targets now work without conflict

See [1] for a similar change made to placement.

It is also necessary to fix issues with the gate. For reasons that I
have yet to grok, a mock of 'requests.request' used in some test is no
longer functioning as expected. My guess is that something is now
importing requests before us and interfering with the mock but never
mind - we can easily bypass the issue by mocking 'requests.post'
instead.

[1] https://review.opendev.org/c/openstack/placement/+/868418/

Change-Id: I3b8263afbf0ccee88ceaac2040d5ad274f22d74a
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-06-27 18:03:28 +01:00
sunyonggen a59020fdab OAuth 2.0 Mutual-TLS Support
The oauth2_mtls_token filter has been added for accepting or denying
incoming requests containing OAuth 2.0 certificate-bound access
tokens that are obtained from keystone identity server by users
through their OAuth 2.0 credentials and Mutual-TLS certificates.

Co-Authored-By: Hiromu Asahina <hiromu.asahina.az@hco.ntt.co.jp>
Depends-On: https://review.opendev.org/c/openstack/keystoneauth/+/860614
Change-Id: I49127d845954ad6eab39e6e6305948ef0e4ed7b5
Implements: blueprint support-oauth2-mtls
2023-03-03 11:28:01 +09:00
Jorge Merlino e05466c5f4 Remove cache invalidation when using expired token
This can create a race condition for long running services that reuse
their token (eg. Kubernetes Cinder CSI plugin) in this case for
example:

1 [user] Asks nova to attach a volume to a server
2 ...the user's token expires
3 [user] Asks cinder if the volume has been attached
4 [nova] Asks cinder to attach the volume

In step 3 the token is marked as invalid in the cache and step 4 fails
even if allow_expired is true

Closes-Bug: #1987355
Change-Id: Ice8e34440a5fe1baa370646ed70b5e085c4af70e
2022-12-12 20:16:14 +00:00
Yi Feng f7ac6a1b24 OAuth2.0 Client Credentials Grant Flow Support
The oauth2_token filter has been added for accepting or denying
incoming requests containing OAuth2.0 client credentials access tokens
that are obtained from keystone identity server by users through their
application credentials.

Change-Id: I15e438681749ed2c2666804a9efd8d4712a7b01c
2022-08-23 09:39:18 +00:00
Ayumu Ueha 9c49da6887 Fix logging notifier unit test
For unknown reasons, the `create_notifier()` in
`test_api_request_no_messaging()` used `oslo_messaging.Notifier`
instead of the `_LogNotifier` that should be originally used,
causing unit test to fail.

This patch fixes this issue by changing `use_oslo_messaging` config to
False for this test.

Change-Id: I32f9dc596525e912e37984764f68564e26ecfd3b
2022-08-09 14:33:32 +00:00
dengzhaosen 6a0974117e Remove references to 'sys.version_info'
We support Python 3.6 as a minimum now, making these checks no-ops.
Change-Id: Iff6abdc56c5627505e774f40af339e1b5790c4d5
2021-04-27 10:27:47 +08:00
Zuul 11ea4a8bd2 Merge "Use unittest.mock instead of third party mock" 2020-08-24 19:38:38 +00:00
Zuul 654d31a1bd Merge "Change the default Identity endpoint to internal" 2020-07-06 10:43:56 +00:00
Jens Harbott 8f9a596fff Change the default Identity endpoint to internal
In [0] the ``interface``option was added in order to allow the Identity
endpoint that is being used when validating tokens to be
configured by the deployer. Change the default to using the internal
endpoint, as that should be what most deployments will end up using.

[0] https://review.opendev.org/651790

Depends-On: https://review.opendev.org/651492
Closes-Bug: 1830002
Change-Id: I0ce8b6d8cd408c7fac8107972e7be70839e337fb
2020-06-14 16:20:05 +00:00
Sean McGinnis 215217ea8b
Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: Idc319f3f8a3ddd57cba91e4cefc66dbb18d5cc22
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-18 11:53:42 -05:00
Andreas Jaeger f32fcc6623 Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Blacklist:
W504 line break after binary operator
W503 line break before binary operator

Fix other problems found

Change-Id: I2fb257a4f42b499df3702f3e8f3c99ecb28557d6
2020-03-30 10:32:07 +00:00
Zuul 2a8e6fb053 Merge "Remove keystoneclient exception usage in tests" 2020-01-02 18:58:56 +00:00
Gage Hugo 7c33d8ebb6 Rename _v3_to_v2_catalog to _normalize_catalog
This change renames the _v3_to_v2_catalog to _normalize_catalog as
part of the v2 removal effort. Several services still rely on the
converted catalog format, so this change maintains the conversion
but removes the v2 association.

Change-Id: Ic7bca16d8c6211d006fc2ba09dc2ecd83f8955db
Partial-Bug: #1845539
Partial-Bug: #1777177
2019-12-20 14:37:43 -06:00
Zuul 97350d16b1 Merge "Change ec2 URLs to v3" 2019-12-03 07:54:19 +00:00
Gage Hugo 09a33cce89 Change ec2 URLs to v3
This change modifies any URLs specifying v2.0 to v3. This is part
of the effort to remove v2.0 functionality from keystonemiddleware.

Change-Id: I9cde8963333ea95b4ab05d9aea4d196ab4357763
Partial-Bug: #1829453
Partial-Bug: #1845539
2019-11-29 04:20:14 +00:00
Gage Hugo a6a3edb80e Remove v2.0 functionality
This change removes v2.0 functionality from
keystonemiddleware, as well as associated tests.

Partial-Bug: #1845539
Partial-Bug: #1777177

Change-Id: If47e90085d8a59c52fb23876dc329cd4f0b05ef0
2019-11-27 10:52:23 -06:00
Gage Hugo d3090bfbc0 Remove keystoneclient exception usage in tests
This change replaces the usage of keystoneclient exceptions in the
auth_token_middleware unit tests to use the ConnectFailure exception
from keystoneauth.

This is part of the process of removing keystoneclient from
keystonemiddleware.

Change-Id: Ie00fc310728c319faf2cfdfb651f0c7a8f48d757
2019-11-24 00:12:24 -06:00
Bernhard M. Wiedemann 4a4c96ce9b Make tests pass in 2022
Background:
As part of my work on reproducible builds for openSUSE, I check that software still gives identical build results in the future.
The usual offset is +15 years, because that is how long I expect some software will be used in some places.
This showed up failing tests in our package build.
See https://reproducible-builds.org/ for why this matters.

This makes it expire 1 year in the future to model realistic tokens.

Change-Id: I73bde68be53afff4e8dff12d756b8381f34b2adb
2019-09-17 13:19:24 +02:00
Colleen Murphy 5f093bf5ee Add validation of app cred access rules
This commit adds a validation step in the auth_token middleware to check
for the presence of an access_rules attribute in an application
credential token and to validate the request against the permissions
granted for that token. During token validation it sends a header to
keystone to indicate that it is capable of validating these access
rules, and not providing this header for a token like this would result
in the token failing validation. This disregards access rules for a
service request made by a service on behalf of a user, such as nova
making a request to glance, because such a request is not under the
control of the user and is not expected to be explicitly allowed in the
access rules.

bp whitelist-extension-for-app-creds

Depends-On: https://review.opendev.org/670377

Change-Id: I185e0541d5df538d74edadf9976b3034a2470c88
2019-07-15 16:05:59 -07:00
Zuul 2ed915f4fe Merge "Remove PKI/PKIZ support" 2019-06-21 21:31:56 +00:00
Colleen Murphy d040cf67fb Remove Diablo compatibility tests
We really don't care about Diablo compatibility any more. Clean up the
old cruft.

Change-Id: Ib1f628eb40ba0cb6334300cb6dca7dcdfcddba1b
2019-06-20 12:40:19 -07:00
Morgan Fainberg b3e84aafc0 Remove PKI/PKIZ support
Keystone server no longer supports PKI/PKIZ. This change removes
keystonemiddleware's support of PKI/PKIZ and associated code.

Change-Id: I9a6639a2aa3774be61972d57f38220f66fd5c0e8
closes-bug: #1649735
partial-bug: #1736985
2019-06-19 12:16:47 -07:00
Jens Harbott f6037a3d50 Add a new option to choose the Identity endpoint
Previously the admin Identity endpoint was hardcoded to be used. Now
that keystone has dropped v2 support, deploying an admin Identity
endpoint is no longer useful, so allow this to be changed by the
deployer. Keep the default as using the `admin` endpoint, but create
a deprecation message so that we can change the default in the future.

Partial-Bug: 1830002
Change-Id: I993a45ccb1109d67e65bf32d1e134cc9bec2d88e
2019-06-03 10:34:25 +00:00
Yang Youseok 4e51cb8e6b Add auth invalidation in auth_token for identity endpoint update
Currently auth_token middleware does not concern identity endpoint
update since service catalog is not updated after service having
auth_token middleware started.

Add invalidation logic when EndpointNotfound exception occurs so
that auth_token middleware can be notified of sevice catalog update
without restart.

Change-Id: I631ee1538883d732fe3987b172d987f703dad5c0
Closes-Bug: #1813739
2019-02-07 12:14:51 +09:00
Leehom Li (feli5) 82707e15a5 Make sure audit middleware use own context
Keystone audit middleware requires to iterate req.context as dict,
but Glance requires to access req.context.read_only.
When glance enabled audit, they are conflict with each other.
This patch fix this issue by store audit context in
req.environ['audit.context']

Change-Id: Ib9a62a4cd0b7b9ffb9fa2d6440e8072d45ee0fee
Closes-Bug: #1809101
Signed-off-by: Leehom Li <feli5@cisco.com>
2018-12-24 02:02:17 +00:00
Artem Vasilyev f2f5820c5f Added request_id and global_request_id to CADF notifications
Change-Id: I8d571d3414071c68b4fa565dec46cc2d2941331c
Closes-Bug: #1803940
2018-11-19 11:49:24 +03:00
Zuul 899aa07a64 Merge "Stop supporting revocation list" 2018-11-07 10:09:35 +00:00
Morgan Fainberg 7e1b536259 Stop supporting revocation list
With keystone's move to eliminating pki, pkiz, and uuid tokens the
revocation list is no longer generated. Keystonemiddleware no longer
needs to attempt to retrieve it and reference it.

Change-Id: Ief3bf1941e62f9136dbed11877bca81c4102041b
closes-bug: #1361743
partial-bug: #1649735
partial-bug: #1736985
2018-10-30 19:36:51 +00:00
Michael Johnson 782729b6e9 Fix audit target service selection
The keystonemiddleware audit code would select the wrong OpenStack service
endpoint for a request if the cloud is not using unique TCP ports for each
service endpoint. As most services are no longer using a port per service,
but instead using unique paths, this caused the audit to select the wrong
target service. This leads to incorrect audit logging due to the wrong
audit map being used.

This patch checks the request to see if a TCP port was present in the request,
and if not, fall back to using the target_endpoint_type configured in the
audit map file.

Change-Id: Ie2e0bf74ecca485d599a4041bb770bd6e296bc99
Closes-bug: 1797584
2018-10-29 11:08:34 -07:00
Zuul 536a8701ed Merge "Skip the services with no endpoints when parsing service catalog" 2018-10-28 11:39:32 +00:00
Zuul 55b6142791 Merge "Expect paste.deploy and gnocchi/panko options" 2018-10-26 18:29:26 +00:00
Guang Yee 6779838a24 Skip the services with no endpoints when parsing service catalog
When parsing the service catalog to find the source, audit middleware
should skip over the services which have no endpoints instead of
assuming they will have at least one endpoint.

Change-Id: I287873e99338d95baaf20d52ecb3a43763a401fc
Closes-Bug: #1800017
2018-10-26 08:13:39 -07:00
Tim Burke da5932affc Respect delay_auth_decision when Keystone is unavailable
The delay_auth_decision option has two main uses:

  1. Allow a service to provide its own auth mechanism, separate from
     auth tokens (like Swift's tempurl middleware).
  2. Allow a service to integrate with multiple auth middlewares which
     may want to use the same X-Auth-Token header.

The first case works fine even when the service has trouble talking to
Keystone -- the client doesn't send an X-Auth-Token header, so we never
even attempt to contact Keystone.

The second case can be problematic, however. The client will provide
some token, and we don't know whether it's valid for Keystone, the other
auth system, or neither. We have to *try* contacting Keystone, but if
that was down we'd previously return a 503 without ever trying the other
auth system. As a result, a Keystone failure results in a total system
failure.

Now, when delay_auth_decision is True and we cannot determine whether a
token is valid or invalid, we'll instead declare the token invalid and
defer the rejection. As a result, Keystone failures only affect Keystone
users, and tokens issued by the other auth system may still be validated
and used.

Change-Id: Ie4b3319862ba7fbd329dc6883ce837e894d5270c
2018-09-11 07:54:43 -06:00
wangxiyuan 4fb7fef1ea No need to compare CONF content
When setup AuthProtocol class, if the CONF object contains
deprecated options, An Error "dictionary changed size during
iteration" will raise when comparing the CONF content.

Changing "!=" to "is not" here to avoid compare the CONF
content anymore.

Change-Id: I820aa244160db4f81149d2576386c86b46de0084
Closes-bug: #1789351
2018-09-07 10:38:14 +08:00
Zuul f6ad3f236f Merge "Handle DiscoveryFailure errors" 2018-08-28 16:21:59 +00:00
Tim Burke 86904543eb Handle DiscoveryFailure errors
DiscoveryFailures can happen for a variety of reasons, ranging
from service misconfiguration to a keystone outage to a transient
network failure. If we don't catch and handle the failure here,
it will almost certainly cause something further up the WSGI stack
to send a 500 Internal Error (and likely log a traceback).

A log line like

    Unable to validate token: Could not find versioned identity
    endpoints when attempting to authenticate. Please check that
    your auth_url is correct. Unable to establish connection to
    http://keystone:35357: HTTPConnectionPool(host='keystone',
    port=35357): Max retries exceeded with url: / (Caused by
    NewConnectionError('<urllib3.connection.HTTPConnection
    object at 0x7fc53e22e050>: Failed to establish a new
    connection: [Errno 111] ECONNREFUSED',))

should be plenty enough for an operator to assess the situation;
I don't need a 29-frame traceback.

Change-Id: I946388c09b2ca0230d2cef009c679a7ac7c8398f
2018-08-01 23:26:13 +00:00
Morgan Fainberg c46f29278d Fix KeystoneMiddleware memcachepool abstraction
Keystonemiddleware's abstraction for the memcache pool was broken
when converting to use a queue.Queue. The logic that placed the
connection back into the pool was moved to .acquire and the reserve
method was not using acquire.

Change-Id: I0eda5981cbb661f63790258cf8e70c7340615159
Closes-Bug: #1782404
2018-07-18 11:56:43 -07:00
Lance Bragstad 245c91f2e3 Introduce new header for system-scoped tokens
Keystonemiddleware attempts to parse user/service tokens and populate
request headers for other services to consume. This information is
important for services looking to build oslo.context objects from
request environments.

Change-Id: I0717c2a5207a647999b4f9bcdf11f728984f0812
Closes-Bug: 1766731
2018-05-02 19:15:16 +00:00
Zuul 686f7a5b0b Merge "Double quote www_authenticate_uri" 2018-04-21 03:57:31 +00:00
Zuul cd919f5d1f Merge "Only include response body if there's a response" 2018-04-20 21:27:33 +00:00
Zuul 6d18e227d9 Merge "Properly zero out max_retries in test_http_error_not_cached_token" 2018-04-20 21:27:32 +00:00
wangxiyuan a78a25ea23 Double quote www_authenticate_uri
Based on the RFCs[1], in http header, a string of text is parsed
as a single value if it is quoted using double-quote marks.

This patch change the single quote to double quote in the header
"WWW-Authenticate" which is returned when 401 error raises.

[1]: https://tools.ietf.org/html/rfc7230#section-3.2.6
     https://tools.ietf.org/html/rfc7235#section-2.1

Change-Id: I524c93d30607ea6ab70de92ceea207ee77f34c25
Closes-bug: #1762362
2018-04-12 12:05:38 +08:00