Skip to content

Commit f5e951f

Browse files
SSPROD-56225 - allow pre-existing SP and AD resources (#73)
* SSPROD-56225 - allow pre-existing SP and AD resources * SSPROD-56225 - allow pre-existing SP and AD resources * SSPROD-56225 - allow pre-existing SP and AD resources * SSPROD-56225 - allow pre-existing SP and AD resources * SSPROD-56225 - allow pre-existing SP and AD resources * SSPROD-56225 - allow pre-existing SP and AD resources * SSPROD-56225 - allow pre-existing SP and AD resources
1 parent b05c27b commit f5e951f

27 files changed

+237
-96
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ for the respective Sysdig features. They manage both, onboarding a single Azure
2626

2727
`onboarding`, `config-posture` and `agentless-scanning` are independent feature modules.
2828

29+
A Service Principal is created per each independent module due to permission scoping, if you want to use a pre-existing one instead of creating a new one, refer to each module's README file.
30+
2931
### Integrations
3032

3133
The modules under `integrations` are feature agnostic modules which deploy and manage all the required Cloud resources and Sysdig resources
@@ -35,6 +37,8 @@ These modules manage both, onboarding a single Azure Subscription or an Azure Te
3537

3638
`event-hub` is an integration module.
3739

40+
A Service Principal is created per each independent integration module due to permission scoping, if you want to use a pre-existing one instead of creating a new one, refer to each module's README file.
41+
3842
## Examples and usage
3943

4044
The modules in this repository can be installed on a single Azure subscription, or on an entire Azure Tenant, or management groups within the Tenant.

modules/config-posture/README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ If instrumenting an Azure Tenant, the following resources will be created:
1212
- Role assignments with associated role permissions at the Root Management Group level by default for the Tenant, or at each of the
1313
instrumented Management Groups within the Tenant if provided.
1414

15+
**Important**. If using a pre-existing Service Principal is needed, creating a service principal associated with the Sysdig Config Posture Application ID is required:
16+
- The Sysdig Config Posture Application ID can be found as part of the output of the `sysdig_secure_trusted_azure_app` data source created in this module. Also, it can be retrieved by hitting the Sysdig onboarding API using the `sysdig_secure_api_token` provided within the Sysdig UI > Settings > Sysdig Secure API Token, the API curl command uses the `app=config_posture` query parameter:
17+
```bash
18+
curl --location 'https://<sysdig-secure>/api/secure/onboarding/v2/trustedAzureApp?app=config_posture' \
19+
--header 'Authorization: Bearer <token>'
20+
```
21+
- From the previous call, use the `applicationId` field from the response to create the Service Principal in your Azure Tenant.
22+
- Assign the [Directory Reader role](https://learn.microsoft.com/en-us/entra/identity/role-based-access-control/permissions-reference#directory-readers) to the Service Principal created in your Azure Tenant. This is a required permission, the role template ID for this role is `88d8e3e3-8f55-4a1e-953a-9b9898b8876b`.
23+
- Provide the Service Principal ID as input to the `config_posture_service_principal` variable in this module. This will
24+
skip the creation of a new Service Principal and use the one provided instead.
25+
- Contact Sysdig Support if you need assistance with this process.
26+
1527
This module will also deploy a Service Principal Component in Sysdig Backend for onboarded Sysdig Cloud Account.
1628

1729
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
@@ -55,13 +67,14 @@ No modules.
5567

5668
## Inputs
5769

58-
| Name | Description | Type | Default | Required |
59-
|------|-------------|------|---------|:--------:|
60-
| <a name="input_agentless_aks_connection_enabled"></a> [agentless\_aks\_connection\_enabled](#input\_agentless\_aks\_connection\_enabled) | Enable the Agentless AKS connection to the K8s clusters within the cloud. This allows admin access. Read more about why this is needed in the official docs. | `bool` | `false` | no |
61-
| <a name="input_is_organizational"></a> [is\_organizational](#input\_is\_organizational) | (Optional) Set this field to 'true' to deploy secure-for-cloud to an Azure Tenant. | `bool` | `false` | no |
62-
| <a name="input_management_group_ids"></a> [management\_group\_ids](#input\_management\_group\_ids) | (Optional) List of Azure Management Group IDs. secure-for-cloud will be deployed to all the subscriptions under these management groups. | `set(string)` | `[]` | no |
63-
| <a name="input_subscription_id"></a> [subscription\_id](#input\_subscription\_id) | Subscription ID in which to create resources for secure-for-cloud | `string` | n/a | yes |
64-
| <a name="input_sysdig_secure_account_id"></a> [sysdig\_secure\_account\_id](#input\_sysdig\_secure\_account\_id) | ID of the Sysdig Cloud Account to enable Config Posture for (incase of organization, ID of the Sysdig management account) | `string` | n/a | yes |
70+
| Name | Description | Type | Default | Required |
71+
|------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|---------|:--------:|
72+
| <a name="input_agentless_aks_connection_enabled"></a> [agentless\_aks\_connection\_enabled](#input\_agentless\_aks\_connection\_enabled) | Enable the Agentless AKS connection to the K8s clusters within the cloud. This allows admin access. Read more about why this is needed in the official docs. | `bool` | `false` | no |
73+
| <a name="input_is_organizational"></a> [is\_organizational](#input\_is\_organizational) | (Optional) Set this field to 'true' to deploy secure-for-cloud to an Azure Tenant. | `bool` | `false` | no |
74+
| <a name="input_management_group_ids"></a> [management\_group\_ids](#input\_management\_group\_ids) | (Optional) List of Azure Management Group IDs. secure-for-cloud will be deployed to all the subscriptions under these management groups. | `set(string)` | `[]` | no |
75+
| <a name="input_subscription_id"></a> [subscription\_id](#input\_subscription\_id) | Subscription ID in which to create resources for secure-for-cloud | `string` | n/a | yes |
76+
| <a name="input_sysdig_secure_account_id"></a> [sysdig\_secure\_account\_id](#input\_sysdig\_secure\_account\_id) | ID of the Sysdig Cloud Account to enable Config Posture for (incase of organization, ID of the Sysdig management account) | `string` | n/a | yes |
77+
| <a name="input_config_posture_service_principal"></a> [config\_posture\_service\_principal](#input\_config\_posture\_service\_principal) | (Optional) Service Principal to be used for CSPM, this SP needs to be associated to the Sysdig Config Posture Application ID. If not provided, a new one will be created. | `string` | `""` | no |
6578

6679
## Outputs
6780

modules/config-posture/main.tf

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ locals {
2727
# Note: Once created, this cannot be deleted via Terraform. It can be manually deleted from Azure.
2828
# This is to safeguard against unintended deletes if the service principal is in use.
2929
#--------------------------------------------------------------------------------------------------------------
30+
data "azuread_service_principal" "sysdig_cspm_sp" {
31+
count = var.config_posture_service_principal != "" ? 1 : 0
32+
object_id = var.config_posture_service_principal
33+
}
34+
3035
resource "azuread_service_principal" "sysdig_cspm_sp" {
36+
count = var.config_posture_service_principal != "" ? 0 : 1
3137
client_id = data.sysdig_secure_trusted_azure_app.config_posture.application_id
3238
use_existing = true
3339
notes = "Service Principal linked to the Sysdig Secure CNAPP - CSPM module"
@@ -36,9 +42,11 @@ resource "azuread_service_principal" "sysdig_cspm_sp" {
3642
#---------------------------------------------------------------------------------------------
3743
# Assign "Directory Reader" AD role to Sysdig SP
3844
#---------------------------------------------------------------------------------------------
45+
3946
resource "azuread_directory_role_assignment" "sysdig_ad_reader" {
47+
count = var.config_posture_service_principal != "" ? 0 : 1
4048
role_id = "88d8e3e3-8f55-4a1e-953a-9b9898b8876b" // template ID of Directory Reader AD role
41-
principal_object_id = azuread_service_principal.sysdig_cspm_sp.object_id
49+
principal_object_id = azuread_service_principal.sysdig_cspm_sp[0].object_id
4250
}
4351

4452
#---------------------------------------------------------------------------------------------
@@ -47,7 +55,7 @@ resource "azuread_directory_role_assignment" "sysdig_ad_reader" {
4755
resource "azurerm_role_assignment" "sysdig_reader" {
4856
scope = data.azurerm_subscription.primary.id
4957
role_definition_name = "Reader"
50-
principal_id = azuread_service_principal.sysdig_cspm_sp.object_id
58+
principal_id = var.config_posture_service_principal != "" ? data.azuread_service_principal.sysdig_cspm_sp[0].object_id : azuread_service_principal.sysdig_cspm_sp[0].object_id
5159
}
5260

5361
#---------------------------------------------------------------------------------------------
@@ -74,7 +82,7 @@ resource "azurerm_role_definition" "sysdig_cspm_role" {
7482
resource "azurerm_role_assignment" "sysdig_cspm_role_assignment" {
7583
scope = data.azurerm_subscription.primary.id
7684
role_definition_id = azurerm_role_definition.sysdig_cspm_role.role_definition_resource_id
77-
principal_id = azuread_service_principal.sysdig_cspm_sp.object_id
85+
principal_id = var.config_posture_service_principal != "" ? data.azuread_service_principal.sysdig_cspm_sp[0].object_id : azuread_service_principal.sysdig_cspm_sp[0].object_id
7886
}
7987

8088
#--------------------------------------------------------------------------------------------------------------
@@ -91,11 +99,11 @@ resource "sysdig_secure_cloud_auth_account_component" "azure_service_principal"
9199
azure = {
92100
active_directory_service_principal = {
93101
account_enabled = true
94-
display_name = azuread_service_principal.sysdig_cspm_sp.display_name
95-
id = azuread_service_principal.sysdig_cspm_sp.object_id
96-
app_display_name = azuread_service_principal.sysdig_cspm_sp.display_name
97-
app_id = azuread_service_principal.sysdig_cspm_sp.client_id
98-
app_owner_organization_id = azuread_service_principal.sysdig_cspm_sp.application_tenant_id
102+
display_name = var.config_posture_service_principal != "" ? data.azuread_service_principal.sysdig_cspm_sp[0].display_name : azuread_service_principal.sysdig_cspm_sp[0].display_name
103+
id = var.config_posture_service_principal != "" ? data.azuread_service_principal.sysdig_cspm_sp[0].object_id : azuread_service_principal.sysdig_cspm_sp[0].object_id
104+
app_display_name = var.config_posture_service_principal != "" ? data.azuread_service_principal.sysdig_cspm_sp[0].display_name : azuread_service_principal.sysdig_cspm_sp[0].display_name
105+
app_id = var.config_posture_service_principal != "" ? data.azuread_service_principal.sysdig_cspm_sp[0].client_id : azuread_service_principal.sysdig_cspm_sp[0].client_id
106+
app_owner_organization_id = var.config_posture_service_principal != "" ? data.azuread_service_principal.sysdig_cspm_sp[0].application_tenant_id : azuread_service_principal.sysdig_cspm_sp[0].application_tenant_id
99107
}
100108
}
101109
})

modules/config-posture/organizational.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ resource "azurerm_role_assignment" "sysdig_reader_for_tenant" {
2020

2121
scope = each.key
2222
role_definition_name = "Reader"
23-
principal_id = azuread_service_principal.sysdig_cspm_sp.object_id
23+
principal_id = var.config_posture_service_principal != "" ? data.azuread_service_principal.sysdig_cspm_sp[0].object_id : azuread_service_principal.sysdig_cspm_sp[0].object_id
2424
}
2525

2626
#---------------------------------------------------------------------------------------------
@@ -53,5 +53,5 @@ resource "azurerm_role_assignment" "sysdig_cspm_role_assignment_for_tenant" {
5353

5454
scope = each.key
5555
role_definition_id = azurerm_role_definition.sysdig_cspm_role_for_tenant[each.key].role_definition_resource_id
56-
principal_id = azuread_service_principal.sysdig_cspm_sp.object_id
56+
principal_id = var.config_posture_service_principal != "" ? data.azuread_service_principal.sysdig_cspm_sp[0].object_id : azuread_service_principal.sysdig_cspm_sp[0].object_id
5757
}

modules/config-posture/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ output "service_principal_component_id" {
55
}
66

77
output "sysdig_cspm_sp_object_id" {
8-
value = azuread_service_principal.sysdig_cspm_sp.object_id
8+
value = var.config_posture_service_principal != "" ? data.azuread_service_principal.sysdig_cspm_sp[0].object_id : azuread_service_principal.sysdig_cspm_sp[0].object_id
99
description = "Object ID of the CSPM SP within the client's infra"
1010
depends_on = [azuread_service_principal.sysdig_cspm_sp]
1111
}

modules/config-posture/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ variable "agentless_aks_connection_enabled" {
2525
description = "Enable the Agentless AKS connection to the K8s clusters within the cloud. This allows admin access. Read more about why this is needed in the official docs."
2626
default = false
2727
}
28+
29+
variable "config_posture_service_principal" {
30+
description = "(Optional) Service Principal to be used for CSPM. If not provided, a new one will be created."
31+
type = string
32+
default = ""
33+
}

0 commit comments

Comments
 (0)