mirror of
https://github.com/rustfs/rustfs.git
synced 2026-12-03 06:36:35 +00:00
fix(replication): validate user destinations separately from site rules
This commit is contained in:
@@ -25,6 +25,7 @@ use tracing::error;
|
||||
|
||||
use super::replication_config_boundary::{
|
||||
ObjectOpts, ReplicationConfigurationExt as _, ReplicationRuleExt as _, invalid_replication_config_status_field,
|
||||
site_replication_rule_deployment_id,
|
||||
};
|
||||
use super::replication_error_boundary::Result;
|
||||
use super::replication_filemeta_boundary::{
|
||||
@@ -153,7 +154,9 @@ fn validate_delete_replication_config(
|
||||
"enabled replication rule has no destination ARN",
|
||||
));
|
||||
}
|
||||
if !role.is_empty() && !destination.is_empty() {
|
||||
// The reconciler appends a rule per site while preserving the operator's role.
|
||||
// Its peer ID and destination ARN identify it independently of the operator rules.
|
||||
if !role.is_empty() && !destination.is_empty() && site_replication_rule_deployment_id(rule).is_none() {
|
||||
match role_destination {
|
||||
Some(existing) if existing != destination => {
|
||||
return Err(super::replication_error_boundary::Error::other(
|
||||
@@ -755,6 +758,31 @@ mod tests {
|
||||
assert!(validate_delete_replication_config(&VersioningConfiguration::default(), Some(&config)).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_snapshot_accepts_an_operator_role_alongside_a_reconciled_site_rule() {
|
||||
let mut operator = replication_rule();
|
||||
operator.destination.bucket = "arn:rustfs:replication::operator:archive".to_owned();
|
||||
let mut site = replication_rule();
|
||||
site.id = Some("site-repl-peer".to_owned());
|
||||
site.destination.bucket = "arn:rustfs:replication::peer:photos".to_owned();
|
||||
let mut metadata = BucketMetadata::new("photos");
|
||||
metadata.versioning_config = Some(VersioningConfiguration {
|
||||
status: Some("Enabled".to_owned()),
|
||||
..Default::default()
|
||||
});
|
||||
metadata.replication_config = Some(PersistedReplicationConfiguration {
|
||||
role: operator.destination.bucket.clone(),
|
||||
rules: vec![operator, site],
|
||||
});
|
||||
let snapshot = delete_request_snapshot_from_metadata(Arc::new(metadata.clone()))
|
||||
.expect("a site rule coexists with bucket replication");
|
||||
assert_eq!(snapshot.replication_config().expect("active rules").rules.len(), 2);
|
||||
|
||||
// An operator can choose any rule ID. Its prefix alone cannot establish site ownership.
|
||||
metadata.replication_config.as_mut().unwrap().rules[1].id = Some("site-repl-other".to_owned());
|
||||
assert!(delete_request_snapshot_from_metadata(Arc::new(metadata)).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_snapshot_rejects_unknown_status_values() {
|
||||
let invalid_versioning = VersioningConfiguration {
|
||||
|
||||
Reference in New Issue
Block a user