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

Allow launcher to run without enrollment secret #1608

Merged

Conversation

RebeccaMahany
Copy link
Contributor

@RebeccaMahany RebeccaMahany commented Feb 15, 2024

Changes

  • launcher runs, instead of immediately shutting down, if it doesn't have an enroll secret
  • lay groundwork for platform-specific ways of reading the enrollment secret in the future and for exposing enrollment status to localserver
  • attempt enrollment immediately, before rungroups even start

Details

Before, the osquery extension rungroup could not be created if the enroll secret wasn't present, preventing launcher from starting up at all. Now, if the secret isn't present, launcher will still start, and will just return an empty config to osquery. Whenever the secret becomes available, it will perform enrollment.

I pulled out reading the secret into the knapsack, with the idea being that in the future we could a) expose enrollment status from localserver, and b) have per-platform implementations of this function that would allow us to e.g. read the key from the Windows registry.

This PR also adds an attempt at immediate enrollment in the background, before the rungroups even start. This should hopefully make first-time launcher startup faster.

Relates to #1473.

Testing notes

In here

Force reenrollment and remove access to enrollment secret:

sudo launchctl unload /Library/LaunchDaemons/com.kolide-k2.launcher.plist
sudo mv /etc/kolide-k2/secret /etc/kolide-k2/secret.bak
sudo rm -rf /var/kolide-k2/k2device-preprod.kolide.com
sudo mkdir /var/kolide-k2/k2device-preprod.kolide.com
sudo chmod -R 0755 /var/kolide-k2/*
sudo launchctl load /Library/LaunchDaemons/com.kolide-k2.launcher.plist

Confirm that launcher starts up and that the osquery process starts up.

Eventually, make the secret available:

sudo mv /etc/kolide-k2/secret.bak /etc/kolide-k2/secret

Observe launcher immediately complete enrollment.

@RebeccaMahany RebeccaMahany force-pushed the becca/run-without-enroll-secret branch from d09e931 to 404cf34 Compare February 15, 2024 18:51
if !e.enrolled() {
// Not enrolled yet -- return an empty config
return map[string]string{"config": "{}"}, nil
}
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'm not positive we even need this? If I omit it, we get:

{
"time":"2024-02-15T18:55:35.676293Z",
"level":"INFO",
"source":{
  "function":"github.com/kolide/launcher/ee/log/osquerylogs.(*OsqueryLogAdapter).Write",
  "file":"/Users/rebeccamahany-horton/Repos/launcher/ee/log/osquerylogs/log.go","line":83},
  "msg":"W0215 13:55:35.676178 -347473728 init.cpp:760] Error reading config: error getting config: loading config failed, no cached config: enrollment invalid, reenrollment errored: could not read enroll secret: could not read enroll secret path /etc/kolide-k2/secret: open /etc/kolide-k2/secret: no such file or directory",
  "launcher_run_id":"01HPQ1ZGS0R3Q0WAZ7FDB4N7FV",
  "component":"osquery",
  "osqlevel":"stderr",
  "caller":"init.cpp:760"
}

And behavior doesn't otherwise change -- as soon as I make the secret file available, launcher completes enrollment and queries start to run.

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 opinion about this. It seems easier to iterate and change

directionless
directionless previously approved these changes Feb 15, 2024
Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

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

This is a nice, very narrow, change on the way.

I think there's stuff we should evolve on -- I think we should rename osquery.Extension to something like agent.Core. I think we should trigger this from runLauncher, not from extension. But I think this could merge and iterate.

if !e.enrolled() {
// Not enrolled yet -- return an empty config
return map[string]string{"config": "{}"}, nil
}
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 opinion about this. It seems easier to iterate and change

@RebeccaMahany RebeccaMahany marked this pull request as ready for review February 15, 2024 19:13
Copy link
Contributor

@James-Pickett James-Pickett left a comment

Choose a reason for hiding this comment

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

nice

@RebeccaMahany RebeccaMahany added this pull request to the merge queue Feb 15, 2024
Merged via the queue into kolide:main with commit 2f09c93 Feb 15, 2024
26 checks passed
@RebeccaMahany RebeccaMahany deleted the becca/run-without-enroll-secret branch February 15, 2024 21:46
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.

3 participants