Skip to content

Support multiple security parameters for receiving SNMP V3 traps #457

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

Merged
merged 8 commits into from
Jan 15, 2024

Conversation

zoedt
Copy link
Contributor

@zoedt zoedt commented Dec 7, 2023

Greetings 😄 PR addressing issue #302

This PR adds multiple security parameter support for receiving SNMP V3 traps.

Notes:

  • For the USM model, the identifier for the security parameters to unmarshal with will be the username.
  • This is supporting that the configuration of multiple security parameters in the conf.yaml may have usernames with the same identifier, so multiple security parameters can be tried until one satisfies the authentication/privacy protocols

Example steps

  1. Run the listener in trapserver_v3
  2. Send a trap, examples below:
$ snmptrap -v3 -l authPriv -u myuser2 -a MD5 -A mypassword2 -x AES -X myprivacy2 127.0.0.1:9162 '' 1.3.6.1.4.1.8072.2.3.0.1 1.3.6.1.4.1.8072.2.3.2.1 i 123456

$ snmptrap -v3 -l authPriv -u myuser2 -a SHA -A mypassword2 -x DES -X myprivacy2 127.0.0.1:9162 '' 1.3.6.1.4.1.8072.2.3.0.1 1.3.6.1.4.1.8072.2.3.2.1 i 123456

zoedt added 4 commits December 7, 2023 15:24
…sernames

Signed-off-by: zoe ✨ <9274242+zoedt@users.noreply.github.com>
…ching

Signed-off-by: zoe ✨ <9274242+zoedt@users.noreply.github.com>
Signed-off-by: zoe ✨ <9274242+zoedt@users.noreply.github.com>
Signed-off-by: zoe ✨ <9274242+zoedt@users.noreply.github.com>
Signed-off-by: zoe ✨ <9274242+zoedt@users.noreply.github.com>
Copy link
Contributor

@Hipska Hipska left a comment

Choose a reason for hiding this comment

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

Oh, now I see why UnmarshalTrapBase was returning the result. So what if instead of passing result as second parameter, you pass the secParams?

What do you think of my suggestions? I also think UnmarshalTrapBase does not need to be exported, just like the one for headers also isn't.

@zoedt zoedt marked this pull request as ready for review December 12, 2023 21:13
@zoedt
Copy link
Contributor Author

zoedt commented Dec 12, 2023

cc @SuperQ @TimRots for any feedback as well

…ms, clearer names

Signed-off-by: zoe ✨ <9274242+zoedt@users.noreply.github.com>
Copy link
Member

@TimRots TimRots left a comment

Choose a reason for hiding this comment

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

Hi @zoedt , thank you for contributing this feature. Initial review looks great to me!
I dropped one implementation specific question for discussion and look forward to reviewing the rest of this feature soon.

}
}

