Skip to content

Commit

Permalink
Added a new Rego function to ensure trial environments can only be cr…
Browse files Browse the repository at this point in the history
…eated by admins (cisagov#110)
  • Loading branch information
tkol2022 authored Jan 11, 2023
1 parent 67a0485 commit d25963d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
19 changes: 18 additions & 1 deletion Rego/PowerPlatformConfig.rego
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ReportDetailsString(Status, String) = Detail if {
# Baseline 2.1: Policy 1
#--
tests[{
"Requirement" : "The ability to create additional environments SHALL be restricted to admins",
"Requirement" : "The ability to create production and sandbox environments SHALL be restricted to admins",
"Control" : "Power Platform 2.1",
"Criticality" : "Shall",
"Commandlet" : "Get-TenantSettings",
Expand All @@ -52,6 +52,23 @@ tests[{
}
#--

#
# Baseline 2.1: Policy 2
#--
tests[{
"Requirement" : "The ability to create trial environments SHALL be restricted to admins",
"Control" : "Power Platform 2.1",
"Criticality" : "Shall",
"Commandlet" : "Get-TenantSettings",
"ActualValue" : EnvironmentCreation.disableTrialEnvironmentCreationByNonAdminUsers,
"ReportDetails" : ReportDetailsBoolean(Status),
"RequirementMet" : Status
}] {
EnvironmentCreation := input.environment_creation
Status := EnvironmentCreation.disableTrialEnvironmentCreationByNonAdminUsers == true
}
#--


################
# Baseline 2.2 #
Expand Down
45 changes: 41 additions & 4 deletions Testing/Unit/Rego/PowerPlatform/PowerPlatformConfig2_01_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import future.keywords
#
# Policy 1
#--
test_disableEnvironmentCreationByNonAdminUsers_Correct if {
test_disableProductionEnvironmentCreationByNonAdminUsers_Correct if {
ControlNumber := "Power Platform 2.1"
Requirement := "The ability to create additional environments SHALL be restricted to admins"
Requirement := "The ability to create production and sandbox environments SHALL be restricted to admins"

Output := tests with input as {
"environment_creation": {
Expand All @@ -22,9 +22,9 @@ test_disableEnvironmentCreationByNonAdminUsers_Correct if {
RuleOutput[0].ReportDetails == "Requirement met"
}

test_disableEnvironmentCreationByNonAdminUsers_Incorrect if {
test_disableProductionEnvironmentCreationByNonAdminUsers_Incorrect if {
ControlNumber := "Power Platform 2.1"
Requirement := "The ability to create additional environments SHALL be restricted to admins"
Requirement := "The ability to create production and sandbox environments SHALL be restricted to admins"

Output := tests with input as {
"environment_creation": {
Expand All @@ -38,3 +38,40 @@ test_disableEnvironmentCreationByNonAdminUsers_Incorrect if {
not RuleOutput[0].RequirementMet
RuleOutput[0].ReportDetails == "Requirement not met"
}

#
# Policy 2
#--
test_disableTrialEnvironmentCreationByNonAdminUsers_Correct if {
ControlNumber := "Power Platform 2.1"
Requirement := "The ability to create trial environments SHALL be restricted to admins"

Output := tests with input as {
"environment_creation": {
"disableTrialEnvironmentCreationByNonAdminUsers" : true
}
}

RuleOutput := [Result | Result = Output[_]; Result.Control == ControlNumber; Result.Requirement == Requirement]

count(RuleOutput) == 1
RuleOutput[0].RequirementMet
RuleOutput[0].ReportDetails == "Requirement met"
}

test_disableTrialEnvironmentCreationByNonAdminUsers_Incorrect if {
ControlNumber := "Power Platform 2.1"
Requirement := "The ability to create trial environments SHALL be restricted to admins"

Output := tests with input as {
"environment_creation": {
"disableTrialEnvironmentCreationByNonAdminUsers" : false
}
}

RuleOutput := [Result | Result = Output[_]; Result.Control == ControlNumber; Result.Requirement == Requirement]

count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
RuleOutput[0].ReportDetails == "Requirement not met"
}

0 comments on commit d25963d

Please sign in to comment.