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

Added a minimal rogue client detection mechanism at the transport level #2850

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mrsuciu
Copy link
Contributor

@mrsuciu mrsuciu commented Nov 18, 2024

Proposed changes

Clients that behave rogue by repeatedly sending invalid messages in a certain interval of time are now tracked and blocked from connecting for a predefined amount of time.
Time calculations are independent of system time.

Related Issues

  • Fixes #

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply. You can also fill these out after creating the PR.

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

Attention: Patch coverage is 15.30612% with 83 lines in your changes missing coverage. Please review.

Project coverage is 55.25%. Comparing base (3672ebe) to head (ae96ded).
Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
...tack/Opc.Ua.Core/Stack/Tcp/TcpTransportListener.cs 11.70% 77 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2850      +/-   ##
==========================================
- Coverage   57.23%   55.25%   -1.98%     
==========================================
  Files         352      352              
  Lines       75520    67433    -8087     
  Branches    15988    13820    -2168     
==========================================
- Hits        43223    37262    -5961     
+ Misses      27870    26085    -1785     
+ Partials     4427     4086     -341     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

/// <param name="remoteEndpoint"></param>
internal void MarkAsPotentialRogue(IPAddress remoteEndpoint)
{
Utils.LogError("MarkClientAsPotentialRogue address: {0} ", remoteEndpoint.ToString());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be LogDebug

// Even if TryRemove fails it will most probably succeed at the next execution
if (m_rogueClients.TryRemove(clientIp, out _))
{
Utils.LogInfo("Rogue Client with IP {0} is not tracked any longer, hasn't had rogue actions for more than {1} ms",
Copy link
Contributor

Choose a reason for hiding this comment

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

LogDebug would be better as well here I think

@romanett
Copy link
Contributor

@mrsuciu tests fail on some pipelines:
The active test run was aborted. Reason: Test host process crashed : Unhandled exception.Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Opc.Ua.Bindings.TcpTransportListener.OnAccept(Object sender, SocketAsyncEventArgs e) in /_/Stack/Opc.Ua.Core/Stack/Tcp/TcpTransportListener.cs:line 761
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

@mrsuciu
Copy link
Contributor Author

mrsuciu commented Nov 19, 2024

@mrsuciu tests fail on some pipelines: The active test run was aborted. Reason: Test host process crashed : Unhandled exception.Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. at Opc.Ua.Bindings.TcpTransportListener.OnAccept(Object sender, SocketAsyncEventArgs e) in /_/Stack/Opc.Ua.Core/Stack/Tcp/TcpTransportListener.cs:line 761 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

@romanett This did not happen on my local runs, but somehow the test machines running the tests do not provide IP Addresses.

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