Skip to content

Commit 5fca467

Browse files
authored
Merge pull request #112 from stackrox/add-azure-sentinel-terraform
Add Azure Sentinel terraform scripts
2 parents e059229 + 1843246 commit 5fca467

File tree

7 files changed

+190
-13
lines changed

7 files changed

+190
-13
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Based on https://gist.github.com/octocat/9257657
22

3+
.idea
4+
35
# Compiled source #
46
###################
57
*.com
@@ -42,5 +44,6 @@ Thumbs.db
4244
##############
4345
sensor*.zip
4446
tmp
45-
/central-bundle/
46-
47+
/central-bundle
48+
/**/.terraform
49+
/terraform/**/.terraform.lock.hcl

acs-export-example/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ require (
8282
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
8383
github.com/hashicorp/errwrap v1.1.0 // indirect
8484
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
85-
github.com/hashicorp/go-hclog v1.5.0 // indirect
8685
github.com/hashicorp/go-multierror v1.1.1 // indirect
8786
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
8887
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect

acs-export-example/go.sum

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f h1:Wl78ApPPB2
133133
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f/go.mod h1:OSYXu++VVOHnXeitef/D8n/6y4QV8uLHSFXX4NeXMGc=
134134
github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
135135
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
136-
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
137136
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
138137
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
139138
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
@@ -272,13 +271,12 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
272271
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
273272
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
274273
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
275-
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
276-
github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c=
277-
github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
274+
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
275+
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
278276
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
279277
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
280-
github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M=
281-
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
278+
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
279+
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
282280
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
283281
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
284282
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
@@ -574,7 +572,6 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
574572
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
575573
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
576574
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
577-
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
578575
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
579576
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
580577
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
@@ -753,11 +750,8 @@ golang.org/x/sys v0.0.0-20201126233918-771906719818/go.mod h1:h1NjWce9XRLGQEsW7w
753750
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
754751
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
755752
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
756-
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
757-
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
758753
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
759754
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
760-
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
761755
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
762756
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
763757
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

terraform/azure-sentinel/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Azure Log Analytics - Sentinel Terraform
2+
3+
This terraform script will provide all resources to setup an integration with Sentinel and Log Analytics Workspace.
4+
5+
This terraform script will provision following resources:
6+
7+
- Resource group
8+
- Log Analytics Workspace
9+
- Data Collection Endpoint
10+
- Data Collection Rule
11+
12+
This script can be used to provision a custom environment and is used for CI testing.
13+
14+
For more information visit the documentation in the [stackrox repo's Sentinel notifier](https://github.com/stackrox/stackrox/tree/master/central/notifiers/microsoftsentinel).
15+
16+
## Quick start
17+
18+
Requirements:
19+
20+
- Install azcli
21+
- Authenticating via a [Service Principal](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_client_secret)
22+
- Access to the Microsoft Azure StackRox tenant
23+
- Access to bitwarden
24+
25+
```
26+
# Login into Azure, select the subscription.
27+
$ az login
28+
29+
$ export ARM_SUBSCRIPTION_ID="<id>"
30+
$ export ARM_CLIENT_SECRET="<password>"
31+
$ export ARM_TENANT_ID="<tenant_id>"
32+
$ export ARM_CLIENT_ID="<client_d>"
33+
34+
$ terraform init
35+
$ terraform fmt
36+
$ terraform validate
37+
$ terraform apply
38+
```
39+
40+
For later reference example Data Collection Rule configuration: https://github.com/hashicorp/terraform-provider-azurerm/blob/main/examples/azure-monitoring/data-collection-rule/main.tf
41+
42+
### Create a service principal
43+
44+
In case you need a new service principal you can run the command below. Please only use this if you are
45+
sure you need new credentials. Make sure to save them in bitwarden.
46+
47+
```
48+
# Create a service principal for authentication
49+
$ az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/$ARM_SUBSCRIPTION_ID"
50+
51+
{
52+
"appId": "<appid>",
53+
"displayName": "azure-cli-2024-10-07-08-49-10",
54+
"password": "<password>",
55+
"tenant": "<tenanid>"
56+
}
57+
```

terraform/azure-sentinel/main.tf

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
resource "azurerm_resource_group" "rg" {
2+
name = "${var.prefix}-resources"
3+
location = var.region
4+
}
5+
6+
resource "azurerm_monitor_data_collection_endpoint" "endpoint" {
7+
name = "${var.prefix}-data-collection-endpoint"
8+
resource_group_name = azurerm_resource_group.rg.name
9+
location = azurerm_resource_group.rg.location
10+
public_network_access_enabled = true
11+
12+
lifecycle {
13+
create_before_destroy = true
14+
}
15+
}
16+
17+
resource "azurerm_log_analytics_workspace" "logworkspace" {
18+
name = "${var.prefix}-log-analytics-workspace"
19+
location = azurerm_resource_group.rg.location
20+
resource_group_name = azurerm_resource_group.rg.name
21+
sku = "PerGB2018"
22+
retention_in_days = 30
23+
}
24+
25+
# We are using the azapi provider to create custom tables because it is unsupported in the Azure provider.
26+
# This resource links to the data_flow.output_stream field in the `azurerm_monitor_data_collection_rule` resource.
27+
resource "azapi_resource" "data_collection_logs_table" {
28+
name = "stackrox_alerts_CL"
29+
parent_id = azurerm_log_analytics_workspace.logworkspace.id
30+
type = "Microsoft.OperationalInsights/workspaces/tables@2022-10-01"
31+
body = jsonencode(
32+
{
33+
"properties" : {
34+
"schema" : {
35+
"name" : "stackrox_alerts_CL",
36+
"columns" : [
37+
{
38+
"name" : "TimeGenerated",
39+
"type" : "datetime",
40+
"description" : "The time at which the data was generated"
41+
},
42+
{
43+
"name" : "msg",
44+
"type" : "dynamic",
45+
"description" : "StackRox alert message sent by a notifer"
46+
}
47+
]
48+
},
49+
"retentionInDays" : 30,
50+
"totalRetentionInDays" : 30
51+
}
52+
}
53+
)
54+
}
55+
56+
# Data Collection Rule
57+
resource "azurerm_monitor_data_collection_rule" "rule" {
58+
name = "${var.prefix}-data-collection-rule"
59+
resource_group_name = azurerm_resource_group.rg.name
60+
location = azurerm_resource_group.rg.location
61+
data_collection_endpoint_id = azurerm_monitor_data_collection_endpoint.endpoint.id
62+
description = "StackRox data collection rule to forward StackRox alerts to the Log Analytics Workspace."
63+
64+
destinations {
65+
log_analytics {
66+
workspace_resource_id = azurerm_log_analytics_workspace.logworkspace.id
67+
name = "destination-logs"
68+
}
69+
}
70+
71+
data_flow {
72+
streams = ["Custom-stackrox_alerts_CL"]
73+
destinations = ["destination-logs"]
74+
75+
# From `data_collection_logs_table.name`. The prefix is prepended by Azure automatically.
76+
output_stream = "Custom-stackrox_alerts_CL"
77+
}
78+
79+
stream_declaration {
80+
stream_name = "Custom-stackrox_alerts_CL"
81+
column {
82+
name = "msg"
83+
type = "dynamic"
84+
}
85+
column {
86+
name = "TimeGenerated"
87+
type = "datetime"
88+
}
89+
}
90+
91+
depends_on = [
92+
azurerm_log_analytics_workspace.logworkspace,
93+
azapi_resource.data_collection_logs_table
94+
]
95+
}
96+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
required_providers {
3+
azurerm = {
4+
source = "hashicorp/azurerm"
5+
version = "~> 4.4.0"
6+
}
7+
azapi = {
8+
source = "Azure/azapi"
9+
version = "~> 1.8.0"
10+
}
11+
}
12+
13+
required_version = ">= 1.1.0"
14+
}
15+
16+
provider "azurerm" {
17+
features {}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
variable "region" {
2+
type = string
3+
default = "westus2"
4+
description = "The Azure region where the resources should be deployed to."
5+
}
6+
7+
variable "prefix" {
8+
type = string
9+
default = "stackrox-sentinel"
10+
}

0 commit comments

Comments
 (0)