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 launcher and publishing support to the mirror command #93

Merged
merged 2 commits into from
Aug 30, 2017
Merged

Add launcher and publishing support to the mirror command #93

merged 2 commits into from
Aug 30, 2017

Conversation

murphybytes
Copy link
Contributor

This PR includes @groob #69. It adds the following capabilities to the package-builder mirror command.

  • Create Launcher tarballs.
  • Push Launcher and Osquery tarballs to mirror.
  • Publish updates and additions to targets to Notary.

@@ -53,6 +53,22 @@ To authenticate to GCloud, use the following:
```
gcloud auth application-default login
```
#### Notary Setup
Notary Client must be properly installed and **be in your search path** in order to publish
binaries. Notary Client can be found [here](https://github.com/docker/notary). Prepare
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: don't wrap your lines to 80 in this file

osqueryd-stable.tar.gz
osqueryd-2.6.0.tar.gz
```
The tarballs are stored in the `gs://binaries-for-launcher` GCS bucket, and exposed at the `https://dl.kolide.com/kolide/<binary>/<platform>/<tarball>` url.
Copy link
Contributor

Choose a reason for hiding this comment

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

in which GCP organization?

@@ -67,6 +83,46 @@ To use the tool to generate Kolide internal development packages, run:

To use the tool to generate Kolide production packages, run:
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like the next section of the docs got weirdly inserted in the production packages section

may be used to produce tar archives for both Launcher and Osquery, upload them
to the mirror site, and register them with Notary so that they can be validated as
part of the Launcher autoupdate process. The following commands would download and
publish the latest version of Osquery, and would publish version 1.2 of Launcher to
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need a VERSION env for this as the package builder is already built with github.com/kolide/kit/version metadata.

mirror
}

func (m mirror) upload(binary, source string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

these two mirror methods are operating on a non-pointer mirror here. is that intentional?

}

// implements methods to post launcher to mirror
type launcher struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe launcherMirror?

return errors.Wrap(err, "preparing osquery mirror upload")
}
bkt := client.Bucket(mirrorBucketname)
objectName := fmt.Sprintf("kolide/%s/%s/%s", binary, m.platform, filepath.Base(source))
Copy link
Contributor

Choose a reason for hiding this comment

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

Would path.join be useful here?

}
// we assume we are running from project root
// but just in case, check for binary
launcherPath := filepath.Join("build", runtime.GOOS, "launcher")
Copy link
Contributor

Choose a reason for hiding this comment

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

you can do filepath.Join(packaging.LauncherSource(), "build", "runtime.GOOS, "launcher") here for the absolute path.

if _, err := os.Stat(launcherPath); err != nil {
return "", errors.Wrap(err, "getting launcher version")
}
cmd := exec.Command(launcherPath, "-version")
Copy link
Contributor

Choose a reason for hiding this comment

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

Package builder is compiled with github.com/kolide/kit/version metadata, so executing the binary is not required to get the version.

"output", tarFilePath,
)
sources := []string{
filepath.Join("build", l.platform, "launcher"),
Copy link
Contributor

Choose a reason for hiding this comment

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

use LauncherSource() here for the absolute path

Copy link
Contributor

@marpaia marpaia left a comment

Choose a reason for hiding this comment

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

This is looking a lot better. My main concern now, like I said in one of the comments, is that all of the options complicate the control flow. Ideally, I could just run package-builder mirror and (assuming I had the keys and notary configured locally) the mirror would be created, binaries uploaded, etc.

// name of GCS bucket where tarballs are saved to
const (
mirrorBucketname = "binaries-for-launcher"
stagingPath = "/tmp/osquery_mirror"
Copy link
Contributor

Choose a reason for hiding this comment

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

use ioutil.TempDir instead of a hardcoded temp deirectory

)
flPlatform = flagset.String(
"platform",
"darwin",
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps just do all platforms and remove this flag?

flTar = flagset.Bool(
"tar",
true,
"create osqueryd.tar.gz archive from binary",
Copy link
Contributor

Choose a reason for hiding this comment

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

why wouldn't I want to do this when running the mirror command?

flExtract = flagset.Bool(
"extract",
true,
"extract binary from downloaded archive",
Copy link
Contributor

Choose a reason for hiding this comment

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

why wouldn't I want to do this when running the mirror command?

flDownload = flagset.Bool(
"download",
true,
"download a fresh copy of osquery from s3",
Copy link
Contributor

Choose a reason for hiding this comment

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

package-builder dev and prod don't give you the option on whether or not you should download anything, I don't think this should either.

flUpdateChannel = flagset.String(
"update_channel",
"stable",
"create a tarball for a specific autoupdate channel. Valid values: stable,beta,nightly",
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to platform, I think this should not be an option and it should just loop through all of them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, here I disagree. You can't mark a beta binary as stable for example.

You have to make that decision before running the utility.

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 that all of this conditional logic should be flattened out and

  • for each update channel
  • for each platform

the binaries should be

  • downloaded
  • extracted
  • tar'd
  • uploaded
  • published

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marpaia I agree for the most part, but @groob is correct, you'll have to choose the channel that you'll be publishing.

Copy link
Contributor

Choose a reason for hiding this comment

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

why can't you make sure that all of the update channels are appropriately published?

Copy link
Contributor

Choose a reason for hiding this comment

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

we resolved this one in chat with regards to update channel.

return errors.Wrap(err, "uploading")
}
}
if m.wantUpload && m.wantPublish {
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 all of the flags that are allowed to be used in this tool make the control flow very complex. It's likely that there are several combinations of options that don't work together, for example. I think we should remove most of the command-line options from this tool and have the default behavior just do all of the things you want.

"msg", "starting",
)
ctx := context.Background()
client, err := storage.NewClient(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat!

@@ -0,0 +1,33 @@
all: clean-darwin dl-darwin extract-darwin tar-darwin dl-linux tar-linux
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this makefile still necessary?

target,
archive,
"-p",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably want to add stdout/stderr to the publish command in case it fails.

buildDir := filepath.Join(packaging.LauncherSource(), "build")
sources := []string{
filepath.Join(buildDir, platform, "launcher"),
filepath.Join(buildDir, platform, "osquery-extension.ext"),
Copy link
Contributor

Choose a reason for hiding this comment

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

You're publishing the .ext file as well. I am not sure it's necessary. It's unlikely to change, it's already shipped with the package.

I also don't think the autoupdate code supports tarballs with multiple binaries.
If you include the launcher, definitely double-check the autoupdate code.

```


### Version info
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this got a little out of place as the next section here isn't about version info as far as I can tell.

@murphybytes murphybytes merged commit 874e302 into kolide:master Aug 30, 2017
@murphybytes murphybytes deleted the launcher_download branch August 30, 2017 17:40
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