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

write out metadata json and plist files to root install directory #1417

Merged
merged 14 commits into from
Oct 23, 2023

Conversation

zackattack01
Copy link
Contributor

addresses #1404

cmd/launcher/launcher.go Outdated Show resolved Hide resolved
@@ -193,6 +193,9 @@ func runLauncher(ctx context.Context, cancel func(), opts *launcher.Options) err
// we expect we're live. Record the version for osquery to
// pickup
internal.RecordLauncherVersion(rootDirectory)
if err = internal.RecordMetadata(rootDirectory, ctx, k); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we confident we'll have all this data on a fresh install since it has to come down via control server? Maybe that's okay and it will get written on the next launcher start up? or perhaps we would to do some retry logic in a goroutine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

discussed offline^ my testing may have been flawed here- adding some async retry, thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm... if we're really concerned about that, I wonder if we should move the write into the server data consumer.

Copy link
Contributor

@James-Pickett James-Pickett Oct 19, 2023

Choose a reason for hiding this comment

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

yea, this ☝️ is better

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, a subscriber makes more sense

zackattack01 and others added 2 commits October 19, 2023 10:55
Co-authored-by: James Pickett <James-Pickett@users.noreply.github.com>
James-Pickett
James-Pickett previously approved these changes Oct 19, 2023
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


// RecordMetadata writes out both a json and plist (for darwin) file including all information
// in the metadata struct to the root install directory
func RecordMetadata(rootDir string, ctx context.Context, knapsack types.Knapsack, logger log.Logger) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ctx should be first, logger second.

is rootDir in knapsack?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cleaning this up, yes it should be just making sure it is initialized by then

// RecordMetadata writes out both a json and plist (for darwin) file including all information
// in the metadata struct to the root install directory
func RecordMetadata(rootDir string, ctx context.Context, knapsack types.Knapsack, logger log.Logger) {
logger = log.With(logger, "method")
Copy link
Contributor

Choose a reason for hiding this comment

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

?

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 fix this

}

if err := backoff.WaitFor(func() error {
sdc := checkups.NewServerDataCheckup(knapsack)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably fish this out of sdc.k.ServerProvidedDataStore() instead of going through checkup

Version: version.Version().Version,
}

if err := backoff.WaitFor(func() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is backoff bringing?

cmd/launcher/internal/record_metadata.go Outdated Show resolved Hide resolved
cmd/launcher/internal/record_metadata.go Outdated Show resolved Hide resolved
Co-authored-by: seph <seph@kolide.co>

type metadata struct {
DeviceId string `json:"device_id" plist:"device_id"`
OrganizationId string `json:"organization_id" plist:"organization_id"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add OrganizationMunemo too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep!

@zackattack01 zackattack01 marked this pull request as draft October 20, 2023 16:14
@zackattack01 zackattack01 marked this pull request as ready for review October 20, 2023 16:23
Comment on lines 71 to 75
if err != nil {
return err
} else if string(deviceId) == "" {
return errors.New("device_id is not yet present in ServerProvidedDataStore")
}
Copy link
Contributor

@James-Pickett James-Pickett Oct 20, 2023

Choose a reason for hiding this comment

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

dont need the else if here since you're returning

Suggested change
if err != nil {
return err
} else if string(deviceId) == "" {
return errors.New("device_id is not yet present in ServerProvidedDataStore")
}
if err != nil {
return err
}
if string(deviceId) == "" {
return errors.New("device_id is not yet present in ServerProvidedDataStore")
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't return the error. If we don't have that data, skip and and try the next piece of data. (Probably log the error)

Comment on lines 80 to 84
if err != nil {
return err
} else if string(organizationId) == "" {
return errors.New("organization_id is not yet present in ServerProvidedDataStore")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Suggested change
if err != nil {
return err
} else if string(organizationId) == "" {
return errors.New("organization_id is not yet present in ServerProvidedDataStore")
}
if err != nil {
return err
}
if string(organizationId) == "" {
return errors.New("organization_id is not yet present in ServerProvidedDataStore")
}

Comment on lines 89 to 93
if err != nil {
return err
} else if string(munemo) == "" {
return errors.New("munemo is not yet present in ServerProvidedDataStore")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same ... starting to feel like this should be a little helper func

Suggested change
if err != nil {
return err
} else if string(munemo) == "" {
return errors.New("munemo is not yet present in ServerProvidedDataStore")
}
if err != nil {
return err
}
if string(munemo) == "" {
return errors.New("munemo is not yet present in ServerProvidedDataStore")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed, I will pull these into a helper. thank you!

// subsystem. whenever new data is received, it will rewrite the metadata.json
// and metadata.plist files to our root install directory
metadataWriter struct {
ctx context.Context
Copy link
Contributor

Choose a reason for hiding this comment

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

context should not be embedded in structs. (and probably isn't needed)

cmd/launcher/internal/record_metadata.go Outdated Show resolved Hide resolved
cmd/launcher/internal/record_metadata.go Outdated Show resolved Hide resolved
Comment on lines 71 to 75
if err != nil {
return err
} else if string(deviceId) == "" {
return errors.New("device_id is not yet present in ServerProvidedDataStore")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't return the error. If we don't have that data, skip and and try the next piece of data. (Probably log the error)

@zackattack01 zackattack01 added this pull request to the merge queue Oct 23, 2023
Merged via the queue into main with commit 6e99505 Oct 23, 2023
24 checks passed
@zackattack01 zackattack01 deleted the zack/write_out_metadata branch October 23, 2023 13:57
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