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

Poetry module not found by systemd services #2408

Closed
6 tasks done
ChrisThibodeaux opened this issue Nov 22, 2024 · 11 comments
Closed
6 tasks done

Poetry module not found by systemd services #2408

ChrisThibodeaux opened this issue Nov 22, 2024 · 11 comments

Comments

@ChrisThibodeaux
Copy link
Contributor

ChrisThibodeaux commented Nov 22, 2024

About accounts on capesandbox.com

  • Issues isn't the way to ask for account activation. Ping capesandbox in Twitter with your username

This is open source and you are getting free support so be friendly!

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest version
  • I did read the README!
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed
  • I'm reporting the issue to the correct repository (for multi-repository projects)
  • I have read and checked all configs (with all optional parts)

Expected Behavior

After full install, CAPE's systemd services should be active.

Current Behavior

Services all fail to activate.

Failure Information (for bugs)

Cape, cape-web, cape-rooter, and cape-processor services fail to activate. Errors indicate poetry not being found by python correctly.

Steps to Reproduce

  1. Edit and run installation scripts.
  2. Install dependencies with poetry install
  3. Restart cape, cape-web, etc. services.
  4. Check the systemctl status and/or journalctl -u <service> -f. Will display failure info.

Context

Installed on a bare metal server with Ubuntu 22.04.

Recent changes to the method of installing poetry in cape2.sh (curl -sSL https://install.python-poetry.org | POETRY_HOME=/etc/poetry python3 -) move where it is installed to /etc/poetry. No issue with installing that way or in that location because that is exactly how poetry's docs say it can be done.

I believe this new install location is not a location that python will check when attempting to load a module with python -m. The previous use of apt install python-poetry was likely installing at /usr/local/lib/python3.10/dist-packages or /usr/lib/python3/dist-packages. Directly running sudo -u cape poetry run python3 cuckoo.py from /opt/CAPEv2 works properly. Nearly positive this issue is isolated to the systemd service files.

PR with proposed fix here: #2407
I am not entirely sure about the ramifications of running the ExecStarts with /etc/poetry/bin/poetry run python ... instead of /usr/bin/python3 poetry run python ..., but the changes in this PR fix the problem for me.

Leaving it as a draft until anyone else can confirm that

  1. A fresh install fails for them in the same way
  2. Applying the Fix systemd services being unable to find the poetry module. #2407 changes fixes that

Failure Logs

From the journalctl for cape.service.

Nov 20 10:18:14 hairy-aviators systemd[1]: Started CAPE.
Nov 20 10:18:14 hairy-aviators python3[1272]: /usr/bin/python3: No module named poetry
Nov 20 10:18:14 hairy-aviators systemd[1]: cape.service: Main process exited, code=exited, status=1/FAILURE
Nov 20 10:18:14 hairy-aviators systemd[1]: cape.service: Failed with result 'exit-code'.
Nov 20 10:23:14 hairy-aviators systemd[1]: cape.service: Scheduled restart job, restart counter is at 1.
Nov 20 10:23:14 hairy-aviators systemd[1]: Stopped CAPE.

Note that poetry is available in the PATH variable.

root@hairy-aviators:/opt/CAPEv2# poetry
Poetry (version 1.8.4)
...
@poland4000
Copy link

poland4000 commented Nov 22, 2024

I'm getting the same exact issue and the suggested PR lets me progress further. Still stuck afterwards due to the cape2.sh installer failing to find poetry anyways despite the fixed issue 2400.

@ChrisThibodeaux
Copy link
Contributor Author

ChrisThibodeaux commented Nov 22, 2024

@poland4000 Can you share the portion of cape.log with the errors? My runs of sudo ./cape.sh base cape | tee cape.log don't seem to fail. This is the only part of the log I see anything about Poetry:

Retrieving Poetry metadata

# Welcome to Poetry!

This will download and install the latest version of Poetry,
a dependency and package manager for Python.

It will add the `poetry` command to Poetry's bin directory, located at:

/etc/poetry/bin

You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.

Installing Poetry (1.8.4)
Installing Poetry (1.8.4): Creating environment
Installing Poetry (1.8.4): Installing Poetry
Installing Poetry (1.8.4): Creating script
Installing Poetry (1.8.4): Done

Poetry (1.8.4) is installed now. Great!

To get started you need Poetry's bin directory (/etc/poetry/bin) in your `PATH`
environment variable.

Add `export PATH="/etc/poetry/bin:$PATH"` to your shell configuration file.

Alternatively, you can call Poetry explicitly with `/etc/poetry/bin/poetry`.

You can test that everything is set up by executing:

`poetry --version`

@poland4000
Copy link

I'd like to provide a log though I already 'fixed' it by including the poetry path into secure_path in visudo. Without this It would install just as in your logs, poetry installation would be successful however every step involving poetry e.g. "poetry --directory /opt/CAPEv2/ run pip install yara-x" would throw poetry command not found. I used "sudo ./cape2.sh all cape | tee cape.log" to install.

@ChrisThibodeaux
Copy link
Contributor Author

So, with the base install that I ran, I did not hit those errors. I have a feeling poetry --directory /opt/CAPEv2/ run ... fails, but sudo -u ${USER} poetry --directory /opt/CAPEv2 run ... definitely does not. There is no place where the direct poetry --directory ... style is used when base arg is used.

May simply be that the spots where the first command is used need to be updated to prepend sudo -u ${USER} to them.

@czechmate247
Copy link

So I got around this by modifying the ExecStart=/usr/bin/python3 -m poetry ... part of each cape.*.service file with ExecStart=/etc/poetry/bin/poetry. The problem is that the cape2.sh script doesn't install poetry as a module to the base system's pip repo so the systemd service files ultimately can't find it. I haven't investigated which part of the cape2.sh install script creates the service files but it seems like if my changes above were put into the service file templates, all will work as intended. I don't know if this will have any unintended side effects but it is working for me so far.

@doomedraven
Copy link
Collaborator

doomedraven commented Nov 22, 2024 via email

@doomedraven
Copy link
Collaborator

fixed here a8c6b37

@ChrisThibodeaux
Copy link
Contributor Author

ChrisThibodeaux commented Nov 24, 2024

@doomedraven From the fix commit in /systemd/cape-rooter.service:

ExecStartPre=/etc/poetry/bin/poetry -m poetry config cache-dir /opt/CAPEv2/.cache/pypoetry
ExecStart=/etc/poetry/bin/poetry -m poetry run python rooter.py -g cape

Should these two lines be this instead?

ExecStartPre=/etc/poetry/bin/poetry config cache-dir /opt/CAPEv2/.cache/pypoetry
ExecStart=/etc/poetry/bin/poetry run python rooter.py -g cape

@doomedraven
Copy link
Collaborator

ah yes good catch, thanks, fixing

@ChrisThibodeaux
Copy link
Contributor Author

@doomedraven As always, thank you for all your work! I'll close out this issue and the PR I put up.

There may remain the problem others are reporting here with the cape2.sh script failing to find Poetry. I don't think that necessarily should be solved in this ticket, though. When I have more time, I will take a look there as well.

@doomedraven
Copy link
Collaborator

thanks for the headups, the poetry now is instaled to /etc/poetry so shouldn't be a problem anymore, let me know if you find any other problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants