Native install and uninstall of osquery via osctrld - #22
Merged
Merged
Conversation
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.
Native install and uninstall
Ports the osctrl quick-add and quick-remove scripts into Go.
osctrld installdoes natively what the shell/PowerShell scripts do — installs osquery when missing or outdated, writes the secret, flags and certificate, then starts and enables the service.osctrld uninstallreverses the configuration and deliberately leaves osquery installed, matching the remove script.enrollandremoveare unchanged — they still print scripts to stdout.Design decisions
retrieveVerifyalready returns flags, certificate and required version together, soinstallneeds no extra calls.--osquery-sha256; without either,--allow-unverifiedis required.VerifyResponsecarries anosquery_sha256field that today's osctrl doesn't send yet — once it does, every node starts verifying with no client change.sudo. It requires existing root (or Administrator) and fails fast before any network or filesystem work.execCommandseam, so tests never invokedpkg,systemctlormsiexec.Windows
Gains real service control via
golang.org/x/sys/windows/svc/mgr, replacing the previous "unsupported on windows" error forinstall/uninstall. Two limitations are documented rather than hidden: osctrld does not create theosquerydservice (it relies on the MSI having registered it), and theservicedaemon's restart path still has no Windows case —osqueryRestartCommandis unchanged, so daemon mode syncs files but leaves osquery on the old configuration. Wiring that up is a small follow-up now that the service-manager pieces exist.Not ported deliberately: FreeBSD, the PowerShell ACL hardening (the MSI already sets those permissions and osctrld writes only config files), machine
PATHmodification, and the service delete-and-recreate dance.Notable fix along the way
writeContentExistsonly applied its file mode at creation —os.WriteFile's perm is ignored for an existing file. A node enrolled by the quick-add script has its secret at0644, soinstallwould have reported success while leaving the enrollment credential world-readable. The mode is now enforced on every path, including the unchanged-content early return, so a re-run repairs a stale mode.