Enabling near real-time cloud security posture management (CSPM)

Near real-time cloud security posture management (CSPM) extends standard CSPM by routing resource configuration-change events through IBM Cloud® App Configuration and IBM Cloud® Event Notifications to IBM Cloud Security and Compliance Center Workload Protection, so that compliance findings appear within minutes of a change rather than at the next scheduled scan cycle. In this tutorial, learn how to add near real-time CSPM to an existing Workload Protection instance that already has CSPM enabled.

Objectives

  • Route resource-change events from Activity Tracker Event Routing to App Configuration.
  • Integrate App Configuration with Event Notifications so that detected changes are forwarded as notifications.
  • Configure an Event Notifications topic, Object Storage destination, and subscription to archive filtered events to a Object Storage bucket.
  • Set up a Code Engine app that reads the Object Storage archive and forwards events to Workload Protection for posture reconciliation.
  • Configure Workload Protection to ingest log events from the Object Storage bucket.
  • Verify the end-to-end event flow.

The following is the event flow that this tutorial configures:

  1. A resource change in the account generates an Activity Tracker Event Routing event.
  2. Activity Tracker Event Routing forwards the event to App Configuration through a dedicated app_config target and route.
  3. App Configuration processes the event through its configuration aggregator and publishes it to Event Notifications.
  4. Event Notifications filters events with a topic rule and archives them to a Object Storage bucket through an Object Storage destination and subscription.
  5. A Code Engine app detects the new file in the Object Storage bucket and forwards the event to Workload Protection, triggering a posture reconciliation for the affected resource.

Before you begin

Before you start, make sure that you have the following resources and access in place:

  • An existing IBM Cloud Security and Compliance Center Workload Protection instance with CSPM enabled and linked to an App Configuration instance. If you need to set this up first, see Getting started with Workload Protection.
  • An existing App Configuration instance with the Enterprise plan. The configuration aggregator feature that near real-time CSPM requires is only available on the Enterprise plan.
  • An Event Notifications instance with the Standard plan in the same region as your App Configuration instance.
  • A IBM Cloud Object Storage instance with a bucket to store the Event Notifications notification archive.
  • The IBM Cloud CLI with the following plug-ins installed:
    • atracker — run ibmcloud plugin install atracker to install.
    • event-notifications — run ibmcloud plugin install event-notifications to install.
    • code-engine — run ibmcloud plugin install code-engine to install.
    • cloud-object-storage - run ibmcloud plugin install cloud-object-storage to install.

The following IAM access is required:

Required IAM access for the tutorial steps
Service Platform role Service role
IBM Cloud® Identity and Access Management (IAM Identity) Operator —
IBM Cloud® Identity and Access Management (IAM Access Management) Administrator —
Activity Tracker Event Routing Editor —
App Configuration Editor Manager
Event Notifications Editor Manager
Object Storage Editor Manager
Code Engine Editor Manager
Container Registry — Reader
Workload Protection Editor —

Log in and set environment variables

Log in to IBM Cloud and export shell variables for the service identifiers that the remaining commands reference.

  1. Log in to IBM Cloud.

    ibmcloud login --sso
    
  2. Target the resource group that contains your existing services.

    ibmcloud target -g RESOURCE_GROUP_NAME
    
  3. Export your Workload Protection instance details. You can find the instance name and CRN on the instance details page, or by running ibmcloud resource service-instance WP_INSTANCE_NAME --output json.

    export WP_INSTANCE_NAME="YOUR_WP_INSTANCE_NAME"
    export WP_CRN="crn:v1:bluemix:public:sysdig-secure:REGION::a/ACCOUNT_ID:INSTANCE_GUID::"
    export WP_ENDPOINT="us-south.security-compliance-secure.cloud.ibm.com"
    export ACCOUNT_ID="YOUR_ACCOUNT_ID"
    export REGION="us-south"
    
  4. Export your App Configuration instance details. You can find the CRN and GUID on the Resource list by clicking on the instance's row, or by running ibmcloud resource service-instance APP_CONFIG_INSTANCE_NAME --output json.

    export APP_CONFIG_CRN="crn:v1:bluemix:public:apprapp:REGION::a/ACCOUNT_ID:INSTANCE_GUID::"
    export APP_CONFIG_GUID="INSTANCE_GUID"
    
  5. Export your Event Notifications instance details.

    export EN_INSTANCE_GUID="EN_INSTANCE_GUID"
    export EN_ENDPOINT="https://REGION.event-notifications.cloud.ibm.com"
    export EN_INSTANCE_CRN="EN_INSTANCE_CRN"
    
  6. Export your Object Storage instance and bucket details. Copy and save the bucket region — it is used to set up log ingestion in Workload Protection later.

    export COS_INSTANCE_NAME="YOUR_COS_INSTANCE_NAME"
    export COS_INSTANCE_GUID="COS_INSTANCE_GUID"
    export COS_INSTANCE_CRN="COS_INSTANCE_CRN"
    export COS_BUCKET_NAME="YOUR_COS_BUCKET_NAME"
    export COS_BUCKET_REGION="us-south"
    
  7. Optional (CDR): If you also want to enable Cloud Detection and Response, export the CDR Object Storage bucket details. You can reuse the same Object Storage bucket as near real-time CSPM or use a separate one.

    export CDR_COS_BUCKET_NAME="${COS_BUCKET_NAME}"
    export CDR_COS_INSTANCE_CRN="crn:v1:bluemix:public:cloud-object-storage:global::a/ACCOUNT_ID:COS_INSTANCE_GUID::"
    export CDR_COS_INSTANCE_GUID="${COS_INSTANCE_GUID}"
    

Create the Activity Tracker Event Routing to App Configuration authorization policy

Activity Tracker Event Routing must be authorized to write events to your App Configuration instance before you can create the target. Create a service-to-service (S2S) authorization policy that grants Activity Tracker Event Routing the Configuration Update Reporter role on your App Configuration instance.

ibmcloud iam authorization-policy-create atracker apprapp \
  "Configuration Update Reporter" \
  --target-service-instance-id ${APP_CONFIG_GUID}

Allow up to 2 minutes for the policy to propagate before you create the Activity Tracker Event Routing target in the next step. Creating the target before the policy is active causes an authorization error.

Create the Activity Tracker Event Routing targets and routes

Create the Activity Tracker Event Routing targets and routes that deliver events into the pipeline. The near real-time CSPM target sends events to App Configuration for posture reconciliation. The optional CDR target sends events directly to an Object Storage bucket for threat detection.

Activity Tracker Event Routing routes are additive. Each target receives its own independent copy of every event.

  1. Create the near real-time CSPM app_config target that points to your App Configuration instance.

    ibmcloud atracker target create \
      --name "my-rt-cspm-at-target" \
      --type app_config \
      --target-crn ${APP_CONFIG_CRN}
    

    Save the target ID from the command output.

    export AT_TARGET_ID="TARGET_ID_FROM_OUTPUT"
    
  2. Create the near real-time CSPM route that sends events from all regions — including global account-level events — to the App Configuration target.

    ibmcloud atracker route create \
      --name "my-rt-cspm-at-route" \
      --rules "[{\"locations\":[\"*\",\"global\"],\"target_ids\":[\"${AT_TARGET_ID}\"]}]"
    

    * captures all regional events and global captures account-level events such as IAM changes. Both are required for comprehensive posture coverage.

  3. (Optional) Create an IAM authorization policy that allows Activity Tracker Event Routing to write directly to the CDR Object Storage bucket. This policy is scoped to the specific bucket, not the entire Object Storage instance.

    ibmcloud iam authorization-policy-create atracker cloud-object-storage \
      "Object Writer" \
      --target-service-instance-id ${CDR_COS_INSTANCE_GUID} \
      --target-resource-type bucket \
      --target-resource ${CDR_COS_BUCKET_NAME}
    
  4. (Optional) Create the CDR cloud_object_storage target that points directly to the CDR Object Storage bucket. Replace <region> with the region of your CDR Object Storage bucket.

    ibmcloud atracker target create \
      --name "my-cdr-at-target" \
      --type cloud-object-storage \
      --endpoint "https://s3.<region>.cloud-object-storage.appdomain.cloud" \
      --target-crn "${CDR_COS_INSTANCE_CRN}" \
      --bucket "${CDR_COS_BUCKET_NAME}" \
      --service-to-service-enabled true
    

    Save the CDR target ID from the output.

    export CDR_AT_TARGET_ID="TARGET_ID_FROM_OUTPUT"
    
  5. (Optional) Create the CDR route.

    ibmcloud atracker route create \
      --name "my-cdr-at-route" \
      --rules "[{\"locations\":[\"*\",\"global\"],\"target_ids\":[\"${CDR_AT_TARGET_ID}\"]}]"
    

