refactor: Redesign SecurityContext with two-phase validation#717
Merged
Conversation
420272b to
369f289
Compare
|
🦢 Load Test Results Goose Attack ReportPlan Overview
Request Metrics
Response Time Metrics
Status Code Metrics
Transaction Metrics
Scenario Metrics
|
|
| Branch | token_refactor2 |
| Testbed | ubuntu-latest |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result nanoseconds (ns) (Result Δ%) | Upper Boundary nanoseconds (ns) (Limit %) |
|---|---|---|---|
| Command_Serde/apply/remove | 📈 view plot 🚷 view threshold | 84,407.00 ns(-38.34%)Baseline: 136,889.80 ns | 363,880.12 ns (23.20%) |
| Command_Serde/apply/set | 📈 view plot 🚷 view threshold | 82,967.00 ns(-36.37%)Baseline: 130,398.25 ns | 241,779.95 ns (34.32%) |
| Command_Serde/pack/delete | 📈 view plot 🚷 view threshold | 124.66 ns(+1.11%)Baseline: 123.30 ns | 145.91 ns (85.43%) |
| Command_Serde/pack/delete_index | 📈 view plot 🚷 view threshold | 116.56 ns(+1.21%)Baseline: 115.16 ns | 135.36 ns (86.11%) |
| Command_Serde/pack/set | 📈 view plot 🚷 view threshold | 195.88 ns(-2.05%)Baseline: 199.97 ns | 237.89 ns (82.34%) |
| Command_Serde/pack/set_index | 📈 view plot 🚷 view threshold | 116.26 ns(+0.77%)Baseline: 115.38 ns | 135.51 ns (85.80%) |
| Command_Serde/unpack/delete | 📈 view plot 🚷 view threshold | 203.82 ns(+9.10%)Baseline: 186.82 ns | 232.62 ns (87.62%) |
| Command_Serde/unpack/delete_index | 📈 view plot 🚷 view threshold | 194.69 ns(+20.83%)Baseline: 161.13 ns | 198.74 ns (97.96%) |
| Command_Serde/unpack/set | 📈 view plot 🚷 view threshold | 272.81 ns(+11.63%)Baseline: 244.38 ns | 290.07 ns (94.05%) |
| Command_Serde/unpack/set_index | 📈 view plot 🚷 view threshold | 175.31 ns(+9.70%)Baseline: 159.81 ns | 199.77 ns (87.76%) |
| Payload_encryption/pack/inner | 📈 view plot 🚷 view threshold | 68.21 ns(+4.58%)Baseline: 65.22 ns | 77.11 ns (88.45%) |
| Payload_encryption/pack/remove_cmd | 📈 view plot 🚷 view threshold | 120.75 ns(-2.03%)Baseline: 123.25 ns | 147.29 ns (81.98%) |
| Payload_encryption/pack/set_cmd | 📈 view plot 🚷 view threshold | 223.14 ns(-5.58%)Baseline: 236.33 ns | 293.35 ns (76.07%) |
| Payload_encryption/unpack/inner | 📈 view plot 🚷 view threshold | 164.92 ns(+0.89%)Baseline: 163.47 ns | 192.08 ns (85.86%) |
| Payload_encryption/unpack/remove_cmd | 📈 view plot 🚷 view threshold | 209.49 ns(+6.74%)Baseline: 196.26 ns | 240.59 ns (87.07%) |
| Payload_encryption/unpack/set_cmd | 📈 view plot 🚷 view threshold | 270.23 ns(+4.12%)Baseline: 259.53 ns | 321.43 ns (84.07%) |
| Raft_1Node_Latency/prefix/1node | 📈 view plot 🚷 view threshold | 6,564,900.00 ns(+85.38%)Baseline: 3,541,268.18 ns | 6,586,735.26 ns (99.67%) |
| Raft_1Node_Latency/read/1node | 📈 view plot 🚷 view threshold | 594.28 ns(+8.03%)Baseline: 550.13 ns | 785.42 ns (75.66%) |
| Raft_1Node_Latency/remove/1node | 📈 view plot 🚷 view threshold | 250,260.00 ns(-30.50%)Baseline: 360,108.18 ns | 646,479.38 ns (38.71%) |
| Raft_1Node_Latency/write/1node | 📈 view plot 🚷 view threshold | 251,780.00 ns(-33.09%)Baseline: 376,302.27 ns | 820,133.08 ns (30.70%) |
| build_snapshot/default | 📈 view plot 🚷 view threshold | 95,168.00 ns(+5.52%)Baseline: 90,192.50 ns | 145,067.03 ns (65.60%) |
| fernet token/project | 📈 view plot 🚷 view threshold | 1,440.90 ns(-2.67%)Baseline: 1,480.39 ns | 1,593.72 ns (90.41%) |
| get_data_keyspace | 📈 view plot 🚷 view threshold | 0.35 ns(+10.45%)Baseline: 0.32 ns | 0.37 ns (94.43%) |
| get_db | 📈 view plot 🚷 view threshold | 0.35 ns(+11.51%)Baseline: 0.32 ns | 0.37 ns (95.03%) |
| get_fernet_token_timestamp/project | 📈 view plot 🚷 view threshold | 145.80 ns(-2.24%)Baseline: 149.14 ns | 173.52 ns (84.03%) |
| get_keyspace | 📈 view plot 🚷 view threshold | 4.83 ns(+1.43%)Baseline: 4.76 ns | 9.31 ns (51.84%) |
gtema
commented
May 23, 2026
| pub fn from_security_context<S: Into<String>>( | ||
| ctx: &SecurityContext, | ||
| trust: &Trust, | ||
| trust: S, |
Collaborator
Author
There was a problem hiding this comment.
Should be renamed to trust_id
| type Error = openstack_keystone_core_types::error::BuilderError; | ||
|
|
||
| fn try_from(vsc: &crate::auth::ValidatedSecurityContext) -> Result<Self, Self::Error> { | ||
| use openstack_keystone_api_types::v3::auth::token::{TokenBuilder, UserBuilder}; |
Collaborator
Author
There was a problem hiding this comment.
Move imports to module top
| response.methods(methods); | ||
| } | ||
|
|
||
| let (user_id, user_name, auth_domain, user_password_expires_at) = build_user_info(ctx)?; |
Collaborator
Author
There was a problem hiding this comment.
Auth_domain ->user_domain
| } | ||
| } | ||
|
|
||
| fn build_user_info( |
Collaborator
Author
There was a problem hiding this comment.
Fill User builder instead
| } | ||
| ScopeInfo::Unscoped => {} | ||
| } | ||
| match authz.effective_roles() { |
Collaborator
Author
There was a problem hiding this comment.
Perhaps the whole construct can be simplified
| AuthenticationContext::Trust { .. } => { | ||
| Err(AuthenticationError::ScopeNotAllowed.into()) | ||
| } | ||
| _ => Ok(Self::DomainScope( |
Collaborator
Author
There was a problem hiding this comment.
Do not implement fallback here
| let authz_info = get_authz_info(&state, &req).await?; | ||
|
|
||
| if let Some(bound) = ctx.authorization() | ||
| && bound.scope != authz_info |
Collaborator
Author
There was a problem hiding this comment.
Would it fail if e.g., description field changes?
| /// # Parameters | ||
| /// * `policy_name` - The name of the policy to evaluate. | ||
| /// * `credentials` - The token containing the requester's credentials. | ||
| /// * `credentials` - The SecurityContext of the connection. |
Collaborator
Author
There was a problem hiding this comment.
Its perhaps a request and not connection
| ..Default::default() | ||
| }; | ||
|
|
||
| let auth = AuthenticationResultBuilder::default() |
Collaborator
Author
There was a problem hiding this comment.
Check whether fixture in core can be used
Access control and encapsulation: - Make all SecurityContext fields pub(crate) with explicit getter/setter methods to enforce encapsulation - Replace for_testing() with SecurityContextTestingBuilder for structured test fixture construction Validation architecture: - Remove validator crate dependency from auth.rs, replacing opaque ValidationErrors with typed AuthenticationError variants - Merge dual validate/xvalidate split into single validate() method per auth type returning specific errors: UserDisabled(id), DomainDisabled(id), AuthzPrincipalMismatch, PrincipalDomainIdMissing - Add validate() to PrincipalInfo, IdentityInfo, UserIdentityInfo, PrincipalIdentityInfo, ScopeInfo, and SecurityContext Structural improvements: - Box ScopeInfo::TrustProject variant as TrustProjectInfo to control enum size (smaller variants remain stack-allocated) - Replace new_with_roles() with new_for_scope(ctx, scope, state) taking explicit scope parameter for unambiguous caller control - Add #[must_use] with descriptive messages on validate() methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Access control and encapsulation:
Validation architecture:
Structural improvements: