38 Commits

Author SHA1 Message Date
Jenkins
9c3ef2dff8 Merge "Small readability change to test_keystoneauth" 2017-08-28 10:51:45 +00:00
Sachin Patil
fb07863155 Small readability change to test_keystoneauth
Changed assertTrue to assertIsNone for better readability

Change-Id: Ibc83c32ccfb5165abf897a15cf2692414a7f95c3
Signed-off-by: Sachin Patil <psachin@redhat.com>
2017-08-28 10:34:49 +00:00
lingyongxu
ee9458a250 Using assertIsNone() instead of assertEqual(None)
Following OpenStack Style Guidelines:
[1] http://docs.openstack.org/developer/hacking/#unit-tests-and-assertraises
[H203] Unit test assertions tend to give better messages for more specific
assertions. As a result, assertIsNone(...) is preferred over
assertEqual(None, ...) and assertIs(..., None)

Change-Id: If4db8872c4f5705c1fff017c4891626e9ce4d1e4
2017-06-07 14:05:53 +08:00
Hisashi Osanai
5cd57dc357 Improve Keystone v3 token support
Now keystoneauth uses HTTP_X_TENANT_NAME/ID only even if v3 token uses for
backward compatibility. There is no problem with current behavior because
keystonemiddleware set same value on the headers but the headers are
specified as deprecated so this patch allows to support HTTP_X_PROJECT_NAME/ID
in addition to HTTP_X_TENANT_NAME/ID.

Change-Id: Ie5e02067a59e18f1ac215f51429863bdd42f729f
2016-07-11 14:05:50 +00:00
Tim Burke
2744492f30 Use the same key for memcache and env['swift.infocache']
When we were caching directly to the WSGI environment, it made sense to
have different keys for the different caches. Now that we have a
separate data structure for the per-request cache, however, we ought to
be consistent.

Change-Id: I199cba6e5fc9ab4205bba369e6a2f34fc5ce22d4
2016-05-16 18:43:32 -07:00
Samuel Merritt
ce90a1e79e Make info caching work across subrequests
Previously, if you called get_account_info, get_container_info, or
get_object_info, then the results of that call would be cached in the
WSGI environment as top-level keys. This is okay, except that if you,
in middleware, copy the WSGI environment and then make a subrequest
using the copy, information retrieved in the subrequest is cached
only in the copy and not in the original. This can mean lots of extra
trips to memcache for, say, SLO validation where the segments are in
another container; the object HEAD ends up getting container info for
the segment container, but then the next object HEAD gets it again.

This commit moves the cache for get_*_info into a dictionary at
environ['swift.infocache']; this way, you can shallow-copy the request
environment and still get the benefits from the cache.

Change-Id: I3481b38b41c33cd1e39e19baab56193c5f9bf6ac
2016-05-13 10:36:49 -07:00
Jenkins
7cc2c783a4 Merge "Keystone middleware deprecated option is_admin removed" 2016-03-18 10:51:46 +00:00
Chaozhe.Chen
4a44e27e00 Replace assertEqual(None, *) with assertIsNone in tests
As swift no longer supports Python 2.6, replace assertEqual(None, *)
with assertIsNone in tests to have more clear messages in case of
failure.

Change-Id: I94af3e8156ef40465d4f7a2cb79fb99fc7bbda56
Closes-Bug: #1280522
2016-02-16 23:49:06 +08:00
Ondřej Nový
335d58611d Keystone middleware deprecated option is_admin removed
It has been deprecated from Swift 1.8.0 (Grizzly)

Change-Id: Id6bc10c3e84262c0a9e6160a76af03c0ad363e9c
2016-02-11 10:52:47 +00:00
Hisashi Osanai
b96fd0d7d8 Remove _keystone_identity method
_keystone_identity method has been maintained for backward
compatibility. But there is no place to use it now so this patch
replace _keystone_identity method to _integrated_keystone_identity
method as _keystone_identity.

Change-Id: I9464c047401f92ae31a5d3bb7aacaeb0624150e0
2015-10-25 16:30:02 +09:00
janonymous
f5f9d791b0 pep8 fix: assertEquals -> assertEqual
assertEquals is deprecated in py3, replacing it.

Change-Id: Ida206abbb13c320095bb9e3b25a2b66cc31bfba8
Co-Authored-By: Ondřej Nový <ondrej.novy@firma.seznam.cz>
2015-10-11 12:57:25 +02:00
Christian Schwede
4b8f52b153 Fix copy requests to service accounts in Keystone
In case of a COPY request the swift_owner was already set to True, and the
following PUT request was granted access no matter if a service token was used
or not.  This allowed to copy data to service accounts without any service
token.

Service token unit tests have been added to verify that when
swift_owner is set to True in a request environ, this setting is
ignored when authorizing another request based on the same
environ. Applying only this test change on master fails currently, and
only passes with the fix in this patch.

Tempauth seems to be not affected, however a small doc update has been added to
make it more clear that a service token is not needed to access a service account
when an ACL is used.

Further details with an example are available in the bug report
(https://bugs.launchpad.net/swift/+bug/1483007).

Co-Authored-By: Alistair Coles <alistair.coles@hp.com>
Co-Authored-By: Hisashi Osanai <osanai.hisashi@jp.fujitsu.com>
Co-Authored-By: Donagh McCabe <donagh.mccabe@hp.com>

Closes-Bug: 1483007
Change-Id: I1207b911f018b855362b1078f68c38615be74bbd
2015-10-01 10:01:03 +01:00
Hisashi Osanai
278adf5c20 Make logic of unit tests responsive to the method names
The two methods, test_authorize_succeeds_for_tenant_name_in_roles and
test_authorize_succeeds_for_tenant_id_in_roles, have names that don't
match what they are testing. tenant_name and tenant_id need to be
switched.

Change-Id: I7cb0a7d2b2111127fd5d6b55f2da6a3eadf2235d
2015-07-15 08:53:46 +09:00
janonymous
09e7477a39 Replace it.next() with next(it) for py3 compat
The Python 2 next() method of iterators was renamed to __next__() on
Python 3. Use the builtin next() function instead which works on Python
2 and Python 3.

Change-Id: Ic948bc574b58f1d28c5c58e3985906dee17fa51d
2015-06-15 22:10:45 +05:30
Hisashi Osanai
749bdac1df Refactor the getting roles logic in _keystone_identity
The list_from_csv in swift.common.utils is used from the composite
auth token support and this method has been used in
_integral_keystone_identity. There is same logic in
_keystone_identity so the logic would be replaced with list_from_csv.

Change-Id: I3d72a34e6fc21fbe1d7331954695b1e3e1b67816
2015-04-14 13:15:15 -07:00
Donagh McCabe
8a1453e61e Support HTTP_X_SERVICE_IDENTITY_STATUS in keystoneauth
Keystone's auth_token now supports delay denial when
a service token is invalid. This change handles
the consequences for determining 401 vs 403 responses.

Related-Bug: #1422389

Change-Id: I90ba062e357cccea061c7101463b82b7c5e69293
2015-04-14 13:15:15 -07:00
Donagh McCabe
89397c5b67 Add multiple reseller prefixes and composite tokens
This change is in support of Composite Tokens and Service Accounts
(see http://specs.openstack.org/openstack/swift-specs/specs/in_progress/
service_token.html)

During coding, minor changes were made compared to the original
specification. See https://review.openstack.org/138771 for these changes.

DocImpact

Change-Id: I6072b4efb3a479a8e0cc2d9c11ffda5764b55e30
2015-02-23 15:57:20 +00:00
anc
a4f634bd89 Restrict keystone cross-tenant ACLs to IDs
The keystoneauth middleware supports cross-tenant access
control using the syntax <tenant>:<user> in container ACLs,
where <tenant> and <user> may currently be either a unique
id or a name. As a result of the keystone v3 API introducing
domains, names are no longer globally unique and are only
unique within a domain. The use of unqualified tenant and
user names in this ACL syntax is therefore not 'safe' in a
keystone v3 environment.

This patch modifies keystoneauth to restrict cross-tenant
ACL matching to use only ids for accounts that are not in
the default domain. For backwards compatibility,
names will still be matched in ACLs when both the requesting
user and tenant are known to be in the default domain AND the
account's tenant is also in the default domain (the default
domain being the domain to which existing tenants are
migrated).

Accounts existing prior to this patch are assumed to be for
tenants in the default domain. New accounts created using a
v2 token scoped on the tenant are also assumed to be in the
default domain. New accounts created using a v3 token scoped
on the tenant will learn their domain membership from the
token info. New accounts created using any unscoped token,
(i.e. with a reselleradmin role) will have unknown domain
membership and therefore be assumed to NOT be in the default
domain.

Despite this provision for backwards compatibility, names
must no longer be used when setting new ACLs in any account,
including new accounts in the default domain.

This change obviously impacts users accustomed to specifying
cross-tenant ACLs in terms of names, and further work will be
necessary to restore those use cases. Some ideas are
discussed under the bug report. With that caveat, this patch
removes the reported vulnerability when using
swift/keystoneauth with a keystone v3 API.

