Skip to content

Commit 1189524

Browse files
committed
switch to svc principal key for onboarding
1 parent 657ad41 commit 1189524

File tree

3 files changed

+19
-64
lines changed

3 files changed

+19
-64
lines changed

modules/config-posture/main.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,12 @@ resource "sysdig_secure_cloud_auth_account_component" "google_service_principal"
104104
email = google_service_account.posture_auth.email
105105
}
106106
})
107-
depends_on = [google_service_account_iam_member.custom_posture_auth]
107+
depends_on = [
108+
google_service_account.posture_auth,
109+
google_service_account_iam_binding.posture_auth_binding,
110+
google_iam_workload_identity_pool.posture_auth_pool,
111+
google_iam_workload_identity_pool_provider.posture_auth_pool_provider,
112+
google_project_iam_member.cspm,
113+
google_service_account_iam_member.custom_posture_auth
114+
]
108115
}

modules/onboarding/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ The Foundational Onboarding module serves the following functions:
77

88
If instrumenting a project, the following resources will be created:
99
- All the necessary `Service Accounts` and `Policies` to enable the Onboarding operation at the project level
10-
- A `Workload Identity Pool`, `Provider` and added custom role permissions to the `Service Account`, to allow Sysdig to authenticate to GCP on your behalf to validate resources.
10+
- A `Service Account key` and added role permissions to the `Service Account`, to allow Sysdig to authenticate to GCP on your behalf to validate resources.
1111
- A cloud account in the Sysdig Backend, associated with the GCP project and with the required component to serve the foundational functions.
1212

1313
If instrumenting an Organziation, the following resources will be created:
1414
- All the necessary `Service Accounts` and `Policies` to enable the Onboarding operation at the organization level
15-
- A `Workload Identity Pool`, `Provider` and added custom role permissions to the `Service Account`, to allow Sysdig to authenticate to GCP on your behalf to validate resources.
15+
- A `Service Account key` and added role permissions to the `Service Account`, to allow Sysdig to authenticate to GCP on your behalf to validate resources.
1616
- A cloud account in the Sysdig Backend, associated with the management project and with the required component to serve the foundational functions.
1717
- A cloud organization in the Sysdig Backend, associated with the GCP Organization to fetch the organization structure to install Sysdig Secure for Cloud on.
1818

modules/onboarding/main.tf

Lines changed: 9 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
#------------------------------------------------------------------#
2-
# Fetch and compute required data for Workload Identity Federation #
2+
# Fetch and compute required data for Service Account Key #
33
#------------------------------------------------------------------#
44

5-
data "sysdig_secure_trusted_cloud_identity" "trusted_identity" {
6-
cloud_provider = "gcp"
7-
}
8-
9-
data "sysdig_secure_tenant_external_id" "external_id" {}
10-
115
data "google_project" "project" {
126
project_id = var.project_id
137
}
148

15-
// suffix to uniquely identify WIF pool and provider during multiple installs. If suffix value is not provided, this will generate a random value.
9+
// suffix to uniquely identify onboarding service account during multiple installs. If suffix value is not provided, this will generate a random value.
1610
resource "random_id" "suffix" {
1711
count = var.suffix == null ? 1 : 0
1812
byte_length = 3
@@ -29,45 +23,6 @@ resource "google_service_account" "onboarding_auth" {
2923
project = var.project_id
3024
}
3125

32-
resource "google_service_account_iam_binding" "onboarding_auth_binding" {
33-
service_account_id = google_service_account.onboarding_auth.name
34-
role = "roles/iam.workloadIdentityUser"
35-
36-
members = [
37-
"serviceAccount:${google_service_account.onboarding_auth.email}",
38-
]
39-
}
40-
41-
#------------------------------------------------------------#
42-
# Configure Workload Identity Federation for auth #
43-
# See https://cloud.google.com/iam/docs/access-resources-aws #
44-
#------------------------------------------------------------#
45-
46-
resource "google_iam_workload_identity_pool" "onboarding_auth_pool" {
47-
project = var.project_id
48-
workload_identity_pool_id = "sysdig-onboarding-${local.suffix}"
49-
}
50-
51-
resource "google_iam_workload_identity_pool_provider" "onboarding_auth_pool_provider" {
52-
project = var.project_id
53-
workload_identity_pool_id = google_iam_workload_identity_pool.onboarding_auth_pool.workload_identity_pool_id
54-
workload_identity_pool_provider_id = "sysdig-onboarding-${local.suffix}"
55-
display_name = "Sysdigcloud onboarding auth"
56-
description = "AWS identity pool provider for Sysdig Secure Data Onboarding resources"
57-
disabled = false
58-
59-
attribute_condition = "attribute.aws_role==\"arn:aws:sts::${data.sysdig_secure_trusted_cloud_identity.trusted_identity.aws_account_id}:assumed-role/${data.sysdig_secure_trusted_cloud_identity.trusted_identity.aws_role_name}/${data.sysdig_secure_tenant_external_id.external_id.external_id}\""
60-
61-
attribute_mapping = {
62-
"google.subject" = "assertion.arn",
63-
"attribute.aws_role" = "assertion.arn"
64-
}
65-
66-
aws {
67-
account_id = data.sysdig_secure_trusted_cloud_identity.trusted_identity.aws_account_id
68-
}
69-
}
70-
7126
#---------------------------------
7227
# role permissions for onboarding
7328
#---------------------------------
@@ -79,11 +34,12 @@ resource "google_project_iam_member" "browser" {
7934
member = "serviceAccount:${google_service_account.onboarding_auth.email}"
8035
}
8136

82-
# attaching WIF as a member to the service account for auth
83-
resource "google_service_account_iam_member" "custom_onboarding_auth" {
37+
#--------------------------------
38+
# service account private key
39+
40+
#--------------------------------
41+
resource "google_service_account_key" "onboarding_service_account_key" {
8442
service_account_id = google_service_account.onboarding_auth.name
85-
role = "roles/iam.workloadIdentityUser"
86-
member = "principalSet://iam.googleapis.com/projects/${data.google_project.project.number}/locations/global/workloadIdentityPools/${google_iam_workload_identity_pool.onboarding_auth_pool.workload_identity_pool_id}/attribute.aws_role/arn:aws:sts::${data.sysdig_secure_trusted_cloud_identity.trusted_identity.aws_account_id}:assumed-role/${data.sysdig_secure_trusted_cloud_identity.trusted_identity.aws_role_name}/${data.sysdig_secure_tenant_external_id.external_id.external_id}"
8743
}
8844

8945
#---------------------------------------------------------------------------------------------
@@ -104,23 +60,15 @@ resource "sysdig_secure_cloud_auth_account" "google_account" {
10460
version = "v0.1.0"
10561
service_principal_metadata = jsonencode({
10662
gcp = {
107-
workload_identity_federation = {
108-
pool_id = google_iam_workload_identity_pool.onboarding_auth_pool.workload_identity_pool_id
109-
pool_provider_id = google_iam_workload_identity_pool_provider.onboarding_auth_pool_provider.workload_identity_pool_provider_id
110-
project_number = data.google_project.project.number
111-
}
112-
email = google_service_account.onboarding_auth.email
63+
key = google_service_account_key.onboarding_service_account_key.private_key
11364
}
11465
})
11566
}
11667

11768
depends_on = [
11869
google_service_account.onboarding_auth,
119-
google_service_account_iam_binding.onboarding_auth_binding,
120-
google_iam_workload_identity_pool.onboarding_auth_pool,
121-
google_iam_workload_identity_pool_provider.onboarding_auth_pool_provider,
12270
google_project_iam_member.browser,
123-
google_service_account_iam_member.custom_onboarding_auth
71+
google_service_account_key.onboarding_service_account_key
12472
]
12573

12674
lifecycle {

0 commit comments

Comments
 (0)