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

EXO 2.7 Rego Bug Fix | Only Enabled Correctly Configured Rules Pass #130

Merged
merged 5 commits into from
Feb 6, 2023

Conversation

rgbrow1949
Copy link
Collaborator

@rgbrow1949 rgbrow1949 commented Jan 23, 2023

πŸ—£ Description

  • Adds extra line in EXO 2.7 rego that filters the rules analyzed in the code by whether the rules are enabled.
  • Writes unit testing for EXO 2.7 to accommodate for the new logic.

πŸ’­ Motivation and context

  • Before this pull request, EXO 2.7 will pass if the rule is correctly configured but disabled, defeating the purpose of the baseline control. The solution is to add a line of rego code before checking the rule to see if it is correctly configured that filters the rules down to only the enabled rules.
  • This pull request closes issues 126 and 27.

πŸ§ͺ Testing

  • I tested my changes on a test tenant by creating two rules: a correctly configured rule and an incorrectly configured rule. After making the change in the rego code, I confirmed that when the correctly configured rule is enabled that the test passes. I also tested if they were both disabled, both enabled, and if the incorrect rule is enabled and the correct is disabled. Each case passed or failed appropriately.
  • I also ran the unit tests for Exchange Online and confirmed that all tests pass.
  • A reviewer should confirm that all unit tests pass and confirm that a correctly configured rule that is disabled fails the test and only a correctly configured rule that is enabled succeeds.

βœ… Pre-approval checklist

  • This PR has an informative and human-readable title.
  • Changes are limited to a single goal - eschew scope creep!
  • All future TODOs are captured in issues, which are referenced
    in code comments.
  • All relevant type-of-change labels have been added.
  • I have read the CONTRIBUTING document.
  • These code changes follow cisagov code standards.
  • All relevant repo and/or project documentation has been updated
    to reflect the changes in this PR.
  • Tests have been added and/or modified to cover the changes in this PR.
  • All new and existing tests pass.

βœ… Pre-merge checklist

  • Revert dependencies to default branches.
  • Finalize version.

βœ… Post-merge checklist

  • Add a tag or create a release.

Copy link
Collaborator

@adhilto adhilto left a comment

Choose a reason for hiding this comment

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

Looks great. I tested this by disabling the needed mail flow rule. On main 2.7, incorrectly passes but on this branch, it correctly displays a failure. After re-enabling it, it correctly showed a pass.

Copy link
Collaborator

@schrolla schrolla left a comment

Choose a reason for hiding this comment

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

I tested out the changes using our G5 test tenant. There I noticed that the updates did cover cases where one or more rules were present but disabled. Those worked correctly. However, the implementation notes and admin center showed each rule also has a Mode setting which can be set to one of the following: Enforce,Audit, or AuditAndNotify. The latter will flag such message, but not actually enforce the baseline policy item. As such, I recommend checking each rules mode and only considering those set to Enforce as properly meeting the intent of the rule since the baseline includes setting the mode to Enforce in the implementation guidance.

I've made code suggestions to both the provider and unit tests that should address this. I actually tested the provider change, but didn't validate the suggested unit test changes.

Let me know what you think about the proposed changes or reach out if you wish to discuss further.

Rego/EXOConfig.rego Outdated Show resolved Hide resolved
Testing/Unit/Rego/EXO/EXOConfig2_07_test.rego Outdated Show resolved Hide resolved
Testing/Unit/Rego/EXO/EXOConfig2_07_test.rego Outdated Show resolved Hide resolved
Testing/Unit/Rego/EXO/EXOConfig2_07_test.rego Outdated Show resolved Hide resolved
Testing/Unit/Rego/EXO/EXOConfig2_07_test.rego Outdated Show resolved Hide resolved
Testing/Unit/Rego/EXO/EXOConfig2_07_test.rego Outdated Show resolved Hide resolved
Testing/Unit/Rego/EXO/EXOConfig2_07_test.rego Outdated Show resolved Hide resolved
Testing/Unit/Rego/EXO/EXOConfig2_07_test.rego Outdated Show resolved Hide resolved
Testing/Unit/Rego/EXO/EXOConfig2_07_test.rego Outdated Show resolved Hide resolved
Testing/Unit/Rego/EXO/EXOConfig2_07_test.rego Outdated Show resolved Hide resolved
@rgbrow1949
Copy link
Collaborator Author

I have pushed changes to the Rego and the Unit Testing so now it requires rules to be both Enforced and Enabled. @schrolla How does it look now?

Copy link
Collaborator

@schrolla schrolla left a comment

Choose a reason for hiding this comment

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

The updates address the additional use cases identified before. Minor change requested to update error text for clarity. Update required in test and associated unit tests. I tried to note suggestions for each, but there may be additional unit tests to update. Fix and validate unit tests pass to ensure all have been updated as needed.

Rego/EXOConfig.rego Outdated Show resolved Hide resolved
Testing/Unit/Rego/EXO/EXOConfig2_07_test.rego Outdated Show resolved Hide resolved
Testing/Unit/Rego/EXO/EXOConfig2_07_test.rego Outdated Show resolved Hide resolved
Testing/Unit/Rego/EXO/EXOConfig2_07_test.rego Outdated Show resolved Hide resolved
@rgbrow1949
Copy link
Collaborator Author

Error messages have been updated.

Copy link
Collaborator

@schrolla schrolla left a comment

Choose a reason for hiding this comment

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

Re-ran tests and shows updated error message when set to fail. All unit tests also pass. Looks good for merge to me.

Copy link
Collaborator Author

@rgbrow1949 rgbrow1949 left a comment

Choose a reason for hiding this comment

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

Merge ready

@nanda-katikaneni nanda-katikaneni merged commit af31c45 into main Feb 6, 2023
@nanda-katikaneni nanda-katikaneni deleted the 126-Exo2-7DisabledRulesNowFail branch February 6, 2023 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue or pull request addresses broken functionality
Projects
None yet
5 participants