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

Rewrite user creation to prevent quoting bug (fixes #173) #176

Merged
merged 2 commits into from
Feb 24, 2019
Merged

Rewrite user creation to prevent quoting bug (fixes #173) #176

merged 2 commits into from
Feb 24, 2019

Conversation

smoeding
Copy link
Contributor

Pull Request (PR) description

This change replaces the exec resource to update the config file with the SNMPv3 user name with a file_line resource. This moves more logic from the exec resource to Puppet types. It should handle special characters better and make the code more robust.

Unfortunately the exec resource can't be replaced completely (see comment in #173).

With this code the service is also stopped only once if multiple users are to be created. This speeds up processing.

This Pull Request (PR) fixes the following issues

Fixes #173

@@ -39,8 +39,8 @@
}

$cmd = $privpass ? {
undef => "createUser ${title} ${authtype} \\\"${authpass}\\\"",
default => "createUser ${title} ${authtype} \\\"${authpass}\\\" ${privtype} \\\"${privpass}\\\""
undef => "createUser ${title} ${authtype} \"${authpass}\"",
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need double quotes around those strings? Can't we use single quotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe. I will do some tests when I get back into office.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that single quotes would also work.

Maybe the quoting should be reviewed. Quotes are only required when the password contains spaces. On the other hand passwords may also include quotes which then need to be escaped (not currently implemented). We could drop the quotes in Puppet and forget about escaping if we would just prohibit passwords with spaces.

#
$command = "service ${service_name} stop ; sleep 5"

exec { "stop-${service_name}":
Copy link
Member

Choose a reason for hiding this comment

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

Why is this even an exec resource? Can't we refresh the service?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, probably not. It seems to be working the following way: The demon writes the internal state (users with hashed passwords, number of restarts, ...) to the config in /var/lib/snmp/snmpd.conf when it terminates. It doesn't update the file, it replaces it. So you loose everything you add to the file when the daemon is still running. Therefore you need to stop the daemon before you add the new users.

Unfortunately you can't use one service resource to terminate a service and another one to start it. If they refer to the same service name then Puppet will throw a duplicate declaration error. So I believe we will have to keep the exec to stop the daemon. I don't like it either but I don't have any better idea.

Copy link

Choose a reason for hiding this comment

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

I'm looking to make some changes to this module to handle v3 engine IDs and other things. I've noticed that /var/lib/net-snmp is being used for the configuration. Why not use /etc/snmp instead? The files under /var/lib/net-snmp say to not edit manually and would make the code for this a lot cleaner.

Copy link
Member

@Dan33l Dan33l Feb 22, 2019

Choose a reason for hiding this comment

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

I've noticed that /var/lib/net-snmp is being used for the configuration. Why not use /etc/snmp instead? The files under /var/lib/net-snmp say to not edit manually and would make the code for this a lot cleaner.

@hanej smoeding explains well. If you need to ready again, for instance have a look to:
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html-single/system_administrators_guide/#sect-System_Monitoring_Tools-Net-SNMP-Configuring

Copy link

Choose a reason for hiding this comment

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

Even that documentation says to edit the config files under /etc/snmp. I’ll create a PR with my changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See the official manpage at http://www.net-snmp.org/docs/man/snmpd.examples.html

Remember that these createUser directives should be defined in the /var/net-snmp/snmpd.conf file, rather than the usual location.

@ghoneycutt ghoneycutt added the bug Something isn't working label Feb 13, 2019
@Dan33l
Copy link
Member

Dan33l commented Feb 22, 2019

@smoeding do you need to make some more work about this PR ? Are you waiting a review ?

@smoeding
Copy link
Contributor Author

@Dan33l As far as I am concerned I am done with this PR.

Copy link
Member

@Dan33l Dan33l left a comment

Choose a reason for hiding this comment

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

LGTM

@Dan33l
Copy link
Member

Dan33l commented Feb 23, 2019

@smoeding sorry but with the last merge, this PR needs now a rebase. Can you do it ? and i'll merge it.

@alexjfisher
Copy link
Member

@smoeding I'll second @Dan33l in apologising about the need for a rebase. #181 was a pretty significant change and unfortunately some disruption was inevitable.

Thanks for your PR and understanding.

This change replaces the exec resource to update the config file with
the SNMPv3 user name with a file_line resource.
@smoeding
Copy link
Contributor Author

No need to apologize! Your are doing a good job to bring the project forward!

@alexjfisher alexjfisher merged commit 5f9273d into voxpupuli:master Feb 24, 2019
@alexjfisher
Copy link
Member

@smoeding Thanks!


Data type: `String`

The authentication type to calculate. This must either be
Copy link
Member

Choose a reason for hiding this comment

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

puppet-strings isn't very good with function docs. I think this function is private, so have opened #186

@smoeding I see you contributed this function. Am I right in thinking it's private? (Comments on the original PR suggest to me it is)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There might maybe be a time when this might be handy outside of the module. But currently I would think it is safe to keep it private to the module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failure to set authpass/privpass containing a dollar sign
6 participants