Skip to content

Commit

Permalink
[Ingest Manager] Agent includes pgp file (#19480)
Browse files Browse the repository at this point in the history
[Ingest Manager] Agent includes pgp file (#19480)
  • Loading branch information
michalpristas authored Sep 22, 2020
1 parent 1761515 commit aebddba
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 107 deletions.
1 change: 1 addition & 0 deletions dev-tools/mage/crossbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (b GolangCrossBuilder) Build() error {
"--env", "MAGEFILE_VERBOSE="+verbose,
"--env", "MAGEFILE_TIMEOUT="+EnvOr("MAGEFILE_TIMEOUT", ""),
"--env", fmt.Sprintf("SNAPSHOT=%v", Snapshot),
"--env", fmt.Sprintf("DEV=%v", DevBuild),
"-v", repoInfo.RootDir+":"+mountPoint,
"-w", workDir,
image,
Expand Down
7 changes: 7 additions & 0 deletions dev-tools/mage/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var (
BeatProjectType ProjectType

Snapshot bool
DevBuild bool

versionQualified bool
versionQualifier string
Expand Down Expand Up @@ -117,6 +118,11 @@ func init() {
panic(errors.Wrap(err, "failed to parse SNAPSHOT env value"))
}

DevBuild, err = strconv.ParseBool(EnvOr("DEV", "false"))
if err != nil {
panic(errors.Wrap(err, "failed to parse DEV env value"))
}

versionQualifier, versionQualified = os.LookupEnv("VERSION_QUALIFIER")
}

Expand Down Expand Up @@ -165,6 +171,7 @@ func varMap(args ...map[string]interface{}) map[string]interface{} {
"BeatURL": BeatURL,
"BeatUser": BeatUser,
"Snapshot": Snapshot,
"DEV": DevBuild,
"Qualifier": versionQualifier,
}

Expand Down
31 changes: 31 additions & 0 deletions x-pack/elastic-agent/GPG-KEY-elasticsearch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2.0.14 (GNU/Linux)

mQENBFI3HsoBCADXDtbNJnxbPqB1vDNtCsqhe49vFYsZN9IOZsZXgp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t8/FKG7sHRFvePFU0ZS6JFx9GJqjSBbHRRkam+4emW3uWgVfZxuwcUCn1ayNgRt
KiFv9jQrg2TIWEvzYx9tywTCxc+FFMWAlbCzi+m4WD+QUWWfDQ009U/WM0ks0Kww
EwSk/UDuToxGnKU2dQARAQABiQEfBBgBAgAJBQJSNx7KAhsMAAoJENJ9ZmzYjkK0
c3MIAIE9hAR20mqJWLcsxLtrRs6uNF1VrpB+4n/55QU7oxA1iVBO6IFu4qgsF12J
TavnJ5MLaETlggXY+zDef9syTPXoQctpzcaNVDmedwo1SiL03uMoblOvWpMR/Y0j
6rm7IgrMWUDXDPvoPGjMl2q1iTeyHkMZEyUJ8SKsaHh4jV9wp9KmC8C+9CwMukL7
vM5w8cgvJoAwsp3Fn59AxWthN3XJYcnMfStkIuWgR7U2r+a210W6vnUxU4oN0PmM
cursYPyeV0NX/KQeUeNMwGTFB6QHS/anRaGQewijkrYYoTNtfllxIu9XYmiBERQ/
qPDlGRlOgVTd9xUfHFkzB52c70E=
=92oX
-----END PGP PUBLIC KEY BLOCK-----
113 changes: 113 additions & 0 deletions x-pack/elastic-agent/dev-tools/cmd/buildpgp/build_pgp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions x-pack/elastic-agent/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

Expand All @@ -40,6 +41,7 @@ const (
buildDir = "build"
metaDir = "_meta"
snapshotEnv = "SNAPSHOT"
devEnv = "DEV"
configFile = "elastic-agent.yml"
agentDropPath = "AGENT_DROP_PATH"
)
Expand Down Expand Up @@ -345,7 +347,7 @@ func commitID() string {

// Update is an alias for executing control protocol, configs, and specs.
func Update() {
mg.SerialDeps(Config, BuildSpec, BuildFleetCfg)
mg.SerialDeps(Config, BuildSpec, BuildPGP, BuildFleetCfg)
}

// CrossBuild cross-builds the beat for all target platforms.
Expand All @@ -370,7 +372,7 @@ func ControlProto() error {

// BuildSpec make sure that all the suppported program spec are built into the binary.
func BuildSpec() error {
// go run x-pack/agent/dev-tools/cmd/buildspec/buildspec.go --in x-pack/agent/spec/*.yml --out x-pack/agent/pkg/agent/program/supported.go
// go run x-pack/elastic-agent/dev-tools/cmd/buildspec/buildspec.go --in x-pack/agent/spec/*.yml --out x-pack/elastic-agent/pkg/agent/program/supported.go
goF := filepath.Join("dev-tools", "cmd", "buildspec", "buildspec.go")
in := filepath.Join("spec", "*.yml")
out := filepath.Join("pkg", "agent", "program", "supported.go")
Expand All @@ -379,6 +381,16 @@ func BuildSpec() error {
return RunGo("run", goF, "--in", in, "--out", out)
}

func BuildPGP() error {
// go run x-pack/elastic-agent/dev-tools/cmd/buildpgp/build_pgp.go --in x-pack/agent/spec/GPG-KEY-elasticsearch --out x-pack/elastic-agent/pkg/release/pgp.go
goF := filepath.Join("dev-tools", "cmd", "buildpgp", "build_pgp.go")
in := "GPG-KEY-elasticsearch"
out := filepath.Join("pkg", "release", "pgp.go")

fmt.Printf(">> BuildPGP from %s to %s\n", in, out)
return RunGo("run", goF, "--in", in, "--out", out)
}

func configYML() error {
return devtools.Config(devtools.AllConfigTypes, ConfigFileParams(), ".")
}
Expand Down Expand Up @@ -620,6 +632,12 @@ func buildVars() map[string]string {
isSnapshot, _ := os.LookupEnv(snapshotEnv)
vars["github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release.snapshot"] = isSnapshot

if isDevFlag, devFound := os.LookupEnv(devEnv); devFound {
if isDev, err := strconv.ParseBool(isDevFlag); err == nil && isDev {
vars["github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release.allowEmptyPgp"] = "true"
}
}

return vars
}

Expand Down
4 changes: 3 additions & 1 deletion x-pack/elastic-agent/pkg/agent/application/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/monitoring"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/server"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/state"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release"
)

type operatorStream struct {
Expand Down Expand Up @@ -56,7 +57,8 @@ func streamFactory(ctx context.Context, cfg *configuration.SettingsConfig, srv *

func newOperator(ctx context.Context, log *logger.Logger, id routingKey, config *configuration.SettingsConfig, srv *server.Server, r state.Reporter, m monitoring.Monitor) (*operation.Operator, error) {
fetcher := downloader.NewDownloader(log, config.DownloadConfig)
verifier, err := downloader.NewVerifier(log, config.DownloadConfig)
allowEmptyPgp, pgp := release.PGP()
verifier, err := downloader.NewVerifier(log, config.DownloadConfig, allowEmptyPgp, pgp)
if err != nil {
return nil, errors.New(err, "initiating verifier")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors"
downloader "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/artifact/download/localremote"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release"
)

func (u *Upgrader) downloadArtifact(ctx context.Context, version, sourceURI string) (string, error) {
Expand All @@ -18,7 +19,8 @@ func (u *Upgrader) downloadArtifact(ctx context.Context, version, sourceURI stri
settings.SourceURI = sourceURI
}

verifier, err := downloader.NewVerifier(u.log, &settings)
allowEmptyPgp, pgp := release.PGP()
verifier, err := downloader.NewVerifier(u.log, &settings, allowEmptyPgp, pgp)
if err != nil {
return "", errors.New(err, "initiating verifier")
}
Expand Down
6 changes: 0 additions & 6 deletions x-pack/elastic-agent/pkg/artifact/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ type Config struct {
// Timeout: timeout for downloading package
Timeout time.Duration `json:"timeout" config:"timeout"`

// PgpFile: filepath to a public key used for verifying downloaded artifacts
// if not file is present elastic-agent will try to load public key from elastic.co website.
PgpFile string `json:"pgpfile" config:"pgpfile"`

// InstallPath: path to the directory containing installed packages
InstallPath string `yaml:"installPath" config:"install_path"`

Expand All @@ -48,12 +44,10 @@ type Config struct {
// DefaultConfig creates a config with pre-set default values.
func DefaultConfig() *Config {
homePath := paths.Home()
dataPath := paths.Data()
return &Config{
SourceURI: "https://artifacts.elastic.co/downloads/",
TargetDirectory: filepath.Join(homePath, "downloads"),
Timeout: 30 * time.Second,
PgpFile: filepath.Join(dataPath, "elastic.pgp"),
InstallPath: filepath.Join(homePath, "install"),
}
}
Expand Down
Loading

0 comments on commit aebddba

Please sign in to comment.