SNMP: Add secret handling from custom_fields#2168
Open
osfrickler wants to merge 1 commit intomainfrom
Open
Conversation
Needed to properly decode vault encrypted values. Signed-off-by: Dr. Jens Harbott <harbott@osism.tech>
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Decrypting
node_secretsin-place will mutatedevice.custom_fields['secrets']for all subsequent users of thedeviceobject; consider deep-copying the secrets dict before callingdeep_decryptto avoid side effects. - The SNMP user passwords now only read from
custom_fields['secrets']; if there are existing deployments that still set_segment_snmp_server_userauthpass/_segment_snmp_server_userprivpassinconfig_context, consider falling back to those keys to preserve backward compatibility. - You create a vault and decrypt secrets even when no SNMP user is configured; you could lazily initialize and decrypt only when
usernameis set to reduce unnecessary work and potential errors when vault access is not needed.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Decrypting `node_secrets` in-place will mutate `device.custom_fields['secrets']` for all subsequent users of the `device` object; consider deep-copying the secrets dict before calling `deep_decrypt` to avoid side effects.
- The SNMP user passwords now only read from `custom_fields['secrets']`; if there are existing deployments that still set `_segment_snmp_server_userauthpass` / `_segment_snmp_server_userprivpass` in `config_context`, consider falling back to those keys to preserve backward compatibility.
- You create a vault and decrypt secrets even when no SNMP user is configured; you could lazily initialize and decrypt only when `username` is set to reduce unnecessary work and potential errors when vault access is not needed.
## Individual Comments
### Comment 1
<location path="osism/tasks/conductor/sonic/config_generator.py" line_range="2160-2163" />
<code_context>
if username:
- userauthpass = device.config_context.get(
- "_segment_snmp_server_userauthpass", "OBFUSCATEDSECRET1"
+ userauthpass = node_secrets.get(
+ "_segment_snmp_server_userauthpass", "OBFUSCATEDAUTHSECRET"
)
- userprivpass = device.config_context.get(
- "_segment_snmp_server_userprivpass", "OBFUSCATEDSECRET2"
+ userprivpass = node_secrets.get(
+ "_segment_snmp_server_userprivpass", "OBFUSCATEDPRIVSECRET"
)
</code_context>
<issue_to_address>
**🚨 issue (security):** Using hard-coded default SNMP credentials when secrets are missing is risky and may lead to predictable credentials in production.
Right now, if those keys are missing in `node_secrets`, we silently fall back to `"OBFUSCATEDAUTHSECRET"` / `"OBFUSCATEDPRIVSECRET"`, creating fixed, guessable credentials when secrets are misconfigured. Instead, consider either not configuring the SNMP user when secrets are absent, failing fast with a clear error, or requiring explicit configuration rather than using built‑in defaults.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Comment on lines
+2160
to
+2163
| userauthpass = node_secrets.get( | ||
| "_segment_snmp_server_userauthpass", "OBFUSCATEDAUTHSECRET" | ||
| ) | ||
| userprivpass = device.config_context.get( | ||
| "_segment_snmp_server_userprivpass", "OBFUSCATEDSECRET2" | ||
| userprivpass = node_secrets.get( |
There was a problem hiding this comment.
🚨 issue (security): Using hard-coded default SNMP credentials when secrets are missing is risky and may lead to predictable credentials in production.
Right now, if those keys are missing in node_secrets, we silently fall back to "OBFUSCATEDAUTHSECRET" / "OBFUSCATEDPRIVSECRET", creating fixed, guessable credentials when secrets are misconfigured. Instead, consider either not configuring the SNMP user when secrets are absent, failing fast with a clear error, or requiring explicit configuration rather than using built‑in defaults.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Needed to properly decode vault encrypted values.