func (spm *SnmpV3SecurityParametersTable) Add(key string, sp SnmpV3SecurityParameters) error {
Copy link
Member

Choose a reason for hiding this comment

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

Current implementation of this Add method allows for multiple UsmSecurityParameters to be associated with the same userName. This approach seems to offer some interesting flexibility. However, I'm keen to understand the specific scenarios or requirements that led to this design choice.

In light of the specifications outlined in RFC 3414, particularly the one-to-one relationship between userName and securityName, The RFC suggests that each userName should correspond to a unique set of security parameters. Were you aware of this?

If all reviewers eventually decide this behavior is OK we could perhaps log the specific occurrence where we append SP's to an existing userName, but lets not get ahead of things yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i did know about the specifications outlined in rfc 3414 - for my use case (for my team) we wanted to reduce the overhead of requiring those wanting to set up a listener of traps for multiple devices (and thus multiple securityNames/engine IDs) and reducing friction that way.

if we followed the unique set of security parameters per key of username/security name it would definitely not need the for loop to try each credential (as there would only be one possible one)

there could be the possibility of supporting that by changing the getIdentifier to return the username/securityName combo to follow the RFC guidelines, but maybe we can discuss further if we want to support both or have a strong opinion (for strictly following the RFC or the current path forward)

Copy link
Contributor Author

@zoedt zoedt Dec 14, 2023

Choose a reason for hiding this comment

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

also (a tangent), i was curious about the gosnmp struct's contextEngineId - what should expected to be populated here? i might have missed something but i don't see it used very often beyond when snmp packets are made / should the informs be using that to discover the engine ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

after talking w/ a coworker: maybe there can be some configuration based on however the user wants to set up:

  • if a security parameter is added with the authoritative engine ID then getIdentifier will return both username / security name
  • otherwise, it will defer to only adding the key as the username

for flexibility between both.

what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for slow replies. I'm sick and not really up for code(review) at this very moment but let's try:

My main point was that I'm a proponent to be verbose when appending multiple security parameters for the same userName, As that behavior is not specifically outlined in the RFC as best-practice nor requirement. Please log the occurrence.

What confuses me about the current implementation of the UsmSecurityParameters struct is that we seem to mix some Engine and User configs. This was never a problem but becomes confusing now that we allow multiple sec params to be defined by this code. Also the fact that we need to define 4 loggers in the example code convinces me that this implementation needs some care. If this would block your PR it would need to become a TODO item so that we can think and discuss this in a separate issue?

@SuperQ @Hipska what do you think about last mentioned item?

Copy link
Contributor

Choose a reason for hiding this comment

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

I have no further opinion on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I addressed some of the logging concerns with my latest commit, let me know your thoughts on that aspect of your feedback!

As for the mixing of engine / user configs - I just want to clarify: that would be around the engine ID, engine boots, engine time and username (as well as if they've configured authentication / privacy protocols)?

…params

Signed-off-by: zoe ✨ <9274242+zoedt@users.noreply.github.com>
@zoedt
Copy link
Contributor Author

zoedt commented Dec 18, 2023

Question:

I feel as though it’s confusing to only utilize the security parameters for storing the engine ID in the case of multiple listeners, should there be an explicit field utilized and should it be contextEngineID or a more explicit snmpEngineID (that can be added)?


More background + defining the terms I’m using because I’m not sure if I’m using them correctly:

SNMP manager

  • sends requests (polling) or receives traps from devices on the network via SNMP agents to get information about them

SNMP agent

  • runs on devices connected to the network the manager is on; receives the requests, returns information in response to manager

Engine ID

  • Currently: we use the singular SecurityParameters on the gosnmp struct to hold the engine ID of the host (SNMP manager) it’s running on
  • With the introduction of multiple security parameters for traps, that blurs the understanding of what should be utilized to be the definitive engine ID that should represent the “device” or unique identifier for the manager/listener
    • The engine ID could be added to each SecurityParameter in the table/map and updated code to pass the original to be able to reference the engine ID
  • However: The gosnmp struct has a ContextEngineID

@zoedt
Copy link
Contributor Author

zoedt commented Jan 3, 2024

@TimRots @SuperQ hi! just wanted to bump this with a question: do we feel like the PR's main logic and additions are generally okay / will be accepted with some more feedback or tweaks?

my team is hoping to utilize this logic and we would like to understand if we use it as it is right now that it won't be something we'd have to maintain ourselves if this PR doesn't actually make it in

thank you!!

Signed-off-by: zoe ✨ <9274242+zoedt@users.noreply.github.com>
@TimRots TimRots requested a review from SuperQ January 15, 2024 11:50
Copy link
Contributor

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

LGTM

@SuperQ SuperQ merged commit db0c093 into gosnmp:master Jan 15, 2024
@zoedt
Copy link
Contributor Author

zoedt commented Jan 16, 2024

@TimRots @SuperQ thank you both!!!

@zoedt zoedt deleted the multiple-users branch January 16, 2024 15:56
SuperQ added a commit that referenced this pull request Aug 7, 2024
* [CHANGE] Refactor netsnmp playback function to use an io.Reader #459
* [FEATURE] Support multiple security parameters for receiving SNMP V3 traps #457
* [ENHANCEMENT] netsnmp tests: tame overzealous file / dir permissions #458

Also update missing v1.37.0 changelog entries.

Signed-off-by: SuperQ <superq@gmail.com>
@SuperQ SuperQ mentioned this pull request Aug 7, 2024
SuperQ added a commit that referenced this pull request Aug 7, 2024
* [CHANGE] Refactor netsnmp playback function to use an io.Reader #459
* [FEATURE] Support multiple security parameters for receiving SNMP V3 traps #457
* [ENHANCEMENT] netsnmp tests: tame overzealous file / dir permissions #458

Also update missing v1.37.0 changelog entries.

Signed-off-by: SuperQ <superq@gmail.com>
vma pushed a commit to sipsolutions/gosnmp that referenced this pull request May 6, 2025
…nmp#457)

* First iteration of adding user security params map, assuming unique usernames
* Log when new SP is added to map, add logger to map

---------

Signed-off-by: zoe ✨ <9274242+zoedt@users.noreply.github.com>
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.

4 participants