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

auto load ATC config in interactive #1685

Merged

Conversation

James-Pickett
Copy link
Contributor

@James-Pickett James-Pickett commented Apr 22, 2024

automatically load automatic table configuration from osquery config when running launcher in interactive mode

closes #1683

@James-Pickett James-Pickett changed the title write atc config to DB auto load ATC config in interactive Apr 22, 2024
@@ -63,6 +65,18 @@ func (s *startupSettingsWriter) setFlags() error {
}
updatedFlags["use_tuf_autoupdater"] = "enabled" // Hardcode for backwards compatibility circa v1.5.3

// Set flags will only be called when a flag value changes. The osquery config that contains the atc config
// comes in via osquery extension. So a new config will not trigger a re-write.
atcConfig, err := s.extractAutoTableConstructionConfig()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it worth figuring out the plumbing to have this fire when we get a new osquery config? This would likely mean that launcher interactive will not pick up the ATCs until the first launcher start up after getting osq config.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand... Is this only called on startup? Which means the sqlite conf file may lag weeks to months?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's possible. I'm trying to find a clever way to plumb this through .... we could treat config like a flag in knapsack and use it's observer pattern or just find a way to have the extension call startupsettings.OpenWriter when the config updates.

Copy link
Contributor

Choose a reason for hiding this comment

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

mmm, that's an interesting thought. If we ever decide we need to restart osquery on a config change, would it leverage that?

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 doubt we would ever leverage that when launcher (daemon) is restarting osquery, since launcher (daemon) can just read the config out of bolt db.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right -- that extension would read it from boltdb. But we still need something like that to trigger the restart, don't we?

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've updated this to have the extension just open the startup settings writer to trigger the write when it gets a new config. I see what you mean about restarting on a new config, as discussed, maybe an issue, but out of scope for this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree it's out of scope for this PR. Mostly mentioning it in case it chanses the direction you want to go in

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.

Looks pretty good. A couple questions

@@ -63,6 +65,18 @@ func (s *startupSettingsWriter) setFlags() error {
}
updatedFlags["use_tuf_autoupdater"] = "enabled" // Hardcode for backwards compatibility circa v1.5.3

// Set flags will only be called when a flag value changes. The osquery config that contains the atc config
// comes in via osquery extension. So a new config will not trigger a re-write.
atcConfig, err := s.extractAutoTableConstructionConfig()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand... Is this only called on startup? Which means the sqlite conf file may lag weeks to months?

pkg/launcher/paths.go Show resolved Hide resolved
pkg/osquery/interactive/interactive.go Outdated Show resolved Hide resolved
pkg/osquery/interactive/interactive.go Outdated Show resolved Hide resolved
@James-Pickett James-Pickett marked this pull request as ready for review April 24, 2024 21:30
Copy link
Contributor

@RebeccaMahany RebeccaMahany left a comment

Choose a reason for hiding this comment

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

I'm sorry for reviewing this piecemeal -- I didn't quite have enough time to finish up reviewing interactive.go. I'll come back to it first thing tomorrow!

@@ -517,6 +518,18 @@ func (e *Extension) GenerateConfigs(ctx context.Context) (map[string]string, err
} else {
// Store good config
e.knapsack.ConfigStore().Set([]byte(configKey), []byte(config))

// open the start up settings writer just to trigger a write of the config,
// then we can immediately close it
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 maybe it would feel cleaner/less easy to introduce bugs in the future if we had a specific function to call to perform the config write, rather than relying on a side effect of OpenWriter...maybe setFlags could be exposed as SyncFlags or something? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how about renaming to WriteSettings and removing from the constructor?

Copy link
Contributor

Choose a reason for hiding this comment

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

That works for me 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

RebeccaMahany
RebeccaMahany previously approved these changes Apr 25, 2024
Copy link
Contributor

@RebeccaMahany RebeccaMahany left a comment

Choose a reason for hiding this comment

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

Never mind, I ended up having time to finish reviewing! This looks good to me overall -- had one final question but it's not blocking.

RebeccaMahany
RebeccaMahany previously approved these changes Apr 26, 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.

I didn't test this, but I think it's probably fine

@James-Pickett James-Pickett enabled auto-merge April 26, 2024 22:27
@James-Pickett James-Pickett added this pull request to the merge queue Apr 26, 2024
Merged via the queue into kolide:main with commit f96aa62 Apr 26, 2024
31 checks passed
@James-Pickett James-Pickett deleted the james/auto-config-atcs-in-interactive branch April 26, 2024 22:39
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.

launcher interactive should include ATC tables
3 participants