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

update windows data dir installation #1510

Merged
merged 6 commits into from
Feb 8, 2024
Merged

Conversation

zackattack01
Copy link
Contributor

@zackattack01 zackattack01 commented Dec 12, 2023

There are two pieces to this update:

  1. breaks the windows installation out into:
  • C:\Program Files\Kolide\Launcher-[IDENTIFIER]\
    • Still contains the bin and conf directories
  • C:\ProgramData\Kolide\Launcher-[IDENTIFIER]\
    • Now contains the data directory
    • Still functions as the rootDir, containing all updates
  1. creates an empty launcher.db file in the data directory
  • doing this (along with any other files we want to add for cleanup) before the harvest tool (heat.exe) is run ensures that the launcher.db is cleaned up when an uninstall is initiated

Ideally we would integrate the wix RemoveFolderEx util extension into the wix-generated files (along with some registry updates) to achieve full cleanup, but this did not work as advertised after several attempts. Our cleanup complications come from arbitrarily nested directories containing filenames which are unknown at the time of harvest (e.g. rotated logs, updates, etc.). But because we are specifically concerned with the launcher.db cleanup, ensuring that file is present is enough for forward progress here.

Another option we can look into in the future if additional cleanup is needed is the wix CustomAction element. There are some reports of successful cleanup on this type of install structure using a separate removal script via CustomAction.

Including a quick logical overview of the changes here because it took me a bit to understand how wix works and how we integrate it within the build process - note that this is especially confusing because wix operates off of relative paths, expanded internally at build time, while the linux and darwin build processes are able to nest full paths within their respective root build directories back at the level of pkg/packaging/packaging.go. This makes it difficult to cleanly share as much logic as we would like between platform builds, and largely shaped this approach methodology in order to prevent excessive changes within the linux/darwin builds.

  • within pkg/packaging/packaging.go, we needed to ensure the windows rootDir would point at ProgramData (see canonicalizeRootDir for the flag file generation
    • we also needed to prevent the data (root) dir from being created at this level for MSI targets to give the logic in pkg/pkgkit/wix/wix.go the chance to set up a separate data directory for harvest (in ProgramData)
  • within pkg/pkgkit/wix/wix.go, we set up this directory and add any additional files we want to be included in the registry for cleanup on uninstall
    • we then run heat for DATADIR (expanded by wix into the ProgramData directory) with our pre-created file stubs, and include the newly generated component group from the main wix template

Testing

To test locally (outside of CI builds) I'd recommend using git bash to build on a windows machine directly (otherwise you will need to make some modifications to the commands below).

Navigate to your launcher directory within git bash and pull down this branch. Most build setup should be identical to other platforms (i.e. make deps && make).

Note your existing enroll secret and replace in the command below: cat C:/Program\ Files/Kolide/Launcher-kolide-k2/conf/secret

Run the following to build an MSI for local installation:

./build/package-builder.exe make -debug=true -transport=jsonrpc -hostname=k2device-preprod.kolide.com -output_dir=./build/ -identifier=kolide-k2 -launcher_version=./build/launcher.exe -enroll_secret="<TAKEN_FROM_ABOVE>" -i-am-a-kolide-customer

Uninstall your existing Launcher installation from Control-Panel and ensure a fresh installation by removing all of C:/Program\ Files/Kolide.

Your new build for testing should be installable from ./build/launcher.windows-service-msi.msi

pkg/packagekit/wix/wix.go Fixed Show fixed Hide fixed
Comment on lines 266 to 267
// touch these known file names before harvest to ensure they're cleaned up on uninstall
dataFilenames := []string{"launcher.db", "metadata.json"}
Copy link
Contributor

Choose a reason for hiding this comment

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

note to self -- think about this

@zackattack01 zackattack01 marked this pull request as ready for review December 21, 2023 12:18
@zackattack01 zackattack01 changed the title draft windows data dir installation update windows data dir installation Dec 21, 2023
@CLAassistant
Copy link

CLAassistant commented Dec 22, 2023

CLA assistant check
All committers have signed the CLA.

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 think this is probably correct, and I love how small it is.

How should we test this? We could build some nabalu packages with the branch maybe

RebeccaMahany
RebeccaMahany previously approved these changes Feb 6, 2024
wo.cleanDirs = append(wo.cleanDirs, wo.packageDataRoot)

fullIdentifier := fmt.Sprintf("Launcher-%s", wo.identifier)
dataFilesPath := filepath.Join(wo.packageDataRoot, fullIdentifier, "data")
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably a good idea to update the default value here https://github.com/kolide/launcher/blob/main/pkg/launcher/paths.go#L42 also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do!

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.

LGTM, thank you for the documentation in the code + in the PR description

@@ -39,7 +39,7 @@ func DefaultPath(path defaultPath) string {
if runtime.GOOS == "windows" {
switch path {
case RootDirectory:
return "C:\\Program Files\\Kolide\\Launcher-kolide-k2\\data"
return "C:\\ProgramData\\Kolide\\Launcher-kolide-k2\\data"
Copy link
Contributor

Choose a reason for hiding this comment

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

how is this going to work with existing installations? Do we need to do some kind of migration or peek at old dir first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was a recent change I can re-run some tests with to verify- but with prior testing this has always worked out regardless of existing/new installation because only the new installations have the new path in launcher.flags

Copy link
Contributor

Choose a reason for hiding this comment

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

ohh duh =) ... yea, I forgot this was assigned in launcher.flags

@zackattack01 zackattack01 added this pull request to the merge queue Feb 8, 2024
Merged via the queue into main with commit 18ea1da Feb 8, 2024
26 checks passed
@zackattack01 zackattack01 deleted the zack/windows_install_datadir branch February 8, 2024 16:06
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.

5 participants