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

Add Check for Application Exclusions for Conditional Access Policies #1537

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

dagarwal-mitre
Copy link
Collaborator

@dagarwal-mitre dagarwal-mitre commented Jan 28, 2025

🗣 Description

This PR adds the ability to ensure that conditional access policies do not contain guest user exclusions, and ensures that every policy checking conditional access uses the PolicyConditionsMatch for consistency.

💭 Motivation and context

Closes #1170
Closes #1323

🧪 Testing

To test, within the conditional access policies, inside of users, inside the ExternalGuestorExternalUsers, update the MembershipKind and the GuestOrExternalUserTypes, and update it to look like the image. The default for these is null, feel free to take a look at the AADBaseConfig.rego file to see the default around line 25. Test with the different tenants.

Screenshot 2025-01-28 at 11 21 22 AM

✅ Pre-approval checklist

  • This PR has an informative and human-readable title.
  • PR targets the correct parent branch (e.g., main or release-name) for merge.
  • Changes are limited to a single goal - eschew scope creep!
  • Changes are sized such that they do not touch excessive number of files.
  • All future TODOs are captured in issues, which are referenced in code comments.
  • These code changes follow the ScubaGear content style guide.
  • Related issues these changes resolve are linked preferably via closing keywords.
  • All relevant type-of-change labels added.
  • All relevant project fields are set.
  • All relevant repo and/or project documentation updated to reflect these changes.
  • Unit tests added/updated to cover PowerShell and Rego changes.
  • Functional tests added/updated to cover PowerShell and Rego changes.
  • All relevant functional tests passed.
  • All automated checks (e.g., linting, static analysis, unit/smoke tests) passed.

✅ Pre-merge checklist

  • PR passed smoke test check.

  • Feature branch has been rebased against changes from parent branch, as needed

    Use Rebase branch button below or use this reference to rebase from the command line.

  • Resolved all merge conflicts on branch

  • Notified merge coordinator that PR is ready for merge via comment mention

  • Demonstrate changes to the team for questions and comments.
    (Note: Only required for issues of size Medium or larger)

✅ Post-merge checklist

  • Feature branch deleted after merge to clean up repository.
  • Verified that all checks pass on parent branch (e.g., main or release-name) after merge.

Copy link
Collaborator

@twneale twneale left a comment

Choose a reason for hiding this comment

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

Looks good 🐄

Copy link
Collaborator

@tkol2022 tkol2022 left a comment

Choose a reason for hiding this comment

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

Looks like some unit tests are missing for specific non-compliant states that PolicyConditionsMatch is checking for.

Missing unit tests for ExcludeRoles for 1.1, 3.1, 3.7, 3.8
Missing unit tests for ExcludeApplications for 1.1, 2.1, 2.3, 3.2, 3.6, 3.7, 3.8

@tkol2022
Copy link
Collaborator

@dagarwal-mitre I see 6 instances of the comment below in AADConfig.Rego and it doesn't make sense to me in any of the contexts where it is placed. I'm wondering if we should remove it? Kindly take a look

# Filter: only include policies that meet all the requirements

… 3.6 which does not require the inclusion of all users
@tkol2022
Copy link
Collaborator

The unit tests for policy 3.6 use an invalid JSON from AADBaseConfig.rego. In that JSON there is an IncludeUsers = All and then the unit tests add an IncludeRoles element as well. In a real tenant this can never happen because when you select the option to include roles you cannot then select the option to include all users as well. I think we should correct this to ensure that the policy and unit tests are aligned with practical scenarios. Given how finicky Rego is, we want to align the states we are testing with as closely to the real world as possible.

@tkol2022
Copy link
Collaborator

Some instances of calling PolicyConditionsMatch look like below whereas other cases the == true is omitted. Change them so they are all consistent to whatever you think is easier to maintain.

PolicyConditionsMatch(CAPolicy, true) == true

@tkol2022
Copy link
Collaborator

I think you should delete the line count(PrivRolesSet & ConvertToSet(CAPolicy.Conditions.Users.ExcludeRoles)) == 0 in AADConfig.rego for policy 3.6 because PolicyConditionsMatch verifies that the ExcludeRoles is empty so I think that line becomes OBE? I commented it out for now with my changes but take a look and see if you agree.

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
3 participants