Skip to content

Commit 5be7ff1

Browse files
POC - Adding CIS and CDR integrations to an existing deployment (#2953)
* add new wf * modify wfs to support cis and cdr install * update wf * update wfs * add stack version * update action condition * update documentation
1 parent 72d3151 commit 5be7ff1

File tree

3 files changed

+157
-13
lines changed

3 files changed

+157
-13
lines changed
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Install Integrations
2+
run-name: Install integrations by @${{ github.actor }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
deployment-name:
8+
type: string
9+
description: |
10+
Name with letters, numbers, hyphens; start with a letter. Max 20 chars. e.g., 'my-env-123'
11+
required: true
12+
stack-version:
13+
type: string
14+
description: "The version of the stack to deploy"
15+
required: true
16+
kibana-url:
17+
type: string
18+
description: "The Kibana URL to install the integrations"
19+
required: true
20+
kibana-username:
21+
type: string
22+
description: "The Kibana username to install the integrations"
23+
required: true
24+
kibana-password:
25+
type: string
26+
description: "The Kibana password to install the integrations"
27+
required: true
28+
infra-type:
29+
description: 'Choose an option (all, cdr, cis)'
30+
required: true
31+
type: choice
32+
options:
33+
- all
34+
- cdr
35+
- cis
36+
docker-image-override:
37+
required: false
38+
description: "Provide the full Docker image path to override the default image (e.g. for testing BC/SNAPSHOT)"
39+
type: string
40+
41+
jobs:
42+
naming:
43+
runs-on: ubuntu-latest
44+
outputs:
45+
es-password: ${{ steps.password.outputs.kbn-password }}
46+
steps:
47+
- name: Mask Sensitive Data
48+
id: password
49+
env:
50+
SECRET: ${{ secrets.GPG_PASSPHRASE }}
51+
run: |
52+
kbn_password=$(jq -r '.inputs["kibana-password"]' $GITHUB_EVENT_PATH)
53+
echo "::add-mask::$kbn_password"
54+
kbn_password_encrypted=$(gpg --symmetric --batch --passphrase "$SECRET" --output - <(echo "$kbn_password") | base64 -w0)
55+
echo "kbn-password=$kbn_password_encrypted" >> $GITHUB_OUTPUT
56+
57+
deploy:
58+
needs: naming
59+
uses: ./.github/workflows/test-environment.yml
60+
secrets: inherit
61+
# Required for the 'Deploy' job in the 'test-environment.yml' to authenticate with Google Cloud (gcloud).
62+
permissions:
63+
contents: 'read'
64+
id-token: 'write'
65+
with:
66+
deployment_name: ${{ inputs.deployment-name }}
67+
# For now, the region is not used because it's overridden in the tf, but it's here for future compatibility.
68+
ess-region: "gcp-us-west2"
69+
elk-stack-version: ${{ inputs.stack-version }}
70+
serverless_mode: false
71+
agentless: false
72+
expiration_days: 14
73+
infra-type: ${{ inputs.infra-type }}
74+
deploy-stack: false
75+
ext-kibana-url: ${{ inputs.kibana-url }}
76+
ext-es-user: ${{ inputs.kibana-username }}
77+
ext-es-password: ${{ needs.naming.outputs.es-password }}
78+
docker-image-override: ${{ inputs.docker-image-override }}

.github/workflows/test-environment.yml

+64-13
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,27 @@ on:
113113
type: boolean
114114
required: false
115115
default: true
116+
ext-kibana-url:
117+
description: "External Kibana URL for update existing environment"
118+
type: string
119+
required: false
120+
ext-es-url:
121+
description: "External Elasticsearch URL for update existing environment"
122+
type: string
123+
required: false
124+
ext-es-user:
125+
description: "External Elasticsearch user for update existing environment"
126+
type: string
127+
required: false
128+
ext-es-password:
129+
description: "External Elasticsearch password for update existing environment"
130+
type: string
131+
required: false
132+
deploy-stack:
133+
description: "Deploy stack"
134+
type: boolean
135+
required: false
136+
default: true
116137
outputs:
117138
s3-bucket:
118139
description: "Terraform state s3 bucket folder"
@@ -239,6 +260,17 @@ jobs:
239260
echo "INFRA_TYPE=$INPUT_INFRA_TYPE" >> $GITHUB_ENV
240261
fi
241262
263+
- name: Init Deploy Stack
264+
id: init-deploy-stack
265+
env:
266+
INIT_DEPLOY_STACK: ${{ inputs.deploy-stack }}
267+
run: |
268+
if [[ "${INIT_DEPLOY_STACK}" == "true" || -z "${INIT_DEPLOY_STACK}" ]]; then
269+
echo "DEPLOY_STACK=true" >> $GITHUB_ENV
270+
else
271+
echo "DEPLOY_STACK=false" >> $GITHUB_ENV
272+
fi
273+
242274
- name: Init Agent Based
243275
id: init-agent-based
244276
env:
@@ -304,6 +336,7 @@ jobs:
304336
305337
- name: Deploy ELK Cloud Stack
306338
id: elk-stack
339+
if: ${{ env.DEPLOY_STACK == 'true' }}
307340
uses: ./.github/actions/elk-stack
308341
with:
309342
deployment-name: ${{ env.DEPLOYMENT_NAME }}
@@ -328,7 +361,8 @@ jobs:
328361
python3 ../../.ci/scripts/create_env_config.py
329362
aws s3 cp "./env_config.json" "${S3_BUCKET}/env_config.json"
330363
331-
- name: Update Stack Vars
364+
- name: Update Stack Vars - new Deployment
365+
if: ${{ env.DEPLOY_STACK == 'true' }}
332366
env:
333367
STACK_ES_USER: ${{ steps.elk-stack.outputs.es-user }}
334368
STACK_ES_PASSWORD: ${{ steps.elk-stack.outputs.es-password }}
@@ -340,6 +374,23 @@ jobs:
340374
echo "KIBANA_URL=$STACK_KIBANA_URL" >> $GITHUB_ENV
341375
echo "ES_URL=$STACK_ES_URL" >> $GITHUB_ENV
342376
377+
- name: Update Stack Vars - existing Deployment
378+
if: ${{ env.DEPLOY_STACK == 'false' }}
379+
env:
380+
USER_ES_USER: ${{ inputs.ext-es-user || '' }}
381+
USER_ES_PASSWORD: ${{ inputs.ext-es-password }}
382+
USER_KIBANA_URL: ${{ inputs.ext-kibana-url || '' }}
383+
USER_ES_URL: ${{ inputs.ext-es-url || '' }}
384+
SECRET: ${{ secrets.GPG_PASSPHRASE }}
385+
run: |
386+
echo "Using user-provided environment values..."
387+
echo "ES_USER=$USER_ES_USER" >> $GITHUB_ENV
388+
user_password=$(gpg --decrypt --quiet --batch --passphrase "$SECRET" --output - <(echo "$USER_ES_PASSWORD" | base64 --decode))
389+
echo "::add-mask::$user_password"
390+
echo "ES_PASSWORD=$user_password" >> $GITHUB_ENV
391+
echo "KIBANA_URL=$USER_KIBANA_URL" >> $GITHUB_ENV
392+
echo "ES_URL=$USER_ES_URL" >> $GITHUB_ENV
393+
343394
- name: Summary
344395
if: success()
345396
run: |
@@ -357,7 +408,7 @@ jobs:
357408
358409
- name: Deploy CDR Integrations
359410
id: cdr-integrations
360-
if: ${{ !cancelled() && steps.elk-stack.outcome == 'success' && env.INFRA_TYPE != 'cis' }}
411+
if: ${{ !cancelled() && (steps.elk-stack.outcome == 'success' || env.DEPLOY_STACK == 'false') && env.INFRA_TYPE != 'cis' }}
361412
uses: ./.github/actions/cdr
362413
with:
363414
deployment-name: ${{ env.DEPLOYMENT_NAME }}
@@ -372,17 +423,17 @@ jobs:
372423
wiz-endpoint-url: ${{ secrets.WIZ_ENDPOINT_URL }}
373424
wiz-token-url: ${{ secrets.WIZ_TOKEN_URL }}
374425
env-s3-bucket: "${{ env.S3_BASE_BUCKET }}/${{ env.DEPLOYMENT_NAME }}_${{ env.TF_STATE_FOLDER }}"
375-
es-user: ${{ steps.elk-stack.outputs.es-user }}
376-
es-password: ${{ steps.elk-stack.outputs.es-password }}
377-
kibana-url: ${{ steps.elk-stack.outputs.kibana-url }}
426+
es-user: ${{ env.ES_USER }}
427+
es-password: ${{ env.ES_PASSWORD }}
428+
kibana-url: ${{ env.KIBANA_URL }}
378429
elk-stack-version: ${{ env.STACK_VERSION }}
379430
azure-tags: ${{ env.AZURE_DEFAULT_TAGS }}
380431
tag-project: ${{ github.actor }}
381432
tag-owner: ${{ github.actor }}
382433

383434
- name: Deploy CIS Agent Based Integrations
384435
id: cis-integrations
385-
if: ${{ !cancelled() && env.AGENT_BASED == 'true' && steps.elk-stack.outcome == 'success' && env.INFRA_TYPE != 'cdr' }}
436+
if: ${{ !cancelled() && env.AGENT_BASED == 'true' && (steps.elk-stack.outcome == 'success' || env.DEPLOY_STACK == 'false') && env.INFRA_TYPE != 'cdr' }}
386437
uses: ./.github/actions/cis-agent-based
387438
with:
388439
deployment-name: ${{ env.DEPLOYMENT_NAME }}
@@ -392,23 +443,23 @@ jobs:
392443
cspm-azure-tags: ${{ env.AZURE_DEFAULT_TAGS }}
393444
stack-enrollment-token: ${{ env.ENROLLMENT_TOKEN }}
394445
env-s3-bucket: "${{ env.S3_BASE_BUCKET }}/${{ env.DEPLOYMENT_NAME }}_${{ env.TF_STATE_FOLDER }}"
395-
es-user: ${{ steps.elk-stack.outputs.es-user }}
396-
es-password: ${{ steps.elk-stack.outputs.es-password }}
397-
kibana-url: ${{ steps.elk-stack.outputs.kibana-url }}
446+
es-user: ${{ env.ES_USER }}
447+
es-password: ${{ env.ES_PASSWORD }}
448+
kibana-url: ${{ env.KIBANA_URL }}
398449
docker-image-override: ${{ env.DOCKER_IMAGE_OVERRIDE }}
399450
serverless-mode: "${{ env.TF_VAR_serverless_mode }}"
400451
tag-project: ${{ github.actor }}
401452
tag-owner: ${{ github.actor }}
402453

403454
- name: Deploy CIS Agentless Integrations
404455
id: cis-agentless-integrations
405-
if: ${{ !cancelled() && env.AGENTLESS == 'true' && steps.elk-stack.outcome == 'success' && env.INFRA_TYPE != 'cdr' }}
456+
if: ${{ !cancelled() && env.AGENTLESS == 'true' && (steps.elk-stack.outcome == 'success' || env.DEPLOY_STACK == 'false') && env.INFRA_TYPE != 'cdr' }}
406457
uses: ./.github/actions/cis-agentless
407458
with:
408459
cspm-azure-creds: ${{ secrets.AZURE_CREDENTIALS }}
409-
es-user: ${{ steps.elk-stack.outputs.es-user }}
410-
es-password: ${{ steps.elk-stack.outputs.es-password }}
411-
kibana-url: ${{ steps.elk-stack.outputs.kibana-url }}
460+
es-user: ${{ env.ES_USER }}
461+
es-password: ${{ env.ES_PASSWORD }}
462+
kibana-url: ${{ env.KIBANA_URL }}
412463

413464
- name: Wait for agents to enroll
414465
id: wait-for-agents

dev-docs/Cloud-Env-Testing.md

+15
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,21 @@ The [`Create Environment with Cloud Logs`](https://github.com/elastic/cloudbeat/
146146

147147
The workflow requires a subset of input parameters. All required inputs are described [here](#how-to-run-the-workflow).
148148

149+
## Install Integrations Worfklow
150+
151+
The [`Install Integrations`](https://github.com/elastic/cloudbeat/actions/workflows/install-integrations.yml) GitHub workflow is used when the Elastic Stack is already installed, and the user wants to add `CIS` and/or `CDR` integrations.
152+
153+
### Workflow Inputs
154+
155+
- **`stack-version`** - The version of the stack to deploy.
156+
- **`kibana-url`** - The Kibana URL where the integrations will be installed.
157+
- **`kibana-username`** - The username for Kibana login.
158+
- **`kibana-password`** - The password for Kibana login.
159+
- **`infra-type`** - The type of integrations to install, with three allow options:
160+
- **`all`** - Installs both `CIS` and `CDR` integrations.
161+
- **`cis`** - Installs `CSPM`, `KSPM`, and `CNVM` integrations.
162+
- **`cdr`** - Installs `Audit Logs`, `Asset Inventory`, and `Wiz` integrations.
163+
- **`docker-image-override`** - For build candidate versions, specifies a custom Docker image path for agent installations.
149164

150165
## Cleanup Procedure
151166

0 commit comments

Comments
 (0)