Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
chore: use preconfigured policy for fleet-server's default policy (#2111
Browse files Browse the repository at this point in the history
)

(cherry picked from commit 5ed1aff)

# Conflicts:
#	e2e/_suites/fleet/fleet.go
  • Loading branch information
mdelapenya authored and mergify-bot committed Feb 8, 2022
1 parent 7f02493 commit 743ca3f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cli/config/compose/profiles/fleet/default/kibana.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ xpack.fleet.agents.fleet_server.hosts: ["http://fleet-server:8220"]

xpack.encryptedSavedObjects.encryptionKey: "12345678901234567890123456789012"
xpack.fleet.agents.tlsCheckDisabled: true

xpack.fleet.packages:
- name: fleet_server
version: latest
xpack.fleet.agentPolicies:
- name: Fleet Server policy
id: fleet-server-policy
description: Fleet server policy
namespace: default
package_policies:
- name: Fleet Server
package:
name: fleet_server
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ xpack.fleet.outputs:
type: "elasticsearch"
id: "output-123"
hosts: ["http://elasticsearch:9200"]
xpack.fleet.packages:
- name: fleet_server
version: latest
xpack.fleet.agentPolicies:
- name: Test preconfigured policy
id: "test-preconfigured"
Expand All @@ -32,3 +35,11 @@ xpack.fleet.agentPolicies:
- package:
name: system
name: sytem-1
- name: Fleet Server policy
id: fleet-server-policy
description: Fleet server policy
namespace: default
package_policies:
- name: Fleet Server
package:
name: fleet_server
46 changes: 46 additions & 0 deletions e2e/_suites/fleet/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,52 @@ func bootstrapFleet(ctx context.Context, env map[string]string) error {
}).Fatal("Fleet could not be recreated")
}

<<<<<<< HEAD
=======
// these values comes from the kibana.config.yml file at Fleet's profile dir
fleetServicePolicy := kibana.Policy{
ID: "fleet-server-policy",
Name: "Fleet Server Policy",
Description: "Fleet Server policy",
}

log.WithFields(log.Fields{
"id": fleetServicePolicy.ID,
"name": fleetServicePolicy.Name,
"description": fleetServicePolicy.Description,
}).Info("Fleet Server Policy retrieved")

serviceToken, err := elasticsearch.GetAPIToken(ctx)
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Fatal("Could not get API Token from Elasticsearch")
}

fleetServerEnv := make(map[string]string)
for k, v := range env {
fleetServerEnv[k] = v
}
fleetServerEnv["fleetServerMode"] = "1"
fleetServerEnv["fleetServerPort"] = "8220"
fleetServerEnv["fleetInsecure"] = "1"
fleetServerEnv["fleetServerServiceToken"] = serviceToken.AccessToken
fleetServerEnv["fleetServerPolicyId"] = fleetServicePolicy.ID

fleetServerSrv := deploy.ServiceRequest{
Name: common.ElasticAgentServiceName,
Flavour: "fleet-server",
}

err = deployer.Add(ctx, deploy.NewServiceRequest(common.FleetProfileName), []deploy.ServiceRequest{fleetServerSrv}, fleetServerEnv)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"env": fleetServerEnv,
}).Fatal("Fleet Server could not be started")
}

>>>>>>> 5ed1aff (chore: use preconfigured policy for fleet-server's default policy (#2111))
err = kibanaClient.WaitForFleet(ctx)
if err != nil {
log.WithFields(log.Fields{
Expand Down
1 change: 1 addition & 0 deletions internal/kibana/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Policy struct {
}

// GetDefaultPolicy gets the default policy or optionally the default fleet policy
// deprecated: will be removed in upcoming releases
func (c *Client) GetDefaultPolicy(ctx context.Context, fleetServer bool) (Policy, error) {
span, _ := apm.StartSpanOptions(ctx, "Getting default policy", "fleet.package-policies.get-default", apm.SpanOptions{
Parent: apm.SpanFromContext(ctx).TraceContext(),
Expand Down

0 comments on commit 743ca3f

Please sign in to comment.