Integrate App Configuration with Event Notifications

Register your Event Notifications instance as an outbound integration in App Configuration. This enables App Configuration to emit a notification to Event Notifications whenever the config aggregator detects a resource change.

Before you connect the two services, create an S2S authorization policy that grants App Configuration the Event Source Manager role on Event Notifications.

  1. Create the S2S authorization policy.

    ibmcloud iam authorization-policy-create apprapp event-notifications \
      "Event Source Manager" \
      --source-service-instance-id ${APP_CONFIG_GUID} \
      --target-service-instance-id ${EN_INSTANCE_GUID}
    
  2. Register Event Notifications as an integration in App Configuration.

    ibmcloud ac integration-create \
      --guid ${APP_CONFIG_GUID} \
      --integration-id "my-en-ac-integration" \
      --integration-type EVENT_NOTIFICATIONS \
      --metadata "{\"event_notifications_instance_crn\": \"${EN_INSTANCE_CRN}\", \"event_notifications_endpoint\": \"${EN_ENDPOINT}\", \"event_notifications_source_name\": \"App Config Source\"}"
    

    This registers App Configuration as a source in your Event Notifications instance, which makes it available to select when you create the topic in the next step.

Create the Event Notifications IAM authorization policy for Object Storage

Event Notifications requires an S2S authorization policy before it can write notification archives to your Object Storage bucket. Both Object Writer and Reader roles are required. Including Object Writer alone causes an s2s_auth_invalid error when you create the Object Storage destination.

ibmcloud iam authorization-policy-create event-notifications cloud-object-storage \
  "Object Writer,Reader" \
  --source-service-instance-id ${EN_INSTANCE_GUID} \
  --target-service-instance-id ${COS_INSTANCE_GUID}

Wait at least 90 seconds after creating this policy before proceeding to create the Object Storage destination. Creating the destination before the policy propagates causes the creation to fail with an s2s_auth_invalid error.

Create the Event Notifications topic, destination, and subscription

Create an Event Notifications topic that filters for App Configuration configuration aggregator events, then create a Object Storage destination and subscribe the topic to it.

  1. Create the topic. The JSONPath filter $.com.ibm.cloud.apprapp.config_aggregator.* matches all event types that the config aggregator emits.

    ibmcloud en topic-create \
      --instance-id ${EN_INSTANCE_GUID} \
      --name "rt-cspm-topic" \
      --description "Routes AppConfig aggregator resource config-change events to RT CSPM subscribers" \
      --sources "[{\"id\":\"${APP_CONFIG_CRN}\",\"rules\":[{\"enabled\":true,\"event_type_filter\":\"$.*\",\"notification_filter\":\"$.type =~ 'com.ibm.cloud.apprapp.config_aggregator.*'\"}]}]"
    

    Save the topic ID from the command output.

    export EN_TOPIC_ID="TOPIC_ID_FROM_OUTPUT"
    
  2. Create the Object Storage destination.

    ibmcloud en destination-create \
      --instance-id ${EN_INSTANCE_GUID} \
      --name "rt-cspm-cos-destination" \
      --type ibmcos \
      --config "{\"params\":{\"bucket_name\":\"${COS_BUCKET_NAME}\",\"instance_id\":\"${COS_INSTANCE_GUID}\",\"endpoint\":\"https://s3.${COS_BUCKET_REGION}.cloud-object-storage.appdomain.cloud\"}}"
    

    Save the destination ID from the output.

    export EN_DESTINATION_ID="DESTINATION_ID_FROM_OUTPUT"
    
  3. Create a subscription that connects the topic to the Object Storage destination.

    ibmcloud en subscription-create \
      --instance-id ${EN_INSTANCE_GUID} \
      --name "rt-cspm-cos-sub" \
      --destination-id ${EN_DESTINATION_ID} \
      --topic-id ${EN_TOPIC_ID}
    

Set up the IBM Cloud Code Engine log ingestion app

Event Notifications archives notification payloads to Object Storage, but nothing forwards them to Workload Protection automatically. A Code Engine app subscribes to Object Storage bucket write events and forwards each new file to Workload Protection for posture reconciliation. This step sets up the app and the IAM objects it needs.

Create a service ID and API key

The Code Engine app uses a service ID and API key to authenticate when forwarding events to the Workload Protection ingestion endpoint.

  1. Create the Service ID.

    ibmcloud iam service-id-create send-rt-cspm-events-id \
      --description "Service ID for RT CSPM event forwarding"
    

    Save the ServiceId-xxx value from the output.

    export SERVICE_ID="ServiceId-xxx"
    
  2. Create a service ID API key.

    ibmcloud iam service-api-key-create send-rt-cspm-events-key send-rt-cspm-events-id \
      --description "API key for RT CSPM Code Engine app"
    

    Save the generated API key. It is only shown once.

    export SERVICE_API_KEY="API_KEY_FROM_OUTPUT"
    
  3. Grant the service ID Reader access to IBM Cloud Container Registry so that Code Engine can pull the app image.

    ibmcloud iam service-policy-create send-rt-cspm-events-id \
      --roles Reader \
      --service-name container-registry
    

Create a trusted profile

A trusted profile grants the Workload Protection instance and the Code Engine app read access to the Object Storage bucket without long-lived credentials.

  1. Create the trusted profile.

    ibmcloud iam trusted-profile-create ibm-rt-cspm-wp-cos \
      --description "Trusted profile for Workload Protection interaction with COS bucket"
    

    Save the profile ID from the output.

    export TRUSTED_PROFILE_ID="PROFILE_ID_FROM_OUTPUT"
    
  2. Assign a trust relationship for your Workload Protection instance.

    ibmcloud iam trusted-profile-identity-create ibm-rt-cspm-wp-cos \
      --id ${WP_CRN} \
      --id-type CRN
    
  3. Assign a trust relationship for the service ID.

    ibmcloud iam trusted-profile-identity-create ibm-rt-cspm-wp-cos \
      --id ${SERVICE_ID} \
      --id-type serviceid
    
  4. Grant the trusted profile read access to the Object Storage bucket.

    ibmcloud iam trusted-profile-policy-create ibm-rt-cspm-wp-cos \
      -r "Content Reader,Reader" \
      --service-name cloud-object-storage \
      --resource-type bucket \
      --resource ${COS_BUCKET_NAME}
    
  5. Grant the trusted profile Viewer access to the service ID.

    ibmcloud iam trusted-profile-policy-create ibm-rt-cspm-wp-cos \
      -r Viewer \
      --service-name iam-identity \
      --resource-type serviceid \
      --resource ${SERVICE_ID}
    

Create the Code Engine project and secrets

The Code Engine project must exist in the same region as your Object Storage bucket.

  1. Create a Code Engine project.

    ibmcloud ce project create --name rt-cspm-ce-project
    
  2. Create a secret to inject the service ID API key into the app.

    ibmcloud ce secret create \
      --name rt-cspm-secrets \
      --from-literal API_KEY=${SERVICE_API_KEY}
    
  3. Create a registry secret to allow Code Engine to pull the app image from IBM Cloud Container Registry.

    ibmcloud ce secret create \
      --name icr-secret \
      --format registry \
      --server icr.io \
      --username iamapikey \
      --password ${SERVICE_API_KEY} \
      --email noreply@rt-cspm-app.ibm.cloud
    

Create the Code Engine app

Deploy the notification app to Code Engine, using the secrets and trusted profile you created to authenticate and forward findings to your Workload Protection instance.

ibmcloud ce application create \
  --name "sccwp-rt-cspm-app" \
  --image icr.io/ext/sysdig/cdr-notification-app:latest \
  --min-scale 1 \
  --max-scale 10 \
  --cpu 0.125 \
  --memory 500M \
  --request-timeout 60 \
  --service-account default \
  --env TARGET_ACCOUNT_ID=${ACCOUNT_ID} \
  --env TRUSTED_PROFILE_ID=${TRUSTED_PROFILE_ID} \
  --env FORWARD_URL="https://${WP_ENDPOINT}/api/cloudingestion/webhooks/ibm/v1/${SERVICE_ID}" \
  --env-from-secret rt-cspm-secrets \
  --registry-secret icr-secret

Connect the Object Storage bucket to Code Engine

Grant Code Engine permission to manage notifications on the Object Storage instance, then create a subscription so the app is triggered each time Event Notifications writes a new archive file to the bucket.

  1. Create the authorization policy.

    ibmcloud iam authorization-policy-create codeengine cloud-object-storage \
      "Notifications Manager" \
      --source-service-instance-name rt-cspm-ce-project \
      --target-service-instance-name ${COS_INSTANCE_NAME}
    
  2. Create the Object Storage event subscription.

    ibmcloud ce subscription cos create \
      --name rt-cspm-cos-sub \
      --bucket ${COS_BUCKET_NAME} \
      --destination sccwp-rt-cspm-app \
      --event-type write
    

Configure log ingestion in Workload Protection

Configure Workload Protection to ingest log events from the Object Storage bucket. This tells Workload Protection where to look for new event files and which trusted profile and service ID to use for authentication.

ibmcloud resource service-instance-update "${WP_INSTANCE_NAME}" \
  -p '{"enable_cdr": true, "target_cdr_accounts": [{"cdr_bucket_region": "'${COS_BUCKET_REGION}'", "cdr_bucket_name": "'${COS_BUCKET_NAME}'", "cdr_trusted_profile_id": "'${TRUSTED_PROFILE_ID}'", "cdr_service_id": "'${SERVICE_ID}'", "cdr_ingestion_url": "https://'${WP_ENDPOINT}'/api/cloudingestion/webhooks/ibm/v1/'${SERVICE_ID}'", "account_id": "'${ACCOUNT_ID}'"}]}' \
  -g Default

Despite the enable_cdr field name in the command, this step configures log ingestion. This shared capability enables both near real-time CSPM posture reconciliation and CDR threat detection. You are not required to use CDR threat detection to complete near real-time CSPM setup.

Enable real-time collection in App Configuration by using the console

The previous steps configure real-time collection in App Configuration, but don't enable it. Enabling real-time collection is required for near real-time CSPM in Workload Protection. Complete the following steps in the console.

  1. In the IBM Cloud console, go to the Resource list.
  2. Find your App Configuration instance and click its name.
  3. Click Configuration aggregator.
  4. In the Collection modes section, turn on Real-time collection.

Verify that near real-time CSPM is working

Confirm that the end-to-end pipeline is active by triggering a resource configuration change and verifying that the event flows through each stage.

  1. Make a small, reversible configuration change. The following example adds a tag to your App Configuration instance.

    ibmcloud resource tag-attach \
      --resource-id ${APP_CONFIG_CRN} \
      --tag-names "rt-cspm-test"
    
  2. Wait 2–3 minutes for Activity Tracker Event Routing to capture the event and the pipeline to process it.

  3. List objects in your Object Storage bucket to confirm that a notification archive has arrived.

    ibmcloud cos config crn --crn "${COS_INSTANCE_CRN}" \
    ibmcloud cos objects --bucket "${COS_BUCKET_NAME}"
    

    You should see a new object in the bucket. Event Notifications stores the archived notifications with a prefix that has the same name as the Object Storage destination that you created earlier, rt-cspm-cos-destination.

    If no object appears after 5 minutes, verify that all three S2S authorization policies exist by running ibmcloud iam authorization-policies, and confirm that the Event Notifications topic filter is $.com.ibm.cloud.apprapp.config_aggregator.*.

  4. Wait 10–15 minutes after the object appears in the bucket for Workload Protection to process the event.

  5. In the IBM Cloud console, click the Navigation Menu icon Navigation Menu icon > Security > Compliance, and then click the name of your instance of Workload Protection.

  6. Click Open dashboard.

  7. Click Inventory to view the latest scan results. For more information, see Resources.

  8. Remove the test tag.

    ibmcloud resource tag-detach \
      --resource-id ${APP_CONFIG_CRN} \
      --tag-names "rt-cspm-test"
    

Next steps

Near real-time CSPM is now active. Workload Protection reconciles the posture of any resource that generates an Activity Tracker Event Routing event, reducing the delay between a configuration change and its posture evaluation from hours to minutes.

If you enabled CDR, create a threat detection policy to detect and respond to suspicious activity in your IBM Cloud environments. For more information, see Creating IBM Cloud threat detection policy.

Troubleshooting

If you run into problems while you complete this tutorial, see the following troubleshooting topics: