-
Notifications
You must be signed in to change notification settings - Fork 795
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
2817 replace agent singleton #3068
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, if tested. GJ!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this been tested with multiple agents running on the same machine? We should probably also run ETE tests.
54c2947
to
df282b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I test:
2023-03-07 20:34:01,680 [12620:MainThread:INFO] main.main.46: writing log file to /home/ubuntu/tmp/infection-monkey-agent-2023-03-07-20-34-01-92ie8i_d.log
2023-03-07 20:34:01,680 [12620:MainThread:INFO] main._run_agent.137: >>>>>>>>>> Initializing the Infection Monkey Agent: PID 12620 <<<<<<<<<<
2023-03-07 20:34:01,680 [12620:MainThread:INFO] main._run_agent.141: version: 2.0.0+dev
2023-03-07 20:34:01,680 [12620:MainThread:INFO] monkey.__init__.102: Agent is initializing...
2023-03-07 20:34:01,680 [12620:MainThread:INFO] monkey.__init__.106: Agent ID: 7a3ee3ba-427d-4f91-aec0-c05913f08190
2023-03-07 20:34:01,680 [12620:MainThread:INFO] monkey.__init__.107: Process ID: 12620
/home/ubuntu/venvs/monkey/src/paramiko/paramiko/transport.py:236: CryptographyDeprecationWarning: Blowfish has been deprecated
"class": algorithms.Blowfish,
2023-03-07 20:34:02,195 [12620:MainThread:INFO] monkey._log_arguments.214: Agent started with arguments: parent: None, servers: [SocketAddress(ip=IPv4Address('10.27.225.28'), port=5000)], depth: 0
2023-03-07 20:34:02,195 [12620:MainThread:DEBUG] monkey._connect_to_island_api.168: Trying to wake up with servers: 10.27.225.28:5000
2023-03-07 20:34:02,196 [12620:FindIslandServer-01:DEBUG] utils._check_if_island_server.62: Trying to connect to server: 10.27.225.28:5000
2023-03-07 20:34:02,253 [12620:FindIslandServer-01:DEBUG] utils._check_if_island_server.68: Successfully connected to the Island via 10.27.225.28:5000
2023-03-07 20:34:02,253 [12620:MainThread:INFO] monkey._connect_to_island_api.176: Using 10.27.225.28:5000 to communicate with the Island
2023-03-07 20:34:02,256 [12620:MainThread:DEBUG] http_client._send_request.132: POST https://10.27.225.28:5000/api/agents, timeout=2.5
2023-03-07 20:34:02,303 [12620:MainThread:INFO] heart.start.21: Starting the Agent's heart
2023-03-07 20:34:02,303 [12620:MainThread:DEBUG] code_utils.start.134: Starting AgentHeart
2023-03-07 20:34:02,303 [12620:AgentHeart:DEBUG] code_utils.run.144: Successfully started AgentHeart
2023-03-07 20:34:02,303 [12620:AgentHeart:DEBUG] http_client._send_request.132: POST https://10.27.225.28:5000/api/agent/7a3ee3ba-427d-4f91-aec0-c05913f08190/heartbeat, timeout=5
2023-03-07 20:34:02,305 [12620:MainThread:INFO] main._run_agent.152: Starting InfectionMonkey
2023-03-07 20:34:02,305 [12620:MainThread:DEBUG] http_client._send_request.132: GET https://10.27.225.28:5000/api/agent-signals/7a3ee3ba-427d-4f91-aec0-c05913f08190, timeout=2.5
2023-03-07 20:34:02,349 [12620:MainThread:INFO] monkey.start.219: The Monkey Island has instructed this agent to stop
2023-03-07 20:34:02,349 [12620:MainThread:INFO] monkey.cleanup.431: Agent cleanup started
2023-03-07 20:34:02,349 [12620:MainThread:INFO] monkey._self_delete.510: Cleaning up the Agent's artifacts
2023-03-07 20:34:02,349 [12620:MainThread:INFO] monkey._send_log.488: Sending agent logs to the Island
2023-03-07 20:34:02,350 [12620:MainThread:DEBUG] http_client._send_request.132: PUT https://10.27.225.28:5000/api/agent-logs/7a3ee3ba-427d-4f91-aec0-c05913f08190, timeout=5
2023-03-07 20:34:02,352 [12620:MainThread:DEBUG] pypubsub_agent_event_queue._publish_event.55: Publishing a AgentShutdownEvent event to all_events_topic
2023-03-07 20:34:02,352 [12620:MainThread:DEBUG] pypubsub_agent_event_queue._publish_event.55: Publishing a AgentShutdownEvent event to AgentShutdownEvent-type
2023-03-07 20:34:02,352 [12620:MainThread:ERROR] monkey.cleanup.458: An error occurred while cleaning up the monkey agent: 'NoneType' object has no attribute 'flush'
Traceback (most recent call last):
File "/home/ubuntu/git/monkey/monkey/infection_monkey/monkey.py", line 451, in cleanup
self._agent_event_forwarder.flush()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'flush'
2023-03-07 20:34:02,353 [12620:MainThread:INFO] plugin_event_forwarder.stop.66: Stopping plugin event forwarder
2023-03-07 20:34:02,353 [12620:MainThread:ERROR] main._run_agent.160: Exception thrown from monkey's cleanup function: More info: cannot join thread before it is started
Traceback (most recent call last):
File "/home/ubuntu/git/monkey/monkey/infection_monkey/main.py", line 158, in _run_agent
monkey.cleanup()
File "/home/ubuntu/git/monkey/monkey/infection_monkey/monkey.py", line 462, in cleanup
self._plugin_event_forwarder.stop()
File "/home/ubuntu/git/monkey/monkey/infection_monkey/plugin_event_forwarder.py", line 68, in stop
self._thread.join(timeout)
File "/usr/lib/python3.11/threading.py", line 1107, in join
raise RuntimeError("cannot join thread before it is started")
RuntimeError: cannot join thread before it is started
2023-03-07 20:34:02,456 [12620:MainThread:DEBUG] main.main.53: Stopping the queue listener
7a856d6
to
fe6b06a
Compare
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## develop #3068 +/- ##
===========================================
+ Coverage 67.14% 67.50% +0.35%
===========================================
Files 442 441 -1
Lines 12751 12685 -66
===========================================
+ Hits 8562 8563 +1
+ Misses 4189 4122 -67
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
The island now determines when duplicate agents are running, and sets the terminate signal when an agent should close. The agent checks whether or not it should stop on startup, as well as periodically.
44fad63
to
ee630bb
Compare
bc8f0f2
to
889fc66
Compare
What does this PR do?
Fixes #2817.
PR Checklist
Testing Checklist
Added relevant unit tests?
Have you successfully tested your changes locally? Elaborate:
If applicable, add screenshots or log transcripts of the feature working
Output of
for i in {1..3}; do python ./infection_monkey.py m0nk3y -s 172.17.0.1:5000 > monkey-${i}.log 2>&1 & done
: