mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-26 08:18:18 +00:00
92f83bfe15
* fix(policy): quantify negated string conditions per value
ForAllValues:/ForAnyValue: negated string operators computed the positive
quantified match and then negated the aggregate. That yields NOT(all match)
and NOT(any match), which is the semantics of the *other* quantifier, so
ForAllValues:StringNotEquals and ForAnyValue:StringNotEquals were exactly
transposed. The same applied to StringNotEqualsIgnoreCase, StringNotLike,
ArnNotEquals and ArnNotLike.
Introduce an explicit Quantifier and push negation into the per-value
predicate for the qualified forms, so ForAllValues requires every request
value to satisfy the operator and ForAnyValue requires at least one.
Unqualified operators keep negating the aggregate, preserving AWS
single-valued-key semantics. Absent keys now follow AWS: ForAllValues is
vacuously satisfied, ForAnyValue is not.
A request value set that is fully contained in or fully disjoint from the
policy set cannot distinguish the two quantifiers, which is why the existing
cases missed this; the new tests use partially overlapping sets.
* fix(auth): keep request headers out of server-derived condition keys
get_condition_values folded every remaining request header into the policy
condition map. HeaderMap lowercases header names, and the server-derived keys
userid, username, principaltype, versionid and signatureversion are lowercase
too, so a header of the same name collided with them. The collision branch used
extend(), and non-quantified string operators match if ANY value in the vector
matches, so sending `userid: admin` was enough to satisfy a condition on
aws:userid. The jwt:/ldap: claim keys were reachable the same way whenever the
credential carried no such claim.
groups was worse than an append: the header loop ran before the cred.groups
block, which is gated on !args.contains_key("groups"), so a `groups:` header
both injected a value and suppressed the credential's real group list.
Resolve claims and group membership before merging headers, then skip any header
naming a key the server already derived or a well-known identity/context key.
The reserved set comes from KeyName so it tracks the key registry; s3:x-amz-*
keys stay mergeable because they mirror request headers by design.
* fix(access): gate the ListBucketVersions fallback on public-access checks
An anonymous request for ListObjectVersions that the bucket policy does not
grant directly falls back to re-checking the grant as s3:ListBucket. That
fallback returned Ok(()) straight away, skipping the two gates the direct grant
passes through: deny_anonymous_table_data_plane_if_needed and the
RestrictPublicBuckets check on the bucket's public-access block.
So a bucket whose policy allows anonymous s3:ListBucket kept serving anonymous
version listings after an operator enabled RestrictPublicBuckets, even though
the equivalent GetObject was correctly denied.
Fold the fallback into policy_allowed so both routes reach the same gates.
* fix(ftps): authorize MKD against the CreateBucket boundary
FTPS MKD creates a bucket but ran no authorization check, so any principal that
could open an FTPS session could create buckets regardless of policy. Every
other operation in this driver authorizes first — LIST, RETR, STOR, DELE and
RMD all call authorize_operation — and the WebDAV gateway checks
S3Action::CreateBucket on the equivalent path.
Add the matching check so MKD clears the same boundary as an S3 CreateBucket.
101 lines
4.2 KiB
Rust
101 lines
4.2 KiB
Rust
//! Regression tests for quantified negated string conditions.
|
|
//!
|
|
//! AWS semantics:
|
|
//! ForAllValues:StringNotEquals -> true iff EVERY request value is absent from the policy set.
|
|
//! ForAnyValue:StringNotEquals -> true iff AT LEAST ONE request value is absent from the policy set.
|
|
//!
|
|
//! Negating the aggregate result of the positive quantified match instead of the
|
|
//! per-value predicate yields NOT(all match) and NOT(any match) respectively,
|
|
//! which transposes the two quantifiers. The discriminating case is a request
|
|
//! whose values partially overlap the policy set; a set that is fully contained
|
|
//! or fully disjoint cannot tell the two apart.
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use rustfs_policy::policy::Functions;
|
|
|
|
fn ctx(key: &str, vals: &[&str]) -> HashMap<String, Vec<String>> {
|
|
let mut m = HashMap::new();
|
|
m.insert(key.to_owned(), vals.iter().map(|s| (*s).to_owned()).collect());
|
|
m
|
|
}
|
|
|
|
fn eval(json: &str, values: &HashMap<String, Vec<String>>) -> bool {
|
|
let f: Functions = serde_json::from_str(json).expect("parse condition");
|
|
pollster::block_on(f.evaluate(values))
|
|
}
|
|
|
|
#[test]
|
|
fn for_all_values_string_not_equals_partial_overlap() {
|
|
// groups = {art, hr}; policy set = {prod, art}. "art" IS in the set,
|
|
// so not every value is "not equal" -> AWS says false.
|
|
let v = ctx("groups", &["art", "hr"]);
|
|
let got = eval(r#"{"ForAllValues:StringNotEquals":{"jwt:groups":["prod","art"]}}"#, &v);
|
|
assert!(
|
|
!got,
|
|
"ForAllValues:StringNotEquals must be false when a request value matches the policy set"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn for_any_value_string_not_equals_partial_overlap() {
|
|
// groups = {art, hr}; policy set = {prod, art}. "hr" is NOT in the set,
|
|
// so at least one value is "not equal" -> AWS says true.
|
|
let v = ctx("groups", &["art", "hr"]);
|
|
let got = eval(r#"{"ForAnyValue:StringNotEquals":{"jwt:groups":["prod","art"]}}"#, &v);
|
|
assert!(
|
|
got,
|
|
"ForAnyValue:StringNotEquals must be true when some request value is outside the policy set"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn for_all_values_string_not_equals_missing_key() {
|
|
// ForAllValues is vacuously true when the key is absent from the request.
|
|
let v = HashMap::new();
|
|
let got = eval(r#"{"ForAllValues:StringNotEquals":{"jwt:groups":["prod","art"]}}"#, &v);
|
|
assert!(got, "ForAllValues:* is vacuously true when the context key is absent");
|
|
}
|
|
|
|
#[test]
|
|
fn for_any_value_string_not_equals_missing_key() {
|
|
// ForAnyValue is false when the key is absent -- there is no value to satisfy it.
|
|
let v = HashMap::new();
|
|
let got = eval(r#"{"ForAnyValue:StringNotEquals":{"jwt:groups":["prod","art"]}}"#, &v);
|
|
assert!(!got, "ForAnyValue:* is false when the context key is absent");
|
|
}
|
|
|
|
#[test]
|
|
fn for_all_values_string_not_like_partial_overlap() {
|
|
// Same inversion for the wildcard family (R03-CAN-042).
|
|
let v = ctx("groups", &["art-team", "hr"]);
|
|
let got = eval(r#"{"ForAllValues:StringNotLike":{"jwt:groups":["art-*"]}}"#, &v);
|
|
assert!(!got, "ForAllValues:StringNotLike must be false when a request value matches the pattern");
|
|
}
|
|
|
|
#[test]
|
|
fn for_any_value_string_not_like_partial_overlap() {
|
|
let v = ctx("groups", &["art-team", "hr"]);
|
|
let got = eval(r#"{"ForAnyValue:StringNotLike":{"jwt:groups":["art-*"]}}"#, &v);
|
|
assert!(got, "ForAnyValue:StringNotLike must be true when some request value does not match");
|
|
}
|
|
|
|
/// Positive (non-negated) quantifiers must keep working -- guards against a fix
|
|
/// that flips these instead.
|
|
#[test]
|
|
fn positive_quantifiers_unchanged() {
|
|
let partial = ctx("groups", &["art", "hr"]);
|
|
let contained = ctx("groups", &["art"]);
|
|
let empty = HashMap::new();
|
|
|
|
let all_eq = r#"{"ForAllValues:StringEquals":{"jwt:groups":["prod","art"]}}"#;
|
|
let any_eq = r#"{"ForAnyValue:StringEquals":{"jwt:groups":["prod","art"]}}"#;
|
|
|
|
assert!(!eval(all_eq, &partial), "ForAllValues:StringEquals false when a value is outside the set");
|
|
assert!(eval(all_eq, &contained), "ForAllValues:StringEquals true when all values are in the set");
|
|
assert!(eval(all_eq, &empty), "ForAllValues:StringEquals vacuously true on absent key");
|
|
|
|
assert!(eval(any_eq, &partial), "ForAnyValue:StringEquals true when some value is in the set");
|
|
assert!(!eval(any_eq, &empty), "ForAnyValue:StringEquals false on absent key");
|
|
}
|