Expand description
The cloud-provider IP table and block selectors.
This is the Rust family’s port of the reference engine’s cloud-provider
blocking data path (guard_core/handlers/cloud_handler.py plus the
selector registry in guard_core/handlers/_cloud_provider_registry.py
and the config validation in guard_core/models.py). It carries three
pieces:
parse_cloud_selectors: theblock_cloud_providerssyntax. A bare name ("GCP") blocks the whole provider; a":!region"suffix ("GCP:!us-central1") blocks the provider except that region. An unrecognized provider name is a config error, exactly the reference_validate_block_cloud_providers_valueValueError.CloudIpTable: the provider ranges the block check consults. The reference keeps a module-singleton handler fed by background fetchers (with Redis caching and a refresh interval); those are I/O concerns this engine does not own, so the table is an in-memory store the adapter feeds (set_provider_ranges), shareable across clones.CloudIpTable::is_cloud_ip: the referenceis_cloud_ipwalk - for every selected provider that has ranges loaded, an address inside one of its networks is blocked unless the network’s region is carved out.
§Details that mirror the reference exactly
- Region carve-outs only exempt networks whose region is known (the
reference
network_regions.get(str(network)) in allowed_regions): a provider that publishes no region data (Azure,DigitalOcean,Linode,Vultr) blocks its whole provider even under a carve-out. - Providers with no ranges loaded are skipped, not blocked (the
reference
if provider not in self.ip_ranges: continue), and an empty range set for a loaded provider blocks nothing (the reference only logs a warning). - Family-strict matching: an IPv4 network never contains an IPv6
address and vice versa, like
ipaddressmembership.
§Example
use guard_core_engine::cloud_provider::{parse_cloud_selectors, CloudIpTable};
use std::net::IpAddr;
use std::str::FromStr;
// Block GCP except one region, and all of AWS.
let selectors = parse_cloud_selectors(["GCP:!us-central1", "AWS"]).expect("valid selectors");
let table = CloudIpTable::default();
table
.set_provider_ranges(
"AWS",
vec![("203.0.113.0/24".to_owned(), None)],
)
.expect("valid ranges");
table
.set_provider_ranges(
"GCP",
vec![
("198.51.100.0/24".to_owned(), Some("us-central1".to_owned())),
("198.51.101.0/24".to_owned(), Some("europe-west1".to_owned())),
],
)
.expect("valid ranges");
// An AWS address is blocked ...
assert!(table.is_cloud_ip(IpAddr::from_str("203.0.113.9").unwrap(), &selectors));
// ... a GCP address in the carved-out region is not ...
assert!(!table.is_cloud_ip(IpAddr::from_str("198.51.100.9").unwrap(), &selectors));
// ... a GCP address elsewhere is ...
assert!(table.is_cloud_ip(IpAddr::from_str("198.51.101.9").unwrap(), &selectors));
// ... and a datacenter address belonging to nobody passes.
assert!(!table.is_cloud_ip(IpAddr::from_str("192.0.2.1").unwrap(), &selectors));Structs§
- Cloud
Config Error - An invalid
block_cloud_providersentry: the config errorparse_cloud_selectorsfails closed with. - Cloud
IpTable - The provider ranges the block check consults.
- Cloud
Range Error - An invalid range entry: the error
CloudIpTable::set_provider_rangesfails with. - Cloud
Selectors - The parsed
block_cloud_providersselectors: the blocked provider names in first-seen order, each optionally carrying carved-out regions. - Provider
Status - One cloud provider’s row of the status payload (the reference
cloud_handler.get_statusshape).
Constants§
- CARVE_
OUT_ SEPARATOR - The selector separator carving a region exception out of a block
(
":!"in the reference_parse_cloud_selectors). - VALID_
CLOUD_ PROVIDERS - The providers the reference publishes range data for
(
VALID_CLOUD_PROVIDERS/_ALL_PROVIDERS).
Functions§
- parse_
cloud_ selectors - Parse the
block_cloud_providersselectors, failing closed on an unknown provider name.