Skip to content

Commit 6a600dc

Browse files
authored
Enable the Cloud Security Posture Kibana plugin (#767)
* add to kibana.yml * remove newline * add 80 config file * fix license * use symlinks * Revert "use symlinks" This reverts commit 1faa0bd. * virtual files * use semver * fix static * retrigger stuck CI * add configuration variant map * use old semver * fix static check
1 parent 317f26f commit 6a600dc

File tree

6 files changed

+167
-5
lines changed

6 files changed

+167
-5
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
server.name: kibana
2+
server.host: "0.0.0.0"
3+
4+
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
5+
elasticsearch.serviceAccountToken: "AAEAAWVsYXN0aWMva2liYW5hL2VsYXN0aWMtcGFja2FnZS1raWJhbmEtdG9rZW46b2x4b051SWNRa0tYMHdXazdLWmFBdw"
6+
7+
monitoring.ui.container.elasticsearch.enabled: true
8+
9+
xpack.fleet.registryUrl: "http://package-registry:8080"
10+
xpack.fleet.agents.enabled: true
11+
xpack.fleet.agents.elasticsearch.hosts: ["http://elasticsearch:9200"]
12+
xpack.fleet.agents.fleet_server.hosts: ["http://fleet-server:8220"]
13+
14+
xpack.encryptedSavedObjects.encryptionKey: "12345678901234567890123456789012"
15+
16+
xpack.fleet.packages:
17+
- name: system
18+
version: latest
19+
- name: elastic_agent
20+
version: latest
21+
- name: fleet_server
22+
version: latest
23+
xpack.fleet.agentPolicies:
24+
- name: Elastic-Agent (elastic-package)
25+
id: elastic-agent-managed-ep
26+
is_default: true
27+
is_managed: false
28+
namespace: default
29+
monitoring_enabled:
30+
- logs
31+
- metrics
32+
package_policies:
33+
- name: system-1
34+
id: default-system
35+
package:
36+
name: system
37+
- name: Fleet Server (elastic-package)
38+
id: fleet-server-policy
39+
is_default_fleet_server: true
40+
is_managed: false
41+
namespace: default
42+
package_policies:
43+
- name: fleet_server-1
44+
id: default-fleet-server
45+
package:
46+
name: fleet_server

internal/profile/_static/kibana_config_8x.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ xpack.fleet.agents.fleet_server.hosts: ["http://fleet-server:8220"]
1313

1414
xpack.encryptedSavedObjects.encryptionKey: "12345678901234567890123456789012"
1515

16+
xpack.cloudSecurityPosture.enabled: true
17+
1618
xpack.fleet.packages:
1719
- name: system
1820
version: latest

internal/profile/profile.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ type configFile string
3838
var managedProfileFiles = map[configFile]NewConfig{
3939
ElasticAgentDefaultEnvFile: newElasticAgentDefaultEnv,
4040
ElasticAgent8xEnvFile: newElasticAgent8xEnv,
41+
ElasticAgent80EnvFile: newElasticAgent80Env,
4142
ElasticsearchConfigDefaultFile: newElasticsearchConfigDefault,
4243
ElasticsearchConfig8xFile: newElasticsearchConfig8x,
44+
ElasticsearchConfig80File: newElasticsearchConfig80,
4345
KibanaConfigDefaultFile: newKibanaConfigDefault,
4446
KibanaConfig8xFile: newKibanaConfig8x,
47+
KibanaConfig80File: newKibanaConfig80,
4548
PackageRegistryDockerfileFile: newPackageRegistryDockerfile,
4649
PackageRegistryConfigFile: newPackageRegistryConfig,
4750
SnapshotFile: newSnapshotFile,

internal/profile/static.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ func newKibanaConfig8x(_ string, profilePath string) (*simpleFile, error) {
5353
}, nil
5454
}
5555

56+
// KibanaConfig80File is the Kibana config file for 8.0 stack family (8.0 to 8.1)
57+
const KibanaConfig80File configFile = "kibana.config.80.yml"
58+
59+
//go:embed _static/kibana_config_80.yml
60+
var kibanaConfig80Yml string
61+
62+
func newKibanaConfig80(_ string, profilePath string) (*simpleFile, error) {
63+
return &simpleFile{
64+
name: string(KibanaConfig80File),
65+
path: filepath.Join(profilePath, profileStackPath, string(KibanaConfig80File)),
66+
body: kibanaConfig80Yml,
67+
}, nil
68+
}
69+
5670
// ElasticsearchConfigDefaultFile is the default Elasticsearch config file
5771
const ElasticsearchConfigDefaultFile configFile = "elasticsearch.config.default.yml"
5872

@@ -81,6 +95,18 @@ func newElasticsearchConfig8x(_ string, profilePath string) (*simpleFile, error)
8195
}, nil
8296
}
8397

98+
// ElasticsearchConfig80File is the Elasticsearch virtual config file name for 8.0 stack family (8.0 to 8.1)
99+
// This file does not exist in the source code, since it's identical to the 8x config file.
100+
const ElasticsearchConfig80File configFile = "elasticsearch.config.80.yml"
101+
102+
func newElasticsearchConfig80(_ string, profilePath string) (*simpleFile, error) {
103+
return &simpleFile{
104+
name: string(ElasticsearchConfig80File),
105+
path: filepath.Join(profilePath, profileStackPath, string(ElasticsearchConfig80File)),
106+
body: elasticsearchConfig8xYml,
107+
}, nil
108+
}
109+
84110
// PackageRegistryConfigFile is the config file for the Elastic Package registry
85111
const PackageRegistryConfigFile configFile = "package-registry.config.yml"
86112

@@ -117,6 +143,18 @@ func newPackageRegistryDockerfile(_ string, profilePath string) (*simpleFile, er
117143
}, nil
118144
}
119145

146+
// ElasticAgent80EnvFile is the .env for the 8.0 stack.
147+
// This file does not exist in the source code, since it's identical to the 8x env file.
148+
const ElasticAgent80EnvFile configFile = "elastic-agent.80.env"
149+
150+
func newElasticAgent80Env(_ string, profilePath string) (*simpleFile, error) {
151+
return &simpleFile{
152+
name: string(ElasticAgent80EnvFile),
153+
path: filepath.Join(profilePath, profileStackPath, string(ElasticAgent80EnvFile)),
154+
body: elasticAgent8xEnv,
155+
}, nil
156+
}
157+
120158
// ElasticAgent8xEnvFile is the .env for the 8x stack.
121159
const ElasticAgent8xEnvFile configFile = "elastic-agent.8x.env"
122160

internal/stack/variants.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,40 @@ package stack
66

77
import (
88
"fmt"
9-
"strings"
9+
10+
"github.com/Masterminds/semver"
1011
)
1112

13+
// configurationVariantMap is a map of version constraints and their matching configuration variant.
14+
// This map is used to deploy different versions of the Elastic stack with matching configurations.
15+
var configurationVariantMap = map[string]string{
16+
"8.0-0 - 8.1.x-x": "80",
17+
"^8.2-0": "8x",
18+
}
19+
1220
// stackVariantAsEnv function returns a stack variant based on the given stack version.
13-
// We identified two variants:
21+
// We identified three variants:
1422
// * default, covers all of 7.x branches
15-
// * 8x, supports different configuration options in Kibana
23+
// * 80, covers stack versions 8.0.0 to 8.1.x
24+
// * 8x, supports different configuration options in Kibana, covers stack versions 8.2.0+
1625
func stackVariantAsEnv(version string) string {
1726
return fmt.Sprintf("STACK_VERSION_VARIANT=%s", selectStackVersion(version))
1827
}
1928

2029
func selectStackVersion(version string) string {
21-
if strings.HasPrefix(version, "8.") {
22-
return "8x"
30+
if v, err := semver.NewVersion(version); err == nil {
31+
for constraint, variant := range configurationVariantMap {
32+
if checkVersion(v, constraint) {
33+
return variant
34+
}
35+
}
2336
}
2437
return "default"
2538
}
39+
40+
func checkVersion(v *semver.Version, constraint string) bool {
41+
if constraint, err := semver.NewConstraint(constraint); err == nil {
42+
return constraint.Check(v)
43+
}
44+
return false
45+
}

internal/stack/variants_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License;
3+
// you may not use this file except in compliance with the Elastic License.
4+
5+
package stack
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
var tests = []struct {
14+
version string
15+
variant string
16+
}{
17+
{"", "default"},
18+
{"7", "default"},
19+
{"7.0.0", "default"},
20+
{"7.14.99-SNAPSHOT", "default"},
21+
{"8", "80"},
22+
{"8-0", "80"},
23+
{"8.0.0-alpha", "80"},
24+
{"8.0.0", "80"},
25+
{"8.0.33", "80"},
26+
{"8.0.33-beta", "80"},
27+
{"8.1-0", "80"},
28+
{"8.1", "80"},
29+
{"8.1-alpha", "80"},
30+
{"8.1.0-alpha", "80"},
31+
{"8.1.0", "80"},
32+
{"8.1.58", "80"},
33+
{"8.1.99-beta", "80"},
34+
{"8.1.999-SNAPSHOT", "80"},
35+
{"8.2-0", "8x"},
36+
{"8.2", "8x"},
37+
{"8.2.0-alpha", "8x"},
38+
{"8.2.0", "8x"},
39+
{"8.2.58", "8x"},
40+
{"8.2.99-gamma", "8x"},
41+
{"8.2.777-SNAPSHOT+arm64", "8x"},
42+
{"8.5", "8x"},
43+
{"9", "default"},
44+
}
45+
46+
func TestSelectStackVersion(t *testing.T) {
47+
for _, tt := range tests {
48+
t.Run(tt.version, func(t *testing.T) {
49+
selected := selectStackVersion(tt.version)
50+
assert.Equal(t, tt.variant, selected)
51+
})
52+
}
53+
}

0 commit comments

Comments
 (0)