monkey365 icon indicating copy to clipboard operation
monkey365 copied to clipboard

[Bug]: errors running in custom docker container

Open LennertVanRiel opened this issue 6 months ago • 11 comments

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

LennertVanRiel avatar Jun 17 '25 09:06 LennertVanRiel

Hi @LennertVanRiel thank you so much for catching this and thanks for the detailed report, it's really appreciated. I can confirm that it's a bug. Some directories contains some capital letters, and this is causing all the cascade errors in linux-like environments.

On the other hand, I have updated the develop branch. Could you please test your python code with the develop branch and do let me know if it works with you?

Please, note that to test the develop version you should change your dockerfile to something like that:

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 && \
    git clone --branch develop https://github.com/silverhack/monkey365.git /root/.local/share/powershell/Modules/monkey365
CMD ["python", "dashboard/app.py"]

And then remove or comment the following section in your Python code:

process = subprocess.Popen(
        ['pwsh', '-Command', "Install-Module -Name monkey365 -Scope CurrentUser -Force -AllowClobber"],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        text=True
    )

Thanks!

silverhack avatar Jun 17 '25 18:06 silverhack

Hi @silverhack ,

The dev branch seems to work flawlessly.

Thanks a lot!

LennertVanRiel avatar Jun 18 '25 07:06 LennertVanRiel

Thank you for replying so promptly. I'll perform some additional updates and will generate a new release asap.

Cheers

silverhack avatar Jun 18 '25 08:06 silverhack

@silverhack small update, while testing the m365 tests all seems to work. When testing the azure module i get the following error/warning message: /root/.local/share/powershell/Modules/monkey365/core/api/m365/SharePointOnline/utils/enum.ps1 not found

Invoked this way: Invoke-Monkey365 -IncludeEntraID -Instance Azure -OutDir './scans/monkey365' -ExportTo @('CSV','JSON','HTML') -DeviceCode -Collect All -AllSubscriptions -TenantID xxx

it does run and doesn't seem to fail but shows the message when launching (after devicecode auth)

LennertVanRiel avatar Jun 18 '25 11:06 LennertVanRiel

I've just updated the develop branch, could you please also test with Azure? I believe that all is sorted now.

Thanks

silverhack avatar Jun 18 '25 18:06 silverhack

The azure scan seems to work perfectly now, i'm having some issues with the o365 scan being stuck but it might be an issue on my end, I will test some more later and let you know if it remains an issue.

LennertVanRiel avatar Jun 24 '25 19:06 LennertVanRiel

Hey @LennertVanRiel could you please elaborate? My plan is to release a new version by the end of this week. Glad to help and to fix any potential issues before releasing a new version.

Thanks!

silverhack avatar Jun 25 '25 07:06 silverhack

@silverhack I'm testing again today, I will let you know the result as soon as I have it

LennertVanRiel avatar Jun 25 '25 09:06 LennertVanRiel

After testing again it all seems to work without any issues, thank you! It seems i just needed to have a little more patience.

LennertVanRiel avatar Jun 25 '25 10:06 LennertVanRiel

Thank you @LennertVanRiel for replying so promptly! it's really appreciated

silverhack avatar Jun 25 '25 11:06 silverhack

@silverhack no worries, thank you for the quick fixes!

LennertVanRiel avatar Jun 25 '25 11:06 LennertVanRiel

This issue has been automatically marked as stale because it has not had recent activity. We kindly ask you to check again if the issue you reported is still relevant in the current version of Monkey365. If it is, update this issue with a comment, otherwise it will be automatically closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Oct 24 '25 02:10 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale. If the issue is still relevant, feel free to re-open it or open a new one.

github-actions[bot] avatar Nov 07 '25 02:11 github-actions[bot]