Repository navigation
fix(networkfirewall): validate replacement before replacing state - #4114
Conversation
|
👋 Thanks for the pull request! It looks like you now have 8 open pull requests in this repository, which is above our advisory limit of 5. To keep the review backlog focused and make sure every contribution gets proper attention, we ask contributors to shepherd their existing PRs to the finish line before opening new ones — responding to review feedback, rebasing, or closing any that are no longer needed. Here is your list of open PRs. Nothing is blocked and this PR stays open — this is just a friendly nudge. The If some of these PRs are stacked or intentionally related, just say so here and a maintainer will take that into account. |
pgermosen
left a comment
There was a problem hiding this comment.
Thanks for this! Validating the replacement before touching the store is the right fix. Today a bad update deletes the rule group or policy and then fails to recreate it, so the resource is just gone. Keeping the existing ARN and returning ResourceNotFoundException for a missing resource both match the model too.
One gap is left, though, and it's the path Terraform uses. For both operations the model says "You must specify the ARN or the name, and you can specify both", and for rule groups Type "is required for requests that do not include the RuleGroupARN". The update still requires the name (and Type for rule groups) up front: ruleGroupArn(request, ...) is evaluated before replaceNamed runs, updateFirewallPolicy calls requiredText(request, "FirewallPolicyName"), and buildNamed requires it again. The Terraform provider's aws_networkfirewall_firewall_policy update sends only FirewallPolicyArn, and aws_networkfirewall_rule_group sends RuleGroupArn plus Type, with no name in either. So every Terraform update of these two resources still gets a 400. It's a lot better than losing the resource, but it's still a failure.
Since replaceNamed already looks up existing, the fix can stay in there: when the request leaves out the name (or the type), take it from the stored resource, and only do the ARN-versus-name check when a name was actually sent. A test that updates each resource by ARN alone would pin it.
Could you also fill in the Summary and AWS Compatibility sections of the description? Right now it's just the empty template.
310d7ff to
ebc3369
Compare
|
All three in ebc3369: updates are identified by ARN alone, taking the name (and the rule group |
|
| ObjectNode replacement = buildNamed(effectiveRequest, nameField, requestBodyField, responseField, | ||
| arnField, idField, existingArn, store, existingArn); | ||
| store.put(existingArn, replacement); |
There was a problem hiding this comment.
Stale updates overwrite newer changes
When two rule-group or firewall-policy updates overlap, this path writes the replacement without comparing the request's UpdateToken with the stored token. buildNamed then discards the supplied token and generates a new one. A stale update can therefore overwrite a newer definition instead of returning InvalidTokenException; updates with no token are accepted too.
| String type = textOrNull(request, "Type"); | ||
| if (type != null) { | ||
| requireEnum(type, RULE_GROUP_TYPES, "Type"); | ||
| } | ||
| return replaceNamed(request, "RuleGroupName", "RuleGroup", "RuleGroupResponse", |
There was a problem hiding this comment.
An update can set Type to STATELESS on an existing stateful rule group because this check validates only that the value is in the enum. The replacement keeps the old stateful-rulegroup ARN while storing the new type, so describe and type-filtered list responses expose a stateless group with a stateful ARN.
| ObjectNode replacement = buildNamed(effectiveRequest, nameField, requestBodyField, responseField, | ||
| arnField, idField, existingArn, store, existingArn); | ||
| store.put(existingArn, replacement); |
There was a problem hiding this comment.
Missing body erases definition
If an ARN-only update omits RuleGroup or FirewallPolicy, this path still writes a replacement. buildNamed leaves the body out when it is absent, so the update returns success but silently erases the stored rules or policy. Validate the update body before replacing the resource.
pgermosen
left a comment
There was a problem hiding this comment.
Thanks, this is exactly what I was after. An update by ARN alone now picks up the stored name and type, the ARN-versus-name check only runs when a name is sent, and the new tests cover both resources that way. The description reads well now too.
One small thing left. The firewall methods in NetworkFirewallService are synchronized, but the rule group and firewall policy create, update and delete methods aren't. replaceNamed reads the existing resource, validates, and then puts the replacement back, so a DeleteRuleGroup (or DeleteFirewallPolicy) that lands in between gets undone: the update writes the resource back after it was deleted. Marking those methods synchronized, like the firewall ones, would close it.
The red shard is Docker Hub rate limiting in the ECS container tests, nothing to do with this change.
…n update UpdateRuleGroup and UpdateFirewallPolicy now require the current UpdateToken and reject a stale one with InvalidTokenException, as the API reference documents. The replacement is built from the stored resource, so Capacity and Tags, which neither update request models, and any field the request leaves out carry over instead of being dropped. A rule group's Type can't change after creation, UpdateFirewallPolicy requires FirewallPolicy, and UpdateRuleGroup requires exactly one of RuleGroup or Rules, so a request without a definition no longer wipes the stored one. Rule group and firewall policy create, update and delete now share the service lock, so a delete can't be undone by an overlapping update and two updates holding the same token can't both apply.
ebc3369 to
402e6aa
Compare
pgermosen
left a comment
There was a problem hiding this comment.
@danielvanza thanks, this closes everything from last time. The rule group and policy methods now share the service lock, so a delete can't be undone by an update landing around it, and the update now requires a matching UpdateToken, keeps the type tied to the ARN, and refuses a request without the rule group or policy body, all as the model describes. Looks good to me.
…oci-io#4114) * fix(networkfirewall): validate replacement before replacing state * fix(networkfirewall): require UpdateToken and keep unchanged fields on update UpdateRuleGroup and UpdateFirewallPolicy now require the current UpdateToken and reject a stale one with InvalidTokenException, as the API reference documents. The replacement is built from the stored resource, so Capacity and Tags, which neither update request models, and any field the request leaves out carry over instead of being dropped. A rule group's Type can't change after creation, UpdateFirewallPolicy requires FirewallPolicy, and UpdateRuleGroup requires exactly one of RuleGroup or Rules, so a request without a definition no longer wipes the stored one. Rule group and firewall policy create, update and delete now share the service lock, so a delete can't be undone by an overlapping update and two updates holding the same token can't both apply. --------- Co-authored-by: Priamo <pgermosen@gmail.com> Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
…oci-io#4114) * fix(networkfirewall): validate replacement before replacing state * fix(networkfirewall): require UpdateToken and keep unchanged fields on update UpdateRuleGroup and UpdateFirewallPolicy now require the current UpdateToken and reject a stale one with InvalidTokenException, as the API reference documents. The replacement is built from the stored resource, so Capacity and Tags, which neither update request models, and any field the request leaves out carry over instead of being dropped. A rule group's Type can't change after creation, UpdateFirewallPolicy requires FirewallPolicy, and UpdateRuleGroup requires exactly one of RuleGroup or Rules, so a request without a definition no longer wipes the stored one. Rule group and firewall policy create, update and delete now share the service lock, so a delete can't be undone by an overlapping update and two updates holding the same token can't both apply. --------- Co-authored-by: Priamo <pgermosen@gmail.com> Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
Summary
Audit finding F-027.
UpdateRuleGroupandUpdateFirewallPolicydeleted the existing resource and then rebuilt it, so arejected update (a name collision, or a missing or invalid field) left the resource gone. This
builds and validates the replacement first and only then swaps it into the store, so a rejected
update leaves the old resource intact.
The update path also now accepts the shape the Terraform provider sends: the resource is identified
by ARN alone, with no name (and no
Typefor a rule group). When the request omits the name or thetype, the value is taken from the stored resource. The ARN-versus-name mismatch check runs only when
a name was actually sent.
Typeis still validated against the modelled values whenever it ispresent.
Type of change
fix:)feat:)feat!:orfix!:)AWS Compatibility
Before: a rejected
UpdateRuleGroup/UpdateFirewallPolicyreturned an error but deleted thetarget, and an ARN-only update (as Terraform sends) failed with
InvalidRequestExceptionbecausethe name (and rule group
Type) was required up front. After: a rejected update keeps the originalresource and its ARN, and an update identified by ARN alone replaces the stored definition,
carrying the stored name and type.
Test evidence
./mvnw test -Dtest='NetworkFirewallIntegrationTest,NetworkFirewallConcurrencyTest': 52 run, 0 failures.Type, replaces the definition and keeps the stored name, type, and ARN.Checklist
./mvnw testpasses locally