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

2216 notify relay when finished #2257

Merged
merged 3 commits into from
Sep 8, 2022

Conversation

cakekoa
Copy link
Contributor

@cakekoa cakekoa commented Sep 7, 2022

What does this PR do?

Fixes part of #2216.

Sends the notification upstream to tell the agent's relay that it is disconnecting.

PR Checklist

  • Have you added an explanation of what your changes do and why you'd like to include them?
  • Is the TravisCI build passing?
  • Was the CHANGELOG.md updated to reflect the changes?
  • Was the documentation framework updated to reflect the changes?
  • Have you checked that you haven't introduced any duplicate code?

Testing Checklist

  • Added relevant unit tests?
  • Have you successfully tested your changes locally? Elaborate:

    Tested by {Running the Monkey locally with relevant config/running Island/...}

  • If applicable, add screenshots or log transcripts of the feature working

@cakekoa cakekoa changed the base branch from develop to tcp-relay September 7, 2022 20:11
@cakekoa cakekoa changed the base branch from tcp-relay to 2216-tcp-relay September 7, 2022 20:22

:param server_ip: The IP address of the server to notify.
:param server_port: The port of the server to notify.
:raises OSError: If the disconnect message failed to send.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other errors that could be raised? ATM, _close_tunnel() doesn't catch any exceptions. If notify_disconnect() raises an exception, than self._singleton.unlock() will never be called, which would prevent new agents from being spawned on the machine.

I think it's fine if this function catches all exceptions and logs them. Either that or _close_tunne() should catch and log. Either way is fine with me, as long as we're confident that self._singleton.unlock() will always get called.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: I pushed 8858bf9 to ensure that the "singleton" is always unlocked. We should still scrutinize this to make sure we're happy with how errors are being caught. If the cleanup routine changes in the future, uncaught errors here could cause issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I looked into this but the socket documentation is pretty vague. From what I can surmise, all socket errors derive from OSError. I opted to allow the function to raise errors to give the caller the option to decide what to do if the disconnect message fails to send. If we're happy not handling that and just logging it, I can switch to logging it here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's handle it in _close_tunnel(). Then the caller still decides and it's handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now updated after rebasing onto the latest 2216-tcp-relay

@cakekoa cakekoa force-pushed the 2216-notify-relay-when-finished branch from 8858bf9 to ab7ac76 Compare September 8, 2022 13:50
@mssalvatore mssalvatore merged commit 28b4a0b into 2216-tcp-relay Sep 8, 2022
@mssalvatore mssalvatore deleted the 2216-notify-relay-when-finished branch September 8, 2022 13:54
mssalvatore added a commit that referenced this pull request Sep 9, 2022
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

Successfully merging this pull request may close these issues.

2 participants