Commit Graph

5103 Commits

Author SHA1 Message Date
Douglas Mendizábal b31007e1b2 Allow admin to access tokens and credentials
This patch modifies a few policies to allow users with the "admin" role
to access /v3/auth/tokens and /v3/credentials.  These policies were
missed when we implemented Phase 1 of Secure RBAC.

Change-Id: Id789c09121f1405f7ba5e4926498dab4ad98e057
2024-04-02 20:58:10 -05:00
Zuul 0ba7fdbd15 Merge "Fix operation order in role deletion" 2024-03-12 17:22:35 +00:00
Zuul 8c2d5769a1 Merge "Dont enforce when HTTP GET on s3tokens and ec2tokens" 2024-03-08 17:05:42 +00:00
Boris Bobrov 63556be0e3 Fix operation order in role deletion
Deletion of a role leads to deletion of role assignments and entries in
the application credentials. However, deletion of the entries in
application credentials depends on the existence of the assignment, so
the order of deletion is important.

Delete the entries from application credentials first and then clean up
role assignment.

Closes-Bug: 2053137
Change-Id: Ibba9063c729961cd4155f8b55dbabd4789d7a438
2024-02-15 23:28:24 +01:00
Tobias Urdin 6096457d74 Dont enforce when HTTP GET on s3tokens and ec2tokens
When calling the s3tokens or ec2tokens API with a
HTTP GET we should get a 405 Method Not Allowed but
we get a 500 Internal Server Error because we enforce
that method.

Closes-Bug: #2052916
Change-Id: I5f60d10dc25551175cc73ca8f3f28b0b95ec9f99
Signed-off-by: Tobias Urdin <tobias.urdin@binero.se>
2024-02-12 08:41:39 +00:00
Markus Hentsch dd785ee692 Add domain scoping to list_domains
Introduces domain-scoped filtering of the response list of the
list_domains endpoint when the user is authenticated in domain scope
instead of returning all domains. This aligns the implementation with
other endpoints like list_projects or list_groups and allows for a
domain-scoped reader role.
Changes the default policy rule for identity:list_domains to
incorporate this new behavior for the reader role.

Closes-Bug: 2041611
Change-Id: I8ee50efc3b4850060cce840fc904bae17f1503a9
2024-02-08 13:55:44 +01:00
Zuul 0608537f03 Merge "Check user existence before setting last_active_at" 2024-01-26 19:25:20 +00:00
Zuul 406233f169 Merge "Clean up deprecated options for eventlet server" 2024-01-26 17:37:17 +00:00
Zuul 6c16f975d2 Merge "Improve application credential validation speed" 2024-01-26 17:37:13 +00:00
Zuul 993e589fa1 Merge "Keystone to honor the "domain" attribute mapping rules." 2024-01-26 17:37:09 +00:00
Douglas Mendizábal f2f1a5c388 Consistent and Secure RBAC (Phase 1)
This patch updates system-scoped policies to also accept project-admin
tokens so that operators can continue to use the "admin" role to access
system level APIs.

The protection test job is marked non-voting since tempest does not yet
expect these policy changes.  A follow-up patch will make it voting
again after the test changes have merged into tempest.

[1] https://governance.openstack.org/tc/goals/selected/consistent-and-secure-rbac.html#phase-1

Change-Id: I31b5a1f85d994a90578657bc77fa46ace0748582
2024-01-19 14:35:37 -05:00
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
Trent Lloyd 67b5cca032 Improve application credential validation speed
Validating an application credential token is very slow, taking at least
400ms+ in a simple devstack environment, 5-10x longer than validating a
user/password project token.

The primary bottleneck during a token validation request
(/v3/auth/tokens) is that token.roles is evaluated at least 5 times.
validate_token is called twice, first during RBAC to populate the
subject token context and again to actually validate the token. Each
call to validate_token then called token.roles twice because it first
checks if it is None, before calling it again to use the result. Lastly
token.roles is evaluated a fifth time during
render_token_response_from_model.

Each evaluation of token.roles calls through
_get_application_credential_roles into list_role_assignments which then
makes multiple round-trip SQL queries to the database.

Unlike the related get_roles_for_user_and_project function, none of
these calls are currently cached/memoized. We memoize
list_role_assignments to get the same-speedup.

Reduce the number of token.roles calls to only 3 by storing and re-using
the token.roles result in validate_token, then memoize
list_role_assignments so the 2nd and 3rd call fetch from the cache
instead of repeating many SQL queries.

This provides a substantial performance improvement bringing validation
time in-line with user/password tokens.

Change-Id: I8c45131b298ceae7b43b42e2c5df167607d18c48
2024-01-02 08:46:24 +00:00
Takashi Kajinami 2a3c73c49b Clean up deprecated options for eventlet server
The eventlet server implementation was removed during Newton, and have
not been used by any other implementations for a while.

Change-Id: I01f9adfc3e610d820c1834209d36c10568cccf41
2023-12-07 10:40:11 +09:00
Zuul bd681f379b Merge "Fix bindep.txt for python 3.11 job(Debian Bookworm)" 2023-11-29 16:35:53 +00:00
Takashi Kajinami 24b77bb643 Fix bindep.txt for python 3.11 job(Debian Bookworm)
Python 3.11 job now run on Debian Bookwarm which does not provide
some of the packages in bindep. This fixes the bindep file so that
it pulls packages actually available.

This also updates a few assertions of log records in unit tests to make
these robust for any warning logs.

Change-Id: Iae3f4da24418530b61b9a0b64390160d194da05b
2023-11-29 12:41:29 +09:00
Boris Bobrov 26c8812b4c Check user existence before setting last_active_at
A situation might arise, when the user does not exist any more and we
are attempting to set last_active_at on them. This results in keystone
raising AttributeError.

Check for user existense before addressing the attribute

Closes-Bug: 2044624
Change-Id: I3eb5890fb6d52a222b7caa4a52effc06774c0542
2023-11-26 00:49:59 +01:00
Zuul 8b8c025fc3 Merge "Stop pinning pep8 related packages" 2023-10-06 15:32:22 +00:00
Zuul be05fb3f11 Merge "Add support for bcrypt_sha256 hasher" 2023-10-04 21:11:33 +00:00
Pete Zaitcev d2deab385b Stop pinning pep8 related packages
These practices cause conflicts periodically. Not right now:
the gate is okay with the current values, which this patch
deletes. However, like sun raising in the east it is sure
to happen again. This patch lets workarounds work that the
infra team puts in place. The downside is, we need to fix
the code once in a while as new checks get added.

Change-Id: Ia7a96fb4b6de4251862a8a96c995cefa94dbc271
2023-10-02 15:41:36 -05:00
Abhishek Kekane bbbbd10e48 Add default manager role support to bootstrap command
Added manager role support to bootstrap command.

Closes-Bug: #1951622
Change-Id: I4149e99bdc50194dd4067f5f3e2f3019e48b5a59
2023-08-30 18:20:43 -05:00
Zuul 02bbc665c4 Merge "Add an option to randomize LDAP urls list" 2023-08-25 16:28:33 +00:00
Dmitriy Rabotyagov 9b0b414e3e Add support for bcrypt_sha256 hasher
This patch adds new hashing alhorythm bcrypt_sha256, which is based on
the bcrypt but does not have limitations on the leght of the passwords,
since passwords are passed through HMAC-SHA2-256 first.
At accepts exactly same parameters as bcrypt does.
However, it prefix the hash using `prefix` attribute rather then
`indent_values` which are same as for bcrypt.

Change-Id: I5430ebf5a20142c1a9caab960ced9b3ee2e782c1
2023-08-10 15:39:51 +02:00
Dmitriy Rabotyagov 6730c761d1 Properly trimm bcrypt hashed passwords
bcrypt  hashing algorythm has a limitation on length of passwords it
can hash on 72 bytes. In [1] a password trimm to 54 symbols has been
implemented, which resulted in password being invalidated after the
keystone upgrade, since passwords are trimmed differently by bcrypt
itself, as well as len(str()) is not always equal to
len(str().encode()) as trimming should be done based on bytes and not
string itself.

With the change we return a byte object from
`verify_length_and_trunc_password`, so it does not need to
be encoded afterwards, since we need to strip based on bytes
rather then on length of the string.

[1] https://review.opendev.org/c/openstack/keystone/+/828595

Closes-Bug: #2028809
Related-Bug: #1901891
Change-Id: Iea95a3c2df041a0046647b3d3dadead1a6d054d1
2023-08-10 11:35:32 +00:00
Zuul 1ac30ab59f Merge "Add default service role support to boostrap command" 2023-08-04 08:07:44 +00:00
Zuul 093b42a1ab Merge "sql: Remove service_provider.relay_state_prefix default" 2023-07-11 18:35:55 +00:00
Stephen Finucane 845e5b2494 sql: Remove service_provider.relay_state_prefix default
We shouldn't specify a server default for a configurable option since it
means our initial database schema is not consistently reproducible.
Instead, we should specify the default at runtime. It turns out we
already do this and the server default was overkill. We can remove it.

