Open adaminato42 opened 8 months ago
Voting for Prioritization
Volunteering to Work on This Issue
Do multiple stateful_rule
blocks get ordered properly? I see that’s also described in documentation as a set, which is unordered (and thus inappropriate in this context, if the documentation is accurate).
Do multiple
stateful_rule
blocks get ordered properly? I see that’s also described in documentation as a set, which is unordered (and thus inappropriate in this context, if the documentation is accurate).
When declared in Terraform, only a single stateful_rule
can exist per rules_source
section as per the docs.
The ordering of the rule groups is handled in aws_networkfirewall_firewall_policy
, using multiple stateful_rule_group_reference
entries which have a priority.
The important part here is the ordering of the rule_options
has to be maintained to create properly constructed Suricata rule string
Do multiple
stateful_rule
blocks get ordered properly? I see that’s also described in documentation as a set, which is unordered (and thus inappropriate in this context, if the documentation is accurate).When declared in Terraform, only a single
stateful_rule
can exist perrules_source
section as per the docs.
That’s not how I’m reading it — the docs there describe it as “(Optional) Set of configuration blocks containing stateful inspection criteria for 5-tuple rules to be used together in a rule group.”, which is the exact same way that rule_option
is described (as a set of configuration blocks) and talks about rules, plural. And the nature of a rule group is to have a collection of rules within it, some of which may well interact with each other, so it seems to me that it couldn’t possibly be the case that Terraform-created rule groups are only allowed to contain a single rule, any more so than it would make senses for it to only allow setting a single rule option. If that is the case then that’s a much bigger problem in the provider.
That’s not how I’m reading it — the docs there describe it as “(Optional) Set of configuration blocks containing stateful inspection criteria for 5-tuple rules to be used together in a rule group.”, which is the exact same way that
rule_option
is described (as a set of configuration blocks) and talks about rules, plural.
It is a set of blocks, but they are specific blocks:
rule_group {
rules_source { # Only one of rules_source_list, rules_string, stateful_rule, or stateless_rules_and_custom_actions must be specified
stateful_rule { # Required
action # Required
header { block } # Required, one only
rule_option { block } # Optional, zero to many
rule_option { block } ...
}
}
}
While the AWS Console UI allows to add multiple stateful rules to the same rule group, Terraform does not. From my perspective, that's a feature parity issue.
The concern for us is that multiple rule_option
entries do not maintain their ordering, which breaks the Suricata language syntax when generated.
Similar to #27102, which addressed ordering of the stateful_rule
block
Terraform Core Version
1.6.6
AWS Provider Version
5.31.0
Affected Resource(s)
aws_networkfirewall_rule_group
Expected Behavior
Network firewall group created
Actual Behavior
Error (due to re-ordering of options) "reason: endswith needs a preceding content option"
Relevant Error/Panic Output Snippet
Terraform Configuration Files
main.tf
network_firewall_group.tf
Steps to Reproduce
A
terraform plan
will be created without issue, but you can see therule_option
sections are now ordered alphabetically bykeyword
:A
terraform apply
will fail, as the ordering appears randomDebug Output
aws_networkfirewall_rule_group.tf_log.debug.txt
Panic Output
No response
Important Factoids
No response
References
We are able to create these rules via the AWS Console. The API documentation https://docs.aws.amazon.com/network-firewall/latest/developerguide/stateful-rule-groups-basic.html https://docs.aws.amazon.com/network-firewall/latest/APIReference/API_StatefulRule.html https://docs.aws.amazon.com/network-firewall/latest/APIReference/API_RuleOption.html
Would you like to implement a fix?
None