-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit number of firewall rules per VPC #5914
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a9a8755
raise cap to 512 and use it for targets and filters too
david-crespo 27bd658
split cap into rules cap (1024) and parts cap (128)
david-crespo e76d4e6
Merge branch 'main' into max-firewall-rules
david-crespo b6932bc
Merge main into max-firewall-rules
david-crespo 5bdaedc
increase parts cap to 256 and update various doc comments
david-crespo d02e474
Merge branch 'main' into max-firewall-rules
david-crespo 8d69b62
more detailed description in API rule replace endpoint
david-crespo a1ecf5a
had to update the sled agent API JSON for the first time in my dang life
david-crespo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,20 +211,55 @@ pub struct VpcFirewallRule { | |
pub priority: VpcFirewallRulePriority, | ||
} | ||
|
||
/// Cap on the number of rules in a VPC | ||
/// | ||
/// The choice of value is somewhat arbitrary, but the goal is to have a | ||
/// large number that customers are unlikely to actually hit, but which still | ||
/// meaningfully limits the ability to overload the DB with a single request. | ||
const MAX_FW_RULES_PER_VPC: usize = 1024; | ||
|
||
/// Cap on targets and on each type of filter | ||
const MAX_FW_RULE_PARTS: usize = 256; | ||
|
||
fn ensure_max_len<T>( | ||
items: &Vec<T>, | ||
label: &str, | ||
max: usize, | ||
) -> Result<(), external::Error> { | ||
if items.len() > max { | ||
let msg = format!("max length {}", max); | ||
return Err(external::Error::invalid_value(label, msg)); | ||
} | ||
Ok(()) | ||
} | ||
|
||
impl VpcFirewallRule { | ||
pub fn new( | ||
rule_id: Uuid, | ||
vpc_id: Uuid, | ||
rule: &external::VpcFirewallRuleUpdate, | ||
) -> Self { | ||
) -> Result<Self, external::Error> { | ||
let identity = VpcFirewallRuleIdentity::new( | ||
rule_id, | ||
external::IdentityMetadataCreateParams { | ||
name: rule.name.clone(), | ||
description: rule.description.clone(), | ||
}, | ||
); | ||
Self { | ||
|
||
ensure_max_len(&rule.targets, "targets", MAX_FW_RULE_PARTS)?; | ||
|
||
if let Some(hosts) = rule.filters.hosts.as_ref() { | ||
ensure_max_len(&hosts, "filters.hosts", MAX_FW_RULE_PARTS)?; | ||
} | ||
if let Some(ports) = rule.filters.ports.as_ref() { | ||
ensure_max_len(&ports, "filters.ports", MAX_FW_RULE_PARTS)?; | ||
} | ||
if let Some(protocols) = rule.filters.protocols.as_ref() { | ||
ensure_max_len(&protocols, "filters.protocols", MAX_FW_RULE_PARTS)?; | ||
} | ||
Comment on lines
+250
to
+260
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a customer is exceeding 2 or more of these limits, it'd be really nice to get a single error message that tells them every limit they've exceeded. WDYT? |
||
|
||
Ok(Self { | ||
identity, | ||
vpc_id, | ||
status: rule.status.into(), | ||
|
@@ -248,19 +283,20 @@ impl VpcFirewallRule { | |
}), | ||
action: rule.action.into(), | ||
priority: rule.priority.into(), | ||
} | ||
}) | ||
} | ||
|
||
pub fn vec_from_params( | ||
vpc_id: Uuid, | ||
params: external::VpcFirewallRuleUpdateParams, | ||
) -> Result<Vec<VpcFirewallRule>, external::Error> { | ||
ensure_no_duplicates(¶ms)?; | ||
Ok(params | ||
ensure_max_len(¶ms.rules, "rules", MAX_FW_RULES_PER_VPC)?; | ||
params | ||
.rules | ||
.iter() | ||
.map(|rule| VpcFirewallRule::new(Uuid::new_v4(), vpc_id, rule)) | ||
.collect()) | ||
.into_iter() | ||
.map(|rule| VpcFirewallRule::new(Uuid::new_v4(), vpc_id, &rule)) | ||
.collect() | ||
} | ||
} | ||
|
||
|
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just occurred to me. We don't support port ranges (e.g. "3000-4000") as a value, do we? If so, we should increase this number. Or better yet, add support for port ranges at some point.
If we do support port ranges, then ignore this comment :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do support ranges. You just put in
“123-456”
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet! Can we add that to the API docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's sort of in there, but I will improve the wording.