cisagov / ScubaGear

Automation to assess the state of your M365 tenant against CISA's baselines
https://www.cisa.gov/resources-tools/services/secure-cloud-business-applications-scuba-project
Creative Commons Zero v1.0 Universal
1.44k stars 203 forks source link

Error when executing from alternate drive #1180

Closed secureality closed 1 day ago

secureality commented 1 week ago

Error with Rego when running any non-default drive letter (ie, C:). Looks like a calling the OPA executable, it cannot open the .rego file as it is looking in "\Program Files\WindowsPowerShell...", this is only on the current drive.

Examples: When running from drive Z:


PS Z:\temp> Invoke-SCuBA -ProductNames *
WARNING: Defender for Office 365 license not available in tenant. Omitting the following commands: Get-AtpPolicyForO365, Get-ATPProtectionPolicyRule.
WARNING: Defender for DLP license not available in tenant. Omitting the following commands: Get-DlpCompliancePolicy, Get-DlpComplianceRule, and Get-ProtectionAlert.
Invoke-RunRego : Error with the AAD Rego invocation. See the exception message for more details:  Error calling the OPA executable: Invalid JSON primitive: rrors occurred:
**CreateFile \Program Files\WindowsPowerShell\Modules\ScubaGear\1.3.0\Rego\AADConfig.rego:** The system cannot find the path specified.
**CreateFile \Program Files\WindowsPowerShell\Modules\ScubaGear\1.3.0\Rego\Utils:** The system cannot find the path specified.
.
At C:\Program Files\WindowsPowerShell\Modules\ScubaGear\1.3.0\Modules\Orchestrator.psm1:378 char:31
+             $ProdRegoFailed = Invoke-RunRego @RegoParams
+                               ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-RunRego

WARNING: aad will be omitted from the output because of the failure above
Invoke-RunRego : Error with the Defender Rego invocation. See the exception message for more details:  Error calling the OPA executable: Invalid JSON primitive: rrors occurred:
**_CreateFile \Program Files\WindowsPowerShell\Modules\ScubaGear\1.3.0\Rego\DefenderConfig.rego: The system cannot find the path specified.
CreateFile \Program Files\WindowsPowerShell\Modules\ScubaGear\1.3.0\Rego\Utils: The system cannot find the path specified._**
.
At C:\Program Files\WindowsPowerShell\Modules\ScubaGear\1.3.0\Modules\Orchestrator.psm1:378 char:31
+             $ProdRegoFailed = Invoke-RunRego @RegoParams
+                               ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-RunRego

WARNING: defender will be omitted from the output because of the failure above
[Repeats for every product].

When run from C:
PS C:\users\john\Documents> Invoke-SCuBA -ProductNames *
WARNING: Defender for Office 365 license not available in tenant. Omitting the following commands: Get-AtpPolicyForO365, Get-ATPProtectionPolicyRule.
WARNING: Defender for DLP license not available in tenant. Omitting the following commands: Get-DlpCompliancePolicy, Get-DlpComplianceRule, and Get-ProtectionAlert.

PS C:\users\john\Documents> 
buidav commented 1 week ago

When installing ScubaGear, the required OPA executable dependency is installed by default in a .scubaGear\Tools folder under the current user's$env:USERPROFILE which by default usually resolves to the C:\Users\UserName folder .

ScubaGear by default will attempt to check this directory for this OPA executable via relative path resolution. Since you're executing from a different drive ScubaGear will fail to find the executable and throw the error you're seeing.

If you need to always execute from your Z drive you can copy the executable C:\Users\UserName\.scubaGear\Tools or download an exe from the OPA website, then put it in the same directory where you're running Invoke-SCuBA in the Z drive.

The run.

Invoke-SCuBA -ProductNames * -OPAPath ./

This OPAPath parameter will point ScubaGear to the current directory to look for the OPA executable in. Hope this helps.

schrolla commented 1 day ago

Responded with possible solution. Closing for now, user may reopen if issue has not been resolved.