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

add func to exclude launcher db from time machine #1531

2 changes: 2 additions & 0 deletions cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/kolide/launcher/ee/agent/startupsettings"
"github.com/kolide/launcher/ee/agent/storage"
agentbbolt "github.com/kolide/launcher/ee/agent/storage/bbolt"
"github.com/kolide/launcher/ee/agent/timemachine"
"github.com/kolide/launcher/ee/control/actionqueue"
"github.com/kolide/launcher/ee/control/consumers/acceleratecontrolconsumer"
"github.com/kolide/launcher/ee/control/consumers/flareconsumer"
Expand Down Expand Up @@ -171,6 +172,7 @@ func runLauncher(ctx context.Context, cancel func(), slogger, systemSlogger *mul
k := knapsack.New(stores, flagController, db, slogger, systemSlogger)

go runOsqueryVersionCheck(ctx, logger, k.LatestOsquerydPath(ctx))
go timemachine.ExcludeLauncherDB(ctx, k)

if k.Debug() {
// If we're in debug mode, then we assume we want to echo _all_ logs to stderr.
Expand Down
36 changes: 36 additions & 0 deletions ee/agent/timemachine/timemachine_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//go:build darwin
// +build darwin

package timemachine

import (
"context"
"log/slog"

"github.com/kolide/launcher/ee/agent/types"
"github.com/kolide/launcher/ee/allowedcmd"
)

// ExcludeLauncherDB adds the launcher db to the time machine exclusions for
// darwin and is noop for other oses
func ExcludeLauncherDB(ctx context.Context, k types.Knapsack) {
dbPath := k.BboltDB().Path()
cmd, err := allowedcmd.Tmutil(ctx, "addexclusion", dbPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should exclude the whole root directory. Maybe the secret too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually keep the secret. But probably ignore the whole root directory

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 thought about that, but if I understand correctly, that would mean we would also not bring along all the updates. So after a time machine restore / backup the user would be back on the very first version of launcher they downloaded and would need to update again. Maybe that's okay?

Copy link
Contributor

Choose a reason for hiding this comment

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

Grabbing the updates, and the TUF db, is a great counterpoint. I think you're right, it's good to carry those.

Maybe we should drop some more stuff though. Can we go by wildcard? Or do we need to do own globbing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can wild card, you thinking *.db?

Copy link
Contributor

Choose a reason for hiding this comment

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

$ ls /var/kolide-k2/k2device-preprod.kolide.com/
augeas-lenses				menu.json
debug-2023-12-31T20-27-14.599.json.gz	menu_template.json
debug-2024-01-03T05-30-26.256.json.gz	metadata.json
debug-2024-01-06T19-20-54.029.json.gz	metadata.plist
debug-2024-01-09T01-44-56.485.json.gz	osquery.autoload
debug-2024-01-10T20-30-07.640.json.gz	osquery.db
debug.json				osquery.pid
desktop_501				osquery.sock
kolide.png				osquery.sock.34719
kv.sqlite				osquery.sock.3513
launcher-staging			osqueryd-staging
launcher-tuf				osqueryd-tuf
launcher-tuf-dev			osqueryd-tuf-dev
launcher-version-1.4.1-3-ge21cebc	tuf
launcher.db				tuf-dev
launcher.pid				updates

json, json.gz, the metadata, the menu, most of the osquery files, desktop, the pid files, sockets...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wildcards did not work as expected, ended up globbing

if err != nil {
k.Slogger().Log(ctx, slog.LevelError,
"could not create tmutil command to add launcher db to time machine exclusions",
"err", err,
"path", dbPath,
)
return
}

if err := cmd.Run(); err != nil {
k.Slogger().Log(ctx, slog.LevelError,
"running command to add launcher db to time machine exclusions",
"err", err,
"path", dbPath,
)
return
}
}
16 changes: 16 additions & 0 deletions ee/agent/timemachine/timemachine_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build !darwin
// +build !darwin

package timemachine

import (
"context"

"github.com/kolide/launcher/ee/agent/types"
)

// ExcludeLauncherDB adds the launcher db to the time machine exclusions for
// darwin and is noop for other oses
func ExcludeLauncherDB(_ context.Context, _ types.Knapsack) {
// do nothing, no time machine on non darwin
}
Loading