-
Notifications
You must be signed in to change notification settings - Fork 103
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
Changes from 2 commits
5eb8e24
ce242c6
6903d3c
c597091
c190125
7ff6a06
01cde17
e5df222
657bbf1
c7a3789
a23a1a5
28ea73f
7c0bd0b
4ae6693
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package internal | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"time" | ||
|
||
"github.com/groob/plist" | ||
"github.com/kolide/kit/version" | ||
"github.com/kolide/launcher/pkg/agent/types" | ||
"github.com/kolide/launcher/pkg/debug/checkups" | ||
) | ||
|
||
type metadata struct { | ||
DeviceId string `json:"device_id" plist:"device_id"` | ||
OrganizationId string `json:"organization_id" plist:"organization_id"` | ||
Timestamp string `json:"timestamp" plist:"timestamp"` | ||
Version string `json:"version" plist:"version"` | ||
} | ||
|
||
// 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) error { | ||
metadataJSONFile := filepath.Join(rootDir, "metadata.json") | ||
sdc := checkups.NewServerDataCheckup(knapsack) | ||
if err := sdc.Run(ctx, io.Discard); err != nil { | ||
return fmt.Errorf("unable to gather metadata, error: %w", err) | ||
} | ||
|
||
metadata := metadata{ | ||
DeviceId: sdc.DeviceId, | ||
OrganizationId: sdc.OrganizationId, | ||
Timestamp: time.Now().String(), | ||
Version: version.Version().Version, | ||
} | ||
|
||
metadataJSON, err := json.MarshalIndent(metadata, "", " ") | ||
if err != nil { | ||
return fmt.Errorf("unable to JSON marshal metadata, error: %w", err) | ||
} | ||
|
||
err = os.WriteFile(metadataJSONFile, metadataJSON, 0644) | ||
if err != nil { | ||
zackattack01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return fmt.Errorf("unable to write JSON metadata, error: %w", err) | ||
} | ||
|
||
if runtime.GOOS != "darwin" { | ||
return nil | ||
} | ||
|
||
metadataPlistFile := filepath.Join(rootDir, "metadata.plist") | ||
metadataPlist, err := plist.MarshalIndent(metadata, " ") | ||
|
||
if err != nil { | ||
return fmt.Errorf("unable to Plist marshal metadata, error: %w", err) | ||
} | ||
|
||
err = os.WriteFile(metadataPlistFile, metadataPlist, 0644) | ||
if err != nil { | ||
zackattack01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return fmt.Errorf("unable to write plist metadata, error: %w", err) | ||
} | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea, this ☝️ is better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, a subscriber makes more sense |
||
level.Error(logger).Log("msg", "unable to write metadata", "error", err.Error()) | ||
zackattack01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// create the certificate pool | ||
var rootPool *x509.CertPool | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep!