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

[8.6](forwardport) Add extra protection against accessing null fields to 8.5 migration (#1921) #1926

Merged
merged 5 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/fleet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func initLogger(cfg *config.Config, version, commit string) (*logger.Logger, err
Str("exe", os.Args[0]).
Strs("args", os.Args[1:]).
Msg("Boot fleet-server")
log.Debug().Strs("env", os.Environ()).Msg("environment")
Copy link
Contributor

Choose a reason for hiding this comment

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

I've merged my refactor. this is now in internal/pkg/server/fleet.go

log.Debug().Strs("env", os.Environ()).Msg("environment variables")

return l, err
}
Expand Down
16 changes: 13 additions & 3 deletions internal/pkg/dl/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ func migrate(ctx context.Context, bulker bulk.Bulk, fn migrationBodyFn) (int, er
for {
name, index, body, err := fn()
if err != nil {
return updatedDocs, fmt.Errorf(": %w", err)
return updatedDocs,
fmt.Errorf("failed to prepare request for migration %s: %w",
name, err)
}

resp, err := applyMigration(ctx, name, index, bulker, body)
if err != nil {
log.Err(err).
Bytes("http.request.body.content", body).
Msgf("migration %s failed", name)
return updatedDocs, fmt.Errorf("failed to apply migration %q: %w",
name, err)
}
Expand Down Expand Up @@ -239,7 +244,9 @@ map.put("id", ctx._source.default_api_key_id);

// Make current API key empty, so fleet-server will generate a new one
// Add current API jey to be retired
ctx._source['` + fieldOutputs + `']['default'].to_retire_api_key_ids.add(map);
if (ctx._source['` + fieldOutputs + `']['default'].to_retire_api_key_ids != null) {
ctx._source['` + fieldOutputs + `']['default'].to_retire_api_key_ids.add(map);
}
ctx._source['` + fieldOutputs + `']['default'].api_key="";
ctx._source['` + fieldOutputs + `']['default'].api_key_id="";
ctx._source['` + fieldOutputs + `']['default'].permissions_hash=ctx._source.policy_output_permissions_hash;
Expand Down Expand Up @@ -273,10 +280,13 @@ func migratePolicyCoordinatorIdx() (string, string, []byte, error) {

query := dsl.NewRoot()
query.Query().MatchAll()
query.Param("script", `ctx._source.coordinator_idx++;`)
painless := `ctx._source.coordinator_idx++;`
query.Param("script", painless)

body, err := query.MarshalJSON()
if err != nil {
log.Debug().Str("painlessScript", painless).
Msgf("%s: failed painless script", migrationName)
return migrationName, FleetPolicies, nil, fmt.Errorf("could not marshal ES query: %w", err)
}

Expand Down