Skip to content
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
31 changes: 20 additions & 11 deletions infrastructure/open_cti.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ resource "aws_iam_role_policy" "open_cti_ssm_read_secrets" {
"ssm:GetParameters",
"ssm:GetParametersByPath",
],
Resource = "arn:${var.aws_partition}:ssm:${var.aws_region}:*:parameter${var.open_cti_ssm_path_prefix}*"
Resource = [
"arn:${var.aws_partition}:ssm:${var.aws_region}:*:parameter${var.open_cti_ssm_path_prefix}*",
# install-deps.sh reads these to install the Wiz sensor.
"arn:${var.aws_partition}:ssm:${var.aws_region}:*:parameter${var.ssm_wiz_backend_env}",
"arn:${var.aws_partition}:ssm:${var.aws_region}:*:parameter${var.ssm_wiz_api_client_id}",
"arn:${var.aws_partition}:ssm:${var.aws_region}:*:parameter${var.ssm_wiz_api_client_secret}",
]
}]
})
}
Expand Down Expand Up @@ -256,16 +262,19 @@ locals {
"set -euo pipefail",
"",
templatefile("${path.module}/open_cti_user_data_env.sh.tpl", {
ssm_path_prefix = var.open_cti_ssm_path_prefix
repo_url = var.open_cti_repo_url
repo_branch = var.open_cti_repo_branch
opencti_host = var.open_cti_host
opencti_admin_email = var.open_cti_admin_email
smtp_hostname = var.open_cti_smtp_hostname
censys_org_id = var.open_cti_censys_org_id
qualys_api_username = var.open_cti_qualys_api_username
xtm_one_host = var.open_cti_xtm_one_host
xtm_one_admin_email = var.open_cti_xtm_one_admin_email
ssm_path_prefix = var.open_cti_ssm_path_prefix
repo_url = var.open_cti_repo_url
repo_branch = var.open_cti_repo_branch
opencti_host = var.open_cti_host
opencti_admin_email = var.open_cti_admin_email
smtp_hostname = var.open_cti_smtp_hostname
censys_org_id = var.open_cti_censys_org_id
qualys_api_username = var.open_cti_qualys_api_username
xtm_one_host = var.open_cti_xtm_one_host
xtm_one_admin_email = var.open_cti_xtm_one_admin_email
wiz_backend_env_ssm_param = var.ssm_wiz_backend_env
wiz_api_client_id_ssm_param = var.ssm_wiz_api_client_id
wiz_api_client_secret_ssm_param = var.ssm_wiz_api_client_secret
}),
"",
"cat > /opt/open-cti/install-deps.sh <<'INSTALL_DEPS_EOF'",
Expand Down
3 changes: 3 additions & 0 deletions infrastructure/open_cti_user_data_env.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ CENSYS_ORG_ID="${censys_org_id}"
QUALYS_API_USERNAME="${qualys_api_username}"
XTM_ONE_HOST="${xtm_one_host}"
XTM_ONE_ADMIN_EMAIL="${xtm_one_admin_email}"
WIZ_BACKEND_ENV_SSM_PARAM="${wiz_backend_env_ssm_param}"
WIZ_API_CLIENT_ID_SSM_PARAM="${wiz_api_client_id_ssm_param}"
WIZ_API_CLIENT_SECRET_SSM_PARAM="${wiz_api_client_secret_ssm_param}"
ENV_DEPLOY_EOF
3 changes: 3 additions & 0 deletions infrastructure/stage.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,6 @@ playwright_worker_repository_name = "crossfeed-playwright-staging-wor
zscaler_cert_bucket_name = "cisa-crossfeed-staging-zscaler"
backend_api_log_group_name = "cyhy-staging-backend-api"
backend_api_requests_log_group_name = "cyhy-staging-backend-api-requests"
ssm_wiz_backend_env = "/crossfeed/staging/WIZ_BACKEND_ENV"
ssm_wiz_api_client_secret = "/crossfeed/staging/WIZ_API_CLIENT_SECRET"
ssm_wiz_api_client_id = "/crossfeed/staging/WIZ_API_CLIENT_ID"
18 changes: 18 additions & 0 deletions infrastructure/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1315,3 +1315,21 @@ variable "ssm_pe_s3_bucket" {
type = string
default = "/crossfeed/staging/PE_S3_BUCKET"
}

variable "ssm_wiz_backend_env" {
description = "ssm_wiz_backend_env"
type = string
default = "/crossfeed/staging/WIZ_BACKEND_ENV"
}

variable "ssm_wiz_api_client_secret" {
description = "ssm_wiz_api_client_secret"
type = string
default = "/crossfeed/staging/WIZ_API_CLIENT_SECRET"
}

variable "ssm_wiz_api_client_id" {
description = "ssm_wiz_api_client_id"
type = string
default = "/crossfeed/staging/WIZ_API_CLIENT_ID"
}
24 changes: 24 additions & 0 deletions open-cti/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,27 @@ if ! command -v aws >/dev/null 2>&1; then
log "FATAL: aws CLI not found -- confirm the base AMI ships it." >&2
exit 1
fi

# WIZ Sensor Installation - Variables fetched from SSM via env.deploy
if [[ -d /opt/wiz/sensor ]] || systemctl list-unit-files 2>/dev/null | grep -qi '^wiz-sensor'; then
log "Wiz sensor already installed, skipping."
else
log "Installing Wiz sensor..."
# shellcheck source=/dev/null
source /opt/open-cti/env.deploy
: "${WIZ_BACKEND_ENV_SSM_PARAM:?WIZ_BACKEND_ENV_SSM_PARAM must be set in /opt/open-cti/env.deploy}"
: "${WIZ_API_CLIENT_ID_SSM_PARAM:?WIZ_API_CLIENT_ID_SSM_PARAM must be set in /opt/open-cti/env.deploy}"
: "${WIZ_API_CLIENT_SECRET_SSM_PARAM:?WIZ_API_CLIENT_SECRET_SSM_PARAM must be set in /opt/open-cti/env.deploy}"

ssm_get() { aws ssm get-parameter --name "$1" --with-decryption --query 'Parameter.Value' --output text; }
WIZ_BACKEND_ENV=$(ssm_get "$WIZ_BACKEND_ENV_SSM_PARAM")
WIZ_API_CLIENT_ID=$(ssm_get "$WIZ_API_CLIENT_ID_SSM_PARAM")
WIZ_API_CLIENT_SECRET=$(ssm_get "$WIZ_API_CLIENT_SECRET_SSM_PARAM")
export WIZ_BACKEND_ENV WIZ_API_CLIENT_ID WIZ_API_CLIENT_SECRET

WIZ_INSTALLER=$(mktemp)
curl -fsSL https://downloads.wiz.us/sensor/sensor_install.sh -o "$WIZ_INSTALLER"
bash "$WIZ_INSTALLER"
rm -f "$WIZ_INSTALLER"
unset WIZ_API_CLIENT_ID WIZ_API_CLIENT_SECRET
fi
8 changes: 7 additions & 1 deletion open-cti/refresh-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ source "$OPEN_CTI_DIR/env.deploy"
: "${OPEN_CTI_REPO_URL:?OPEN_CTI_REPO_URL must be set in $OPEN_CTI_DIR/env.deploy}"
: "${OPEN_CTI_REPO_BRANCH:?OPEN_CTI_REPO_BRANCH must be set in $OPEN_CTI_DIR/env.deploy}"

# Sparse checkout: only open-cti/ is materialized under $REPO_DIR (paths unchanged, e.g.
# $REPO_DIR/open-cti/bootstrap.sh); the rest of the monorepo is never written to disk.
# --filter=blob:none also skips downloading blobs outside the sparse set.
if [[ -d "$REPO_DIR/.git" ]]; then
# Idempotent -- also shrinks a pre-existing full checkout on its next boot.
git -C "$REPO_DIR" sparse-checkout set open-cti
git -C "$REPO_DIR" fetch --depth 1 origin "$OPEN_CTI_REPO_BRANCH"
git -C "$REPO_DIR" reset --hard "origin/$OPEN_CTI_REPO_BRANCH"
else
git clone --depth 1 --branch "$OPEN_CTI_REPO_BRANCH" "$OPEN_CTI_REPO_URL" "$REPO_DIR"
git clone --depth 1 --filter=blob:none --sparse --branch "$OPEN_CTI_REPO_BRANCH" "$OPEN_CTI_REPO_URL" "$REPO_DIR"
git -C "$REPO_DIR" sparse-checkout set open-cti
fi

install -m 644 "$REPO_DIR/open-cti/systemd/open-cti-render-env.service" /etc/systemd/system/
Expand Down
Loading