Note: to observe the new 'restricted' behaviour you will need
to setup keystone user(s) and tenant(s) in a non-default domain
and set auth_version = v3.0 in the auth_token middleware config
section of proxy-server.conf. You may also benefit from the
keystone v3 enabled swiftclient patch under review here:
https://review.openstack.org/#/c/91788/

DocImpact

blueprint keystone-v3-support

Closes-Bug:  #1299146

Change-Id: Ib32df093f7450f704127da77ff06b595f57615cb
2014-08-08 15:58:29 +01:00
David Goetz
ab510952ef xLO bug with auth tokens expiring during download.
Just put SLO and DLO after any auth middleware. This works because when
the request goes through that middleware in the pipeline the
authentication takes place: validation of the token, setting up who the
user is, and setting the authorization call back. Each subrequest made
for the segments will be subjected to that authorization call back which
verifies the user has access to the individual segments.

To get this to work with keystone, the keystone identity is set up
during __call__ and applied to the authorize function using a
functools.partial. When the authorize function is later called from the
environ by the proxy server the idenity that was set up when the request
passed through the auth middleware is used, not what can be pulled out
of the possibly altered state of the request's environment.

DocImpact
fixes bug: 1315133

Change-Id: I7827dd2d9dfbb3c6424773fb2891355d47e372ba
2014-06-10 12:48:05 +00:00
Brian Cline
b4c5a13664 Uses None instead of mutables for function param defaults
As seen on #1174809, changes use of mutable types as default
arguments and defaults them within the method. Otherwise, those
defaults can be unexpectedly persisted with the function between
invocations and erupt into mass hysteria on the streets.

There was indeed a test (TestSimpleClient.test_get_with_retries)
that was erroneously relying on this behavior. Since previous tests
had populated their own instantiations with a token, this test only
passed because the modified headers dict from previous tests was
being overridden. As expected, with the mutable defaults fix in
SimpleClient, this test begain to fail since it never specified any
token, yet it has always passed anyway. This change also now provides
the expected token.

Change-Id: If95f11d259008517dab511e88acfe9731e5a99b5
Related-Bug: #1174809
2014-05-10 11:15:56 +00:00
Peter Portante
a410730a2b Do not format messages before they are logged
Change-Id: Ia645c9eca47b7f404d9b987f68a96b4744031e9d
Signed-off-by: Peter Portante <peter.portante@redhat.com>
2013-11-21 22:34:36 -05:00
Donagh McCabe
9807a358c6 Add WWW-Authenticate to 401 responses
Per http://www.ietf.org/rfc/rfc2616.txt, when a 401 error is returned, the
Www-Authenticate response header MUST also be returned. The format is
described in http://www.ietf.org/rfc/rfc2617.txt.

Swift supports and/or implements a number of authentication schemes
including tempauth, Keystone, tempurl, formpost and container sync. In
this fix, we use a catch-all, "Swift". The realm is the account (where
known) or "unknown" (bad path or where the 401 is returned from code
that does not have the request). Examples:

     Www-Authenticate: Swift realm="AUTH_1234567889"
     Www-Authenticate: Swift realm="unknown"

Fixes bug #1215491

Change-Id: I03362789318dfa156d3733ef9348795062a9cfc4
2013-10-22 15:49:09 +01:00
ZhiQiang Fan
f72704fc82 Change OpenStack LLC to Foundation
Change-Id: I7c3df47c31759dbeb3105f8883e2688ada848d58
Closes-bug: #1214176
2013-09-20 01:02:31 +08:00
Peter Portante
56593a1323 Pep8 unit test modules w/ <= 20 violations (6 of 12)
Change-Id: I7317beb97e1530cb18c62da55ccf4c64206ff362
Signed-off-by: Peter Portante <peter.portante@redhat.com>
2013-09-01 16:12:42 -04:00
Jenkins
2a359f2037 Merge "Don't allow users to delete their own account." 2013-07-23 01:23:54 +00:00
Chmouel Boudjnah
6f57b06c7c Make keystoneauth reseller_prefix check for _
- Automatically add underscore if there wasn't one already.
- This makes consistent with tempauth.
- Fixes bug 1198878.
- This should probably need to be mentioned in the release changelog for
  upgrades.

Change-Id: Ia82f14f82c380c7ed2ddd190116f1493e410cfbe
2013-07-08 13:32:28 +02:00
Chmouel Boudjnah
6f722f7320 Don't allow users to delete their own account.
- In keystoneauth we allowed authenticated users to delete their own
  account we are disallowing that and only allow users with reseller
  admin to do that for its own or for the others.
