Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/config/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,30 @@ pub struct TokenProvider {
/// compromised token.
#[serde(default = "default_token_expiration")]
pub expiration: usize,
/// Controls whether token revocation is enabled for group role
/// assignments. When disabled (default), group role revocations do not
/// create revocation events since token validation rebuilds assignments
/// at validation time. Enabling this creates revocation events for group
/// assignments but may cause overly broad token invalidation.
/// Matches Python Keystone's [token] revoke_by_id option.
#[serde(default = "default_revoke_by_id")]
pub revoke_by_id: bool,
Comment on lines +37 to +44

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Matches Python Keystone's [token] revoke_by_id option" is misleading:

  • Python default is True, not false.
  • Python's flag gates a non-destructive token-cache flush; it never persists the broad (scope, role) revocation event. Here revoke_by_id=true re-enables exactly that broad event (see service.rs comment). The Rust flag means "restore broad scope+role revocation for group grants", which is the pre-#1662514 behavior, not Python parity.

Also: this option is not surfaced in the sample / reference config. Add it next to [token] expiration with help text that describes the actual Rust behavior.

}

fn default_token_expiration() -> usize {
3600
}

fn default_revoke_by_id() -> bool {
false
}

impl Default for TokenProvider {
fn default() -> Self {
Self {
provider: TokenProviderDriver::Fernet,
expiration: default_token_expiration(),
revoke_by_id: default_revoke_by_id(),
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions crates/core-types/src/assignment/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ impl AssignmentCreate {
)
}

/// Instantiate GroupSystem assignment.
pub fn group_system<A, T, R>(actor_id: A, target_id: T, role_id: R, inherited: bool) -> Self
where
A: Into<String>,
T: Into<String>,
R: Into<String>,
{
Self::new(
actor_id,
target_id,
role_id,
AssignmentType::GroupSystem,
inherited,
)
}

/// Instantiate UserDomain assignment.
pub fn user_domain<A, T, R>(actor_id: A, target_id: T, role_id: R, inherited: bool) -> Self
where
Expand Down
42 changes: 31 additions & 11 deletions crates/core/src/assignment/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,17 +813,37 @@ impl AssignmentApi for AssignmentService {
audit_chain_id: None,
revoked_at: chrono::Utc::now(),
};

// ADR 0034 §4: the central revocation event stays on the global revoke
// provider, unrouted — it is not an assignment-backend operation.
ctx.state()
.provider
.get_revoke_provider()
.create_revocation_event(ctx, revocation_event)
.await?;
// ADR 0031 "Tokens": revoking a grant cascades revocation of every
// token carrying that role - `"cascade"`, not a direct user request.
crate::token::TOKEN_METRICS.revoked_total.inc(["cascade"]);
// Only create revocation event for group assignments if revoke_by_id is enabled.
// By default group revocations do not create revocation events since token
// validation rebuilds assignments at validation time.
// Reference: Python Keystone bug #1662514
let is_group_assignment = matches!(
&grant.r#type,
AssignmentType::GroupDomain
| AssignmentType::GroupProject
| AssignmentType::GroupSystem
);

let revoke_by_id = ctx

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading config.read().await.token.revoke_by_id per revoke is fine. But note the default (false, config/token.rs) is the opposite of Python's (keystone/conf/token.py:82default=True). false is the right call for Rust since the true path is the buggy one — but the PR description's "(default: false)" claim about Python is wrong; state the real reason Rust diverges.

.state()
.config_manager
.config
.read()
.await
.token
.revoke_by_id;
if !is_group_assignment || revoke_by_id {
// ADR 0034 §4: the central revocation event stays on the global revoke
// provider, unrouted — it is not an assignment-backend operation.
ctx.state()
.provider
.get_revoke_provider()
.create_revocation_event(ctx, revocation_event)
.await?;
// ADR 0031 "Tokens": revoking a grant cascades revocation of every
// token carrying that role - `"cascade"`, not a direct user request.
crate::token::TOKEN_METRICS.revoked_total.inc(["cascade"]);
}
Comment on lines +816 to +846

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cross-checked against Python Keystone (opendev.org/openstack/keystone @ 5f1d13f38), bug #1662514, fix 9a4391c49.

The diagnosis is correct: Rust currently builds an over-broad revoke event for group grants (RevocationEventCreate { user_id: None, role_id: Some, project/domain } at L802) — exactly the pre-2017 Python bug. Guarding it is the right fix, and validation-time recomputation makes it safe: calculate_effective_roles (auth.rs:666) runs every validation and the SQL driver expands user_id → list_groups_of_user → group actors for domain/project/system scope (assignment-driver-sql/src/lib.rs:289). The PR's "known limitation" is the reverse direction (group → members) and does not affect token validation.

Three problems:

  1. 🔴 revoke_by_id=true is not equivalent to Python's revoke_by_id=True — it re-introduces the bug. Modern Python gates only _invalidate_token_cache(...) on the flag: a blanket, non-destructive cache flush (still-valid tokens survive; test_v3_auth.py token3 now expects OK). Python never re-persists the broad (scope, role) event, flag on or off. This true branch calls create_revocation_event with user_id: None → a hard revocation via is_token_revoked that permanently kills every token carrying that role on that scope, including users with a direct assignment. Enabling the flag = "revert #1662514". Fix: resolve group members and emit per-user-scoped events, or rename/document the flag as "restores broad scope+role revocation for group grants; NOT equivalent to Python [token] revoke_by_id".

  2. Scope creep. is_group_assignment also covers GroupDomain | GroupProject, changing revoke behavior for pre-existing endpoints, not just the new system/group one. Call this out in the PR description and in the security-model / ADR 0031 — revocation is a MUST-READ area.

  3. No test for the new branch. test_revoke_grant (L448) only exercises UserProject. Add: GroupSystem + revoke_by_id=falsecreate_revocation_event not called; GroupProject same; any group + revoke_by_id=true → event created; UserProject unchanged.


Ok(())
}
Expand Down
23 changes: 23 additions & 0 deletions crates/keystone/src/api/v3/role_assignment/system/group/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
//! # System Group role API
use utoipa_axum::router::OpenApiRouter;

use crate::keystone::ServiceState;

mod role;

pub(crate) fn openapi_router() -> OpenApiRouter<ServiceState> {
OpenApiRouter::new().merge(role::openapi_router())
}
Loading
Loading