Change-Id: I74e47a9ed986c7c3af19676ac65f4d290bcb4cc0
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-07-06 10:19:05 +01:00
Zuul a2f0236e81 Merge "sql: Remove duplicate constraints" 2023-07-04 10:53:59 +00:00
Zuul 7d169870fe Merge "sql: Fix incorrect constraints" 2023-07-04 10:30:11 +00:00
Zuul 14944384a3 Merge "tests: Rework BannedDBSchemaOperations fixture" 2023-06-27 16:02:13 +00:00
Zuul 7048252d9b Merge "db: Remove legacy migrations" 2023-06-27 16:02:10 +00:00
Zuul b0c54cec2d Merge "db: Replace use of reverse cascades" 2023-06-27 16:02:08 +00:00
Zuul 95c99f91c2 Merge "db: Replace use of Query.get()" 2023-06-27 15:41:55 +00:00
Zuul 84712f96cf Merge "db: Don't pass strings to 'Connection.execute'" 2023-06-27 15:41:53 +00:00
Zuul 132fc39fd2 Merge "db: Replace use of 'autoload' parameter" 2023-06-26 21:45:59 +00:00
Zuul 409bc26d70 Merge "Don't forget to check if authorization fails" 2023-06-26 14:22:56 +00:00
Zuul 710561c829 Merge "db: Replace use of legacy select() calling style" 2023-06-22 23:24:14 +00:00
Zuul 1af39c2a72 Merge "db: Remove use of 'bind' arguments" 2023-06-22 23:24:11 +00:00
Zuul 0d884624e2 Merge "tests: Enable SQLAlchemy 2.0 deprecation warnings" 2023-06-22 23:23:54 +00:00
Zuul 95288d2ce3 Merge "fix(federation): allow using numerical group names" 2023-04-21 17:30:22 +00:00
Stephen Finucane 535bc8e22e sql: Remove duplicate constraints
A primary key is automatically unique, therefore if one or columns is
included in a primary key constraint there is no need to add a separate
unique constraint for these columns. Remove it.

Note that this only affects MySQL. Both SQLite and PostgreSQL appear to
ignore the duplicate unique constraint. As a result, it was necessary to
run auto-generation against MySQL instead of the default SQLite. The
actual command used was similar to what we normally do, however.

  $ python keystone/common/sql/migrations/manage.py revision \
      --autogenerate --message 'Remove duplicate constraints'

As always, the resulting schema migrations then needed some manual
tweaks to remove "please adjust!" comments and unnecessary imports but
they are correct.

Change-Id: I64252086f994901a5ebe05afec37a6afd3a192ee
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-04-06 11:23:03 +01:00
Abhishek Kekane d0eacc4729 Add default service role support to boostrap command
Added service role support to bootstrap command.

Closes-Bug: #1951632
Change-Id: I9cb25a111c84ecb3a09158cbe44b0954df89096c
2023-03-28 17:51:17 +00:00
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
Stephen Finucane 56c47d0a39 sql: Fix incorrect constraints
This is our first test of the autogeneration tooling integrated in
change I17c9ff9508c5e2bd9521c18973af093d7550ab5a. To generate this, we
simply removed all but one of the "skipped" constraints defined in the
'env.py' file and then ran the following command within a virtualenv:

  $ python keystone/common/sql/migrations/manage.py revision \
      --autogenerate --message 'Fix incorrect constraints'

The resulting schema migrations then needed some manual tweaks to remove
"please adjust!" comments (don't worry, the commands were correct).

Change-Id: Ie1be3df78189f4165079a43d0a9050fcece6989b
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-03-15 12:56:32 +00:00
Zuul c08d97672d Merge "OAuth 2.0 Mutual-TLS Support" 2023-03-03 17:14:58 +00:00
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
Stephen Finucane 5e9f32469e tests: Rework BannedDBSchemaOperations fixture
Two issues here. The most pressing is that we are banning use of the
'batch_alter_table' operation. There's no reason to do this as it isn't
an operation per se, but rather a way of modifying how operations run.

Fixing this highlighted a weird error case, whereby the error message
we'd see when we called a banned operation would indicate that we had
called a different operation from the one we were *actually* calling.
This made fixing the issue far more time consuming than it should have
been (I thought it was doing something else entirely!). Turns out this
is due to late binding [1]. The fixture is rewritten to avoid the issue,
simplifying it significantly in the process.

[1] https://stackoverflow.com/a/3431699/613428

Change-Id: Ib3f9099160265c4eafea1b2e38537c58eadf9a5c
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-02-28 17:46:53 +00:00
Stephen Finucane 8c9462f6fa db: Remove legacy migrations
sqlalchemy-migrate does not (and will not) support sqlalchemy 2.0. We
need to drop these migrations to ensure we can upgrade our sqlalchemy
version.

Change-Id: I31ba9e4f129a7cc28744e814b5fd28eb284ae3de
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-02-28 17:26:39 +00:00
Stephen Finucane 0bbaf63a5a db: Replace use of reverse cascades
Resolve the following RemovedIn20Warning warning:

  "ApplicationCredentialRoleModel" object is being merged into a Session
  along the backref cascade path for relationship
  "ApplicationCredentialModel.roles"; in SQLAlchemy 2.0, this reverse
  cascade will not take place.  Set cascade_backrefs to False in either
  the relationship() or backref() function for the 2.0 behavior; or to
  set globally for the whole Session, set the future=True flag

This also applies for "ApplicationCredentialAccessRuleModel" and
"AccessRuleModel.application_credential".

Change-Id: I277cb4d512ca6b4e4aca5aad60a97a78cdb961e3
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-02-28 17:26:39 +00:00
Stephen Finucane 5d2ab6c63b db: Replace use of Query.get()
Resolve the following LegacyAPIWarning warning:

  The Query.get() method is considered legacy as of the 1.x series of
  SQLAlchemy and becomes a legacy construct in 2.0. The method is now
  available as Session.get()

Change-Id: I30d0bccaddff6a1d91fcd5660f490f904e7c8965
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-02-28 17:26:39 +00:00