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 policy check for SharePoint 3.2 when using service principal and update SharePoint 4.2 rego for deprecation #1309

Merged
merged 15 commits into from
Oct 3, 2024

Conversation

mitchelbaker-cisa
Copy link
Collaborator

@mitchelbaker-cisa mitchelbaker-cisa commented Sep 6, 2024

🗣 Description

  • Removed input.OneDrive_PnP_Flag == false/true statements and Not-Implemented test in SharePointConfig.rego. The input.OneDrive_PnP_Flag is still used in the SharePoint unit tests to indicate spo/pnp variants

  • Removed unnecessary fields from sharepoint.spo.testplan.yaml to get rid of warnings; removed deprecated parameter ("Detailed"=$true) from Get-SPOSite and Get-PnPTenantSite in SharePoint provider

  • Expanded unit test coverage for SharePoint 3.2 to cover service principal cases in SharepointConfig_03_test.rego; expanded functional test coverage for SharePoint 3.2 in the sharepoint.pnp.testplan.yaml

  • Logic for SharePoint 3.1 fixed to account for negative integer value, -1, when the Anyone links checkbox is not set. The policy now displays a fail for this case

  • Set SharePoint 4.2 to not-implemented in SharepoingConfig.rego, updated its unit/functional tests

💭 Motivation and context

Closes #1221
Closes #1268
Closes #1220
Closes #1324
closes #622

🧪 Testing

Checkout the branch locally:

git fetch
git checkout 1221-sharepoint-3.2-incorrect-NA

Check if all unit tests pass:

.\Testing\RunUnitTests.ps1 -p sharepoint

Check if all functional tests pass against SharePoint, use both spo/pnp variants.

✅ 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

✅ 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.

@mitchelbaker-cisa mitchelbaker-cisa added the bug This issue or pull request addresses broken functionality label Sep 6, 2024
@mitchelbaker-cisa mitchelbaker-cisa added this to the Jellyfish milestone Sep 6, 2024
@mitchelbaker-cisa mitchelbaker-cisa self-assigned this Sep 6, 2024
@mitchelbaker-cisa mitchelbaker-cisa changed the title Add policy check for SharePoint 3.2 when using service principal Add policy check for SharePoint 3.2 when using service principal and remove deprecated Get-SPOSite parameter Sep 6, 2024
@mitchelbaker-cisa mitchelbaker-cisa added the enhancement This issue or pull request will add new or improve existing functionality label Sep 6, 2024
@mitchelbaker-cisa mitchelbaker-cisa marked this pull request as ready for review September 6, 2024 23:35
@tkol2022
Copy link
Collaborator

It is not clear why the test_File_Folder_AnonymousLinkType_Correct should produce a Pass? The SharingCapability is explicitly set to 2 (Anyone) within the unit test, but the other fields that are checked by the policy FileAnonymousLinkType & FolderAnonymousLinkType are not set in the unit test. Since they are already setup to the compliant value of 1 in the SharepointBaseConfig.rego file, the policy passes, but as a developer when I read the unit test this is not clear and I think this will make it hard to maintain these tests and know what they doing. I am wondering if we should explicitly set the values related to the policy and scenario we are testing within each unit test?

image

image

@tkol2022
Copy link
Collaborator

I don't see the difference between these two tests?
Also, what does the "UsingServicePrincipal" in the test name mean? I don't see anything in the test JSON that indicates that a service principal was used.

image

image

I don't see the difference between the two tests below either?

image

image

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.

Reviewed the code updates, unit tests and functional tests. Will leverage the support of another team member to perform hands-on testing.

I had a couple of minor questions related to the consistency and maintainability of the unit tests. Other than that, looks good. Nice work.

@mitchelbaker-cisa
Copy link
Collaborator Author

mitchelbaker-cisa commented Sep 13, 2024

Reviewed the code updates, unit tests and functional tests. Will leverage the support of another team member to perform hands-on testing.

I had a couple of minor questions related to the consistency and maintainability of the unit tests. Other than that, looks good. Nice work.

@tkol2022 Thanks for the review. I addressed your feedback in 7bc0975

@tkol2022
Copy link
Collaborator

@mitchelbaker-cisa Seems there is a logic flaw in the Rego implementation for policy 3.1 that I found when testing the branch. It is easy to fix so I recommend that you address it now especially given the importance of this release.

To recreate the problem

Set the external sharing slider to Anyone

image

Uncheck the expiration days option
image

Run ScubaGear and observe that it produces a Pass which is incorrect because the expiration option was not selected and configured
image

The fix

I believe the fix is relatively straightforward. When the expiration checkbox is unselected in the portal, you will notice that the JSON produces a value of -1 for RequireAnonymousLinksExpireInDays, so I am thinking that we need to ensure that the value of the field is between 1 and 30 inclusive. Currently the Rego code only checks for <= 30 and hence why it is flawed. Take a look and see if you agree.

image

image

@tkol2022
Copy link
Collaborator

N/A messages for section 3 are inconsistent with the baseline document

While testing I noticed that when policies 3.1, 3.2 or 3.3 produce an N/A, the messages provided in the report are inaccurate and/or do not align with the messages in the baseline document.

Policies 3.1 and 3.2

Should say "This policy is only applicable if the external sharing slider on the admin center sharing page is set to Anyone." but in the report they say "This policy is only applicable if External Sharing is set to any value other than Anyone."
image

Policy 3.3

Should say "This policy is only applicable if the external sharing slider on the admin center sharing page is set to Anyone or New and existing guests." but in the report it says "This policy is only applicable if External Sharing is set to any value other than Only People In Your Organization or Existing Guests." In this case, technically the message in the report is correct but it does not align with the baseline so we might as well synch them up for consistency.

image

@tkol2022
Copy link
Collaborator

I tested interactive and non-interactive against E5 tenant and policy 3.2 seems to behave as expected.

@mitchelbaker-cisa
Copy link
Collaborator Author

@tkol2022

I addressed the logic for policy 3.1 to account for the negative integer value, -1, when the Anyone links checkbox is not set. The policy now displays a fail for this case.

The report details for policies 3.1-3.3 are also fixed.

@mitchelbaker-cisa mitchelbaker-cisa changed the title Add policy check for SharePoint 3.2 when using service principal and remove deprecated Get-SPOSite parameter Add policy check for SharePoint 3.2 when using service principal and update SharePoint 4.2 rego for deprecation Sep 23, 2024
@tkol2022
Copy link
Collaborator

@tkol2022

I addressed the logic for policy 3.1 to account for the negative integer value, -1, when the Anyone links checkbox is not set. The policy now displays a fail for this case.

The report details for policies 3.1-3.3 are also fixed.

@Sloane4 Can you test the negative integer value logic and make sure it works for you? would be nice to have some independent validation.

@schrolla schrolla removed the request for review from james-garriss October 2, 2024 14:18
Copy link
Collaborator

@Sloane4 Sloane4 left a comment

Choose a reason for hiding this comment

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

Dont forget to rebase with main

@schrolla schrolla force-pushed the 1221-sharepoint-3.2-incorrect-NA branch from 8f181fb to b280935 Compare October 3, 2024 13:55
@schrolla schrolla force-pushed the 1221-sharepoint-3.2-incorrect-NA branch from b280935 to c21eee2 Compare October 3, 2024 17:02
@tkol2022
Copy link
Collaborator

tkol2022 commented Oct 3, 2024

Final Tests

I did a final functional test on all the Sharepoint policies that were affected by this PR 1.3, 3.1, 3.2, 3.3, 4.2
They all passed except for 3.2. After further investigation the failures were intermittent and are not related to the code changes, but instead are related to the problems we have been experiencing with the Set-PnPTenant and Set-SPOTenant not updating the tenant in some cases. The problem seems to be random and we have informed Microsoft of the issue.
I also double checked and the unit tests are passing fine.
Also @ehaines1 Performed a hands-on test of the update to policy 3.1 based on the bug that was discovered during this PR review and it works as expected.

@nanda-katikaneni Ready for merge

@nanda-katikaneni nanda-katikaneni merged commit cba64da into main Oct 3, 2024
26 checks passed
@nanda-katikaneni nanda-katikaneni deleted the 1221-sharepoint-3.2-incorrect-NA branch October 3, 2024 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment