Skip to content

Commit d11abd3

Browse files
Add support for bundling Cloudbeat in Agent 9.x within CI workflows and installation scripts. (#3029)
* modify wf and scripts to support cloudbeat install * update script * update wf
1 parent 8ec9f09 commit d11abd3

15 files changed

+87
-32
lines changed

.ci/scripts/run_agent.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,11 @@ done
2525

2626
cd "elastic-agent-${ELASTIC_AGENT_VERSION}-linux-x86_64" || exit
2727

28+
install_servers_opt=""
29+
major_version=$(echo "${ELASTIC_AGENT_VERSION}" | cut -d'.' -f1)
30+
if [ "$major_version" -ge 9 ]; then
31+
install_servers_opt="--install-servers"
32+
fi
33+
2834
# Install the Elastic Agent
29-
sudo ./elastic-agent install -f
35+
sudo ./elastic-agent install -f ${install_servers_opt:+$install_servers_opt}

.github/workflows/test-environment.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,16 @@ jobs:
191191
run: |
192192
# Extract the stack version
193193
stack_version="${{ inputs.elk-stack-version }}"
194-
195194
echo "TF_VAR_stack_version=$stack_version" >> $GITHUB_ENV
196195
echo "STACK_VERSION=$stack_version" >> $GITHUB_ENV
196+
echo "AGENT_VERSION=$stack_version" >> $GITHUB_ENV
197197
198198
# Handle BC versions with commit hash (e.g. 8.11.0-1234567890)
199199
if [[ $stack_version =~ -[a-f0-9]+ ]]; then
200200
cleaned_version=$(echo $stack_version | awk -F"-" '{print $1}')
201+
# handling major and minor versions for agent version
202+
agent_version=$(echo "$stack_version" | awk -F"-" '{if (NF>2) print $1"-"$2; else print $1}')
203+
echo "AGENT_VERSION=$agent_version" >> $GITHUB_ENV
201204
202205
# Versions with commit hash are not allowed for EC regular deployments and should be modified
203206
# EC module resource:
@@ -392,6 +395,7 @@ jobs:
392395
es-user: ${{ steps.elk-stack.outputs.es-user }}
393396
es-password: ${{ steps.elk-stack.outputs.es-password }}
394397
kibana-url: ${{ steps.elk-stack.outputs.kibana-url }}
398+
docker-image-override: ${{ env.DOCKER_IMAGE_OVERRIDE }}
395399
serverless-mode: "${{ env.TF_VAR_serverless_mode }}"
396400
tag-project: ${{ github.actor }}
397401
tag-owner: ${{ github.actor }}

tests/fleet_api/utils.py

+9
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,12 @@ def add_tags(tags: str, yaml_content: str):
346346
modified_content = output_stream.getvalue()
347347

348348
return modified_content
349+
350+
351+
def get_install_servers_option(stack_version: str):
352+
"""
353+
Returns "--install-servers" if stack_version starts with "9.", otherwise returns None.
354+
"""
355+
if stack_version.startswith("9."):
356+
return "--install-servers"
357+
return None

tests/integrations_setup/configuration_fleet.py

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
elk_config.password = os.getenv("ES_PASSWORD", "NA")
3636
elk_config.kibana_url = os.getenv("KIBANA_URL", "")
3737
elk_config.stack_version = os.getenv("STACK_VERSION", "NA")
38+
elk_config.agent_version = os.getenv("AGENT_VERSION", "")
3839
elk_config.auth = (elk_config.user, elk_config.password)
3940

4041
kspm_config = Munch()

tests/integrations_setup/data/cspm-linux.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
curl -L -O {{ artifacts_url }}/elastic-agent-{{ agent_version }}-linux-x86_64.tar.gz
44
tar xzvf elastic-agent-{{ agent_version }}-linux-x86_64.tar.gz
55
cd elastic-agent-{{ agent_version }}-linux-x86_64
6-
sudo ./elastic-agent install -f --url={{ fleet_url }} --enrollment-token={{ enrollment_token }}
6+
sudo ./elastic-agent install -f{% if install_servers %} {{ install_servers }}{% endif %} --url={{ fleet_url }} --enrollment-token={{ enrollment_token }}

tests/integrations_setup/install_aws_asset_inventory_integration.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
get_package_version,
2121
)
2222
from fleet_api.package_policy_api import create_integration
23-
from fleet_api.utils import render_template
23+
from fleet_api.utils import get_install_servers_option, render_template
2424
from loguru import logger
2525
from munch import Munch
2626
from package_policy import (
@@ -97,8 +97,11 @@
9797
)
9898
manifest_params.fleet_url = get_fleet_server_host(cfg=cnfg.elk_config)
9999
manifest_params.file_path = Path(__file__).parent / "aws-asset-inventory.sh"
100-
manifest_params.agent_version = cnfg.elk_config.stack_version
101-
manifest_params.artifacts_url = get_artifact_server(cnfg.elk_config.stack_version)
100+
manifest_params.agent_version = cnfg.elk_config.agent_version
101+
manifest_params.artifacts_url = get_artifact_server(cnfg.elk_config.agent_version)
102+
install_servers = get_install_servers_option(cnfg.elk_config.agent_version)
103+
if install_servers:
104+
manifest_params.install_servers = install_servers
102105

103106
# Render the template and get the replaced content
104107
rendered_content = render_template(script_template, manifest_params.toDict())

tests/integrations_setup/install_az_activity_logs_integration.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
get_package_version,
1919
)
2020
from fleet_api.package_policy_api import create_integration
21-
from fleet_api.utils import read_json, render_template, update_key_value
21+
from fleet_api.utils import (
22+
get_install_servers_option,
23+
read_json,
24+
render_template,
25+
update_key_value,
26+
)
2227
from loguru import logger
2328
from munch import Munch
2429
from package_policy import SIMPLIFIED_AGENT_POLICY, generate_random_name
@@ -79,8 +84,11 @@
7984

8085
manifest_params.fleet_url = get_fleet_server_host(cfg=cnfg.elk_config)
8186
manifest_params.file_path = Path(__file__).parent / "az_activity_logs.sh"
82-
manifest_params.agent_version = cnfg.elk_config.stack_version
83-
manifest_params.artifacts_url = get_artifact_server(cnfg.elk_config.stack_version)
87+
manifest_params.agent_version = cnfg.elk_config.agent_version
88+
manifest_params.artifacts_url = get_artifact_server(cnfg.elk_config.agent_version)
89+
install_servers = get_install_servers_option(cnfg.elk_config.agent_version)
90+
if install_servers:
91+
manifest_params.install_servers = install_servers
8492

8593
# Render the template and get the replaced content
8694
rendered_content = render_template(agent_launcher_template, manifest_params.toDict())

tests/integrations_setup/install_azure_asset_inventory_integration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@
124124
"value": get_fleet_server_host(cfg=cnfg.elk_config),
125125
}
126126
azure_arm_parameters["parameters"]["ElasticArtifactServer"] = {
127-
"value": get_artifact_server(cnfg.elk_config.stack_version),
127+
"value": get_artifact_server(cnfg.elk_config.agent_version),
128128
}
129129
azure_arm_parameters["parameters"]["ElasticAgentVersion"] = {
130-
"value": cnfg.elk_config.stack_version,
130+
"value": cnfg.elk_config.agent_version,
131131
}
132132

133133
with open(path_arm_parameters, "w") as file:

tests/integrations_setup/install_cloudtrail_integration.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
get_package_version,
1919
)
2020
from fleet_api.package_policy_api import create_cspm_integration
21-
from fleet_api.utils import read_json, render_template, update_key_value
21+
from fleet_api.utils import (
22+
get_install_servers_option,
23+
read_json,
24+
render_template,
25+
update_key_value,
26+
)
2227
from loguru import logger
2328
from munch import Munch
2429
from package_policy import SIMPLIFIED_AGENT_POLICY, generate_random_name
@@ -77,9 +82,11 @@
7782

7883
manifest_params.fleet_url = get_fleet_server_host(cfg=cnfg.elk_config)
7984
manifest_params.file_path = Path(__file__).parent / "cloudtrail.sh"
80-
manifest_params.agent_version = cnfg.elk_config.stack_version
81-
manifest_params.artifacts_url = get_artifact_server(cnfg.elk_config.stack_version)
82-
85+
manifest_params.agent_version = cnfg.elk_config.agent_version
86+
manifest_params.artifacts_url = get_artifact_server(cnfg.elk_config.agent_version)
87+
install_servers = get_install_servers_option(cnfg.elk_config.agent_version)
88+
if install_servers:
89+
manifest_params.install_servers = install_servers
8390
# Render the template and get the replaced content
8491
rendered_content = render_template(cloudtrail_template, manifest_params.toDict())
8592

tests/integrations_setup/install_cnvm_integration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@
101101
)
102102

103103
cloudformation_params.FLEET_URL = get_fleet_server_host(cfg=cnfg.elk_config)
104-
cloudformation_params.ELASTIC_AGENT_VERSION = cnfg.elk_config.stack_version
105-
cloudformation_params.ELASTIC_ARTIFACT_SERVER = get_artifact_server(cnfg.elk_config.stack_version)
104+
cloudformation_params.ELASTIC_AGENT_VERSION = cnfg.elk_config.agent_version
105+
cloudformation_params.ELASTIC_ARTIFACT_SERVER = get_artifact_server(cnfg.elk_config.agent_version)
106106

107107
with open(cnvm_cloudformation_config, "w") as file:
108108
json.dump(cloudformation_params, file)

tests/integrations_setup/install_cspm_azure_integration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@
126126
}
127127

128128
azure_arm_parameters["parameters"]["ElasticArtifactServer"] = {
129-
"value": get_artifact_server(cnfg.elk_config.stack_version),
129+
"value": get_artifact_server(cnfg.elk_config.agent_version),
130130
}
131131

132132
azure_arm_parameters["parameters"]["ElasticAgentVersion"] = {
133-
"value": cnfg.elk_config.stack_version,
133+
"value": cnfg.elk_config.agent_version,
134134
}
135135

136136
if version.parse(package_version) < version.parse("1.7"):

tests/integrations_setup/install_cspm_gcp_integration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@
123123
)
124124

125125
deploy_manager_params.FLEET_URL = get_fleet_server_host(cfg=cnfg.elk_config)
126-
deploy_manager_params.ELASTIC_ARTIFACT_SERVER = get_artifact_server(cnfg.elk_config.stack_version)
126+
deploy_manager_params.ELASTIC_ARTIFACT_SERVER = get_artifact_server(cnfg.elk_config.agent_version)
127127
deploy_manager_params.DEPLOYMENT_NAME = cnfg.gcp_dm_config.deployment_name
128128
deploy_manager_params.ZONE = cnfg.gcp_dm_config.zone
129129
deploy_manager_params.ALLOW_SSH = cnfg.gcp_dm_config.allow_ssh
130-
deploy_manager_params.STACK_VERSION = cnfg.elk_config.stack_version
130+
deploy_manager_params.STACK_VERSION = cnfg.elk_config.agent_version
131131

132132
with open(cspm_gcp_deployment_manager_config, "w") as file:
133133
json.dump(deploy_manager_params, file)

tests/integrations_setup/install_cspm_integration.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
update_package_version,
2121
)
2222
from fleet_api.package_policy_api import create_cspm_integration
23-
from fleet_api.utils import render_template
23+
from fleet_api.utils import get_install_servers_option, render_template
2424
from loguru import logger
2525
from munch import Munch
2626
from package_policy import (
@@ -112,8 +112,11 @@
112112

113113
manifest_params.fleet_url = get_fleet_server_host(cfg=cnfg.elk_config)
114114
manifest_params.file_path = Path(__file__).parent / "cspm.sh"
115-
manifest_params.agent_version = cnfg.elk_config.stack_version
116-
manifest_params.artifacts_url = get_artifact_server(cnfg.elk_config.stack_version)
115+
manifest_params.agent_version = cnfg.elk_config.agent_version
116+
manifest_params.artifacts_url = get_artifact_server(cnfg.elk_config.agent_version)
117+
install_servers = get_install_servers_option(cnfg.elk_config.agent_version)
118+
if install_servers:
119+
manifest_params.install_servers = install_servers
117120

118121
# Render the template and get the replaced content
119122
rendered_content = render_template(cspm_template, manifest_params.toDict())

tests/integrations_setup/install_gcp_audit_logs_integration.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
get_package_version,
1919
)
2020
from fleet_api.package_policy_api import create_integration
21-
from fleet_api.utils import read_json, render_template, update_key_value
21+
from fleet_api.utils import (
22+
get_install_servers_option,
23+
read_json,
24+
render_template,
25+
update_key_value,
26+
)
2227
from loguru import logger
2328
from munch import Munch
2429
from package_policy import SIMPLIFIED_AGENT_POLICY, generate_random_name
@@ -85,9 +90,11 @@
8590

8691
manifest_params.fleet_url = get_fleet_server_host(cfg=cnfg.elk_config)
8792
manifest_params.file_path = Path(__file__).parent / "gcp_audit_logs.sh"
88-
manifest_params.agent_version = cnfg.elk_config.stack_version
89-
manifest_params.artifacts_url = get_artifact_server(cnfg.elk_config.stack_version)
90-
93+
manifest_params.agent_version = cnfg.elk_config.agent_version
94+
manifest_params.artifacts_url = get_artifact_server(cnfg.elk_config.agent_version)
95+
install_servers = get_install_servers_option(cnfg.elk_config.agent_version)
96+
if install_servers:
97+
manifest_params.install_servers = install_servers
9198
# Render the template and get the replaced content
9299
rendered_content = render_template(agent_launcher_template, manifest_params.toDict())
93100

tests/integrations_setup/install_wiz_integration.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
get_package_version,
1919
)
2020
from fleet_api.package_policy_api import create_integration
21-
from fleet_api.utils import read_json, render_template, update_key_value
21+
from fleet_api.utils import (
22+
get_install_servers_option,
23+
read_json,
24+
render_template,
25+
update_key_value,
26+
)
2227
from loguru import logger
2328
from munch import Munch
2429
from package_policy import SIMPLIFIED_AGENT_POLICY, generate_random_name
@@ -86,9 +91,11 @@
8691

8792
manifest_params.fleet_url = get_fleet_server_host(cfg=cnfg.elk_config)
8893
manifest_params.file_path = Path(__file__).parent / "wiz.sh"
89-
manifest_params.agent_version = cnfg.elk_config.stack_version
90-
manifest_params.artifacts_url = get_artifact_server(cnfg.elk_config.stack_version)
91-
94+
manifest_params.agent_version = cnfg.elk_config.agent_version
95+
manifest_params.artifacts_url = get_artifact_server(cnfg.elk_config.agent_version)
96+
install_servers = get_install_servers_option(cnfg.elk_config.agent_version)
97+
if install_servers:
98+
manifest_params.install_servers = install_servers
9299
# Render the template and get the replaced content
93100
rendered_content = render_template(agent_launcher_template, manifest_params.toDict())
94101

0 commit comments

Comments
 (0)