- Fixes bug 1177526.

Change-Id: I825c5a968e8eae0991915056825fe0e0c195647e
2013-07-03 16:33:20 +00:00
Kun Huang
58a095b93e Improve swift's keystoneauth ACL support
Below three bug reports talk about one thing.
Current keystoneauth ACL supports as:

tenant_name:user_id         ok
tenant_name:user_name       no
tenant_name:*               no
tenant_id:user_id           ok
tenant_id:user_name         no
tenant_id:*                 no
*:user_id                   ok
*:user_name                 no
*:*                         no

This patch will make all of above work fine.
Applying (tenant/user)name could let user put or get their data in a
more readable way. The tenant_name:* and *:user_name is suitable for
many usage.

note: to keep compatibility here add a new keystone.identity just for
authorize() itself and leave env['keystone.identity'] to other
middlerwares.

Fixes: bug #1020709
Fixes: bug #1075362
Fixes: bug #1155389
Change-Id: I9354dedaad875117f6a9072c67e9ecf69bfca77e
2013-06-13 13:25:25 +08:00
Greg Lange
44f00a23c1 fixed some minor things in tests that pyflakes complained about
Change-Id: Ifeab56a964630bcf941e932fcbe39e6572e62975
2013-03-26 20:42:26 +00:00
Kun Huang
7dd966192a Use role in insensitive case in keystoneauth.
Using insensitive case could tolerate human error. For example,
user maybe set like this "operator_roles = Admin, swiftoperator"

- also fix a mistake in test, ['admin'] is correct value for roles, not
  'admin' (it will be looped as ['a', 'd', 'm', 'i', 'n'])
- add test for insensitive cases

Fixes: bug #1013120
Change-Id: I56d71da8bc503e48e92dd743692ba6fc237f029e
2013-03-19 16:26:22 +08:00
Christian Schwede
157c3c91ee Add tests and doc entry for request.environ[reseller_request]
The recent account_quotas (https://review.openstack.org/23434)
patch added a new setting request.environ[reseller_request].
This patch adds tests for tempauth and keystoneauth as well as
an updated overview_auth.rst.

Change-Id: Icdb7ec9948ae7424b0721fc51a143782b2fdc5a6
2013-03-10 19:21:13 +01:00
Jenkins
b6b5d6670d Merge "Allow acl with a valid token." 2013-02-28 04:51:55 +00:00
Chmouel Boudjnah
a7e31eb5dd Add tests on keystone for invalid path requests.
- Add missing tests to make it coverage to 100%.

Change-Id: Ic182ad379e2c48cc4151b2532c509bd62d44bd00
2013-02-21 14:05:25 +01:00
Chmouel Boudjnah
0f284e04e4 Allow acl with a valid token.
- When a user as a valid token it would go to authorize but the acl
  check was after the reseller_check and due fail. Check this before
  reseller_check and add a test for it.
- Fixes bug 1020722.

Change-Id: Iaff9f35f5ee690e9b729c36d05fb9adf3368dc79
2013-02-20 18:08:58 +01:00
Chmouel Boudjnah
0dc32d31c5 Fix keystoneauth with OPTIONS headers (eg: CORS)
- Fixes bug 1101143.

Change-Id: I2a82269e4aed2c8926e0aa736c38120784e25de2
2013-01-24 12:36:35 +01:00
Guang Yee
795acd40f1 bp/cross-tenant-acls: allow tenantId:user, tenantName:user, and *:user ALCs
Change-Id: I7cfe77b3f03172814814f2e2bae04a3ae184efb0
2012-11-30 13:53:00 -08:00
Michael Barton
5e3e9a882d local WSGI Request and Response classes
This change replaces WebOb with a mostly compatible local library,
swift.common.swob.  Subtle changes to WebOb's API over the years have been a
huge headache.  Swift doesn't even run on the current version.

There are a few incompatibilities to simplify the implementation/interface:
 * It only implements the header properties we use.  More can be easily added.
 * Casts header values to str on assignment.
 * Response classes ("HTTPNotFound") are no longer subclasses, but partials
   on Response, so things like isinstance no longer work on them.
 * Unlike newer webob versions, will never return unicode objects.

Change-Id: I76617a0903ee2286b25a821b3c935c86ff95233f
2012-09-28 14:48:48 -07:00
Chmouel Boudjnah
afa4f70024 Move swift_auth middleware from keystone to swift.
- Rename it to keystoneauth for consistenties.
- Implements blueprint keystone-middleware.

Change-Id: I208fecdf3ee991694b4239f065032324d297fd35
2012-07-05 14:36:14 -04:00