Skip to content
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

feat(new): Added Azure.EventHub.Firewall #2872

Conversation

BenjaminEngeset
Copy link
Contributor

PR Summary

Fixes #2701

Added Azure.EventHub.Firewall.

PR Checklist

  • PR has a meaningful title
  • Summarized changes
  • Change is not breaking
  • This PR is ready to merge and is not Work in Progress
  • Rule changes
    • Unit tests created/ updated
    • Rule documentation created/ updated
    • Link to a filed issue
    • Change log has been updated with change under unreleased section
  • Other code changes
    • Unit tests created/ updated
    • Link to a filed issue
    • Change log has been updated with change under unreleased section

@BenjaminEngeset BenjaminEngeset requested a review from a team as a code owner May 19, 2024 17:18
@BenjaminEngeset
Copy link
Contributor Author

BenjaminEngeset commented May 19, 2024

Hi @BernieWhite. I want some feedback from you on this one, what do you think? The AnyOf method used can give customers some output that can be confusing, but after reading the rule documentation I suppose it will make sense?

I can also go for another design with an if else statement using $PSRule.TargetType, but will end up with some "duplicated" code by doing so for each block.

@BernieWhite
Copy link
Collaborator

BernieWhite commented May 20, 2024

@BenjaminEngeset Nice work so far. This one does have one additional complexity that you may not have encountered with previous rules, that I hadn't thought about in the initial issue.

There is an order of precedence on which will take effect for the final resource.

ARM take the approach of deploy the parent resource first Microsoft.EventHub/namespaces then the sub-resource Microsoft.EventHub/namespaces/networkRuleSets.

The impact of this is: If the sub-resource is set it will override the configuration on the parent resource, because it is deployed last and modifies the state of the parent.

Use Azure.SQL.AAD rule as a guide for the implementation: https://github.com/benjaminengeset/psrule.rules.azure/blob/daf85d5b183913461c6ef4d575e8fe93aae727a6/src/PSRule.Rules.Azure/rules/Azure.SQL.Rule.ps1#L58-L80

i.e.

  • If the resource type is Microsoft.EventHub/namespaces/networkRuleSets check properties.publicNetworkAccess or properties.defaultAction. Using AnyOf is fine.
  • If the resource type is Microsoft.EventHub/namespaces check for sub-resources an loop over any found performing a check properties.publicNetworkAccess or properties.defaultAction. Using AnyOf is fine.
  • Fall back to check of the parent resource properties properties.publicNetworkAccess. Using AnyOf is fine.

Copy link
Collaborator

@BernieWhite BernieWhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional suggestions for docs.

docs/en/rules/Azure.EventHub.Firewall.md Outdated Show resolved Hide resolved
docs/en/rules/Azure.EventHub.Firewall.md Outdated Show resolved Hide resolved
docs/en/rules/Azure.EventHub.Firewall.md Outdated Show resolved Hide resolved
@BenjaminEngeset
Copy link
Contributor Author

@BenjaminEngeset Nice work so far. This one does have one additional complexity that you may not have encountered with previous rules, that I hadn't thought about in the initial issue.

There is an order of precedence on which will take effect for the final resource.

ARM take the approach of deploy the parent resource first Microsoft.EventHub/namespaces then the sub-resource Microsoft.EventHub/namespaces/networkRuleSets.

The impact of this is: If the sub-resource is set it will override the configuration on the parent resource, because it is deployed last and modifies the state of the parent.

Use Azure.SQL.AAD rule as a guide for the implementation: https://github.com/benjaminengeset/psrule.rules.azure/blob/daf85d5b183913461c6ef4d575e8fe93aae727a6/src/PSRule.Rules.Azure/rules/Azure.SQL.Rule.ps1#L58-L80

i.e.

  • If the resource type is Microsoft.EventHub/namespaces/networkRuleSets check properties.publicNetworkAccess or properties.defaultAction. Using AnyOf is fine.
  • If the resource type is Microsoft.EventHub/namespaces check for sub-resources an loop over any found performing a check properties.publicNetworkAccess or properties.defaultAction. Using AnyOf is fine.
  • Fall back to check of the parent resource properties properties.publicNetworkAccess. Using AnyOf is fine.

Makes sense. I was aware of this, but didn't expect us to take that into consideration, but now that we are aligned I'll adjust accordingly. Great feedback. The $Assert.AnyOf() method doesn't work so well for me.

image image

Writing it with AnyOf{} instead works. What is this, a global function?

image

Found it here:

@BernieWhite
Copy link
Collaborator

@BenjaminEngeset Nice work so far. This one does have one additional complexity that you may not have encountered with previous rules, that I hadn't thought about in the initial issue.
There is an order of precedence on which will take effect for the final resource.
ARM take the approach of deploy the parent resource first Microsoft.EventHub/namespaces then the sub-resource Microsoft.EventHub/namespaces/networkRuleSets.
The impact of this is: If the sub-resource is set it will override the configuration on the parent resource, because it is deployed last and modifies the state of the parent.
Use Azure.SQL.AAD rule as a guide for the implementation: https://github.com/benjaminengeset/psrule.rules.azure/blob/daf85d5b183913461c6ef4d575e8fe93aae727a6/src/PSRule.Rules.Azure/rules/Azure.SQL.Rule.ps1#L58-L80
i.e.

  • If the resource type is Microsoft.EventHub/namespaces/networkRuleSets check properties.publicNetworkAccess or properties.defaultAction. Using AnyOf is fine.
  • If the resource type is Microsoft.EventHub/namespaces check for sub-resources an loop over any found performing a check properties.publicNetworkAccess or properties.defaultAction. Using AnyOf is fine.
  • Fall back to check of the parent resource properties properties.publicNetworkAccess. Using AnyOf is fine.

Makes sense. I was aware of this, but didn't expect us to take that into consideration, but now that we are aligned I'll adjust accordingly. Great feedback. The $Assert.AnyOf() method doesn't work so well for me.

image image
Writing it with AnyOf{} instead works. What is this, a global function?

image Found it here:

$Assert.AnyOf would require , between because it is an array of results. See: https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Assert/#aggregating-assertion-methods

Or use the { } if that works better for you. Either is fine.

@BenjaminEngeset
Copy link
Contributor Author

Should be ready for another review @BernieWhite. I don't undestand why $ruleresult[2].Reason and up to $ruleresult[4].Reason is empty. Any idea why the property has no value on these objects?

@BernieWhite
Copy link
Collaborator

Should be ready for another review @BernieWhite. I don't undestand why $ruleresult[2].Reason and up to $ruleresult[4].Reason is empty. Any idea why the property has no value on these objects?

I did a bit of investigating and this seems to be a bug with $Assert.AnyOf, it is currently dropping any aggregated reasons. Using AnyOf produces the correct result.

Copy link
Collaborator

@BernieWhite BernieWhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @BenjaminEngeset. All good to merge.

@BernieWhite BernieWhite merged commit 9cb4be7 into Azure:main May 22, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RULE] Event Hub Firewall
2 participants