Skip to content

[Bug]: errors running in custom docker container #150

@LennertVanRiel

Description

@LennertVanRiel

What happened?
When attempting to run monkey365 in a docker container based on the latest python image, and with pwsh installed, multiple errors are shown. Attempted using both the Import-Module and Install-Module methods with the same result. The problem seems to consist of 2 issues, both causing errors.
The first issue seems related to inconsistency in upper/lowercase usage as renaming the folders to contain capital letters resolves this, this second issue I have not been able to resolve myself.

How to reproduce it
Dockerfile used:

FROM python
WORKDIR /app
COPY . /app
RUN apt-get update && \
    apt-get install -y wget apt-transport-https software-properties-common && \
    wget -q "https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb" && \
    dpkg -i packages-microsoft-prod.deb && \
    apt-get update && \
    apt-get install -y powershell && \
    rm -f packages-microsoft-prod.deb
CMD ["python", "dashboard/app.py"]

In the python script first using the install-module and then calling the script:

process = subprocess.Popen(
        ['pwsh', '-Command', "Install-Module -Name monkey365 -Scope CurrentUser -Force -AllowClobber"],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        text=True
    )
process = subprocess.Popen(
        ['pwsh', '-Command', "Invoke-Monkey365 -IncludeEntraID -Instance Microsoft365 -OutDir './scans/monkey365' -ExportTo @('CSV','JSON','CLIXML','HTML') -DeviceCode -Collect ExchangeOnline -Verbose
"],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        text=True
    )

Using the import-module method:
Added to the dockerfile:

RUN mkdir -p $HOME/.config/powershell/
RUN echo "Import-Module ./dashboard/monkey365 -InformationAction Continue" > $HOME/.config/powershell/Microsoft.PowerShell_profile.ps1

Python code:

process = subprocess.Popen(
        ['pwsh', '-Command', "Invoke-Monkey365 -IncludeEntraID -Instance Microsoft365 -OutDir './scans/monkey365' -ExportTo @('CSV','JSON','CLIXML','HTML') -DeviceCode -Collect ExchangeOnline -Verbose
"],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        text=True
    )

Both of these result in the following 2 errors:

WARNING: Directory /app/dashboard/monkey365/collectors/Azure was not found
WARNING: Directory /app/dashboard/monkey365/collectors/Microsoft365 was not found
WARNING: Directory /app/dashboard/monkey365/collectors/EntraID was not found

and

[31;1mImport-Module: �[31;1mThe specified module '/app/dashboard/monkey365/core/modules/monkeyOutput' was�[0m
�[31;1m�[31;1mnot loaded because no valid module file was found in any module directory.�[0m
�[33;1mWARNING: Directory /app/dashboard/monkey365/collectors/Azure was not found�[0m
�[33;1mWARNING: Directory /app/dashboard/monkey365/collectors/Microsoft365 was not found�[0m
�[31;1mNew-Object: �[0m/app/dashboard/monkey365/Invoke-Monkey365.ps1:328�[0m
�[31;1m�[0m�[36;1mLine |�[0m
�[31;1m�[0m�[36;1m�[36;1m 328 | �[0m … attr_name = �[36;1mNew-Object System.Management.Automation.ValidateSetAttrib�[0m …�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m     | �[31;1m               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m     | �[31;1mA constructor was not found. Cannot find an appropriate constructor for�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m�[31;1m�[36;1m     | �[31;1mtype System.Management.Automation.ValidateSetAttribute.�[0m
�[31;1mInvalidOperation: �[0m/app/dashboard/monkey365/Invoke-Monkey365.ps1:329�[0m
�[31;1m�[0m�[36;1mLine |�[0m
�[31;1m�[0m�[36;1m�[36;1m 329 | �[0m             $attributeCollection.Add(�[36;1m$token_attr_name�[0m)�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m     | �[31;1m                                      ~~~~~~~~~~~~~~~~�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m     | �[31;1mThe variable '$token_attr_name' cannot be retrieved because it has not�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m�[31;1m�[36;1m     | �[31;1mbeen set.�[0m
�[31;1mException: �[0m/app/dashboard/monkey365/core/init/New-O365Object.ps1:240�[0m
�[31;1m�[0m�[36;1mLine |�[0m
�[31;1m�[0m�[36;1m�[36;1m 240 | �[0m             �[36;1mthrow ("[ParameterError] {0}: {1}" -f "Unable to create M�[0m …�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m     | �[31;1m             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m     | �[31;1m[ParameterError] Unable to create Monkey365 object: You cannot call a�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m�[31;1m�[36;1m     | �[31;1mmethod on a null-valued expression.�[0m

Screenshots or Logs
when running Invoke-Monkey365 -IncludeEntraID -Instance Microsoft365 -OutDir './scans/monkey365' -ExportTo @('CSV','JSON','CLIXML','HTML') -DeviceCode -Collect ExchangeOnline -Verbose
using import-module:
Image
using install-module:
Image

From where are you running Monkey365?
Please, complete the following information:

  • Resource: Docker container (based on the latest python image)
  • OS: Debian GNU/Linux 12 (bookworm)
  • PowerShell Version
PSVersion 7.5.1
PSEdition Core
GitCommitId 7.5.1
OS Debian GNU/Linux 12 (bookworm)
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion  2.3
SerializationVersion  1.1.0.1
WSManStackVersion  3.0]:
  • Monkey365 Version: latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingimpact-mediumIssue with medium impact to codebaseseverity-mediumIssue with medium severity

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions