Collect Salesforce Commerce Cloud logs
This document explains how to ingest Salesforce Commerce Cloud logs to Google Security Operations using Google Cloud Storage V2.
Salesforce Commerce Cloud is an e-commerce platform that generates transaction, access, and security audit logs. A Cloud Run function connects to the Salesforce Commerce Cloud WebDAV endpoint on a schedule, downloads log files, writes them to a GCS bucket in NDJSON format, and Google SecOps ingests them through a GCS V2 feed.
Before you begin
Mkae sure you have the following prerequisites:
- A Google SecOps instance
- A GCP project with Cloud Storage API enabled
- Permissions to create and manage GCS buckets
- Permissions to manage IAM policies on GCS buckets
- Permissions to create Cloud Run services, Pub/Sub topics, and Cloud Scheduler jobs
- Privileged access to Salesforce Commerce Cloud Business Manager with WebDAV access permission
Create Google Cloud Storage bucket
- Go to the Google Cloud Console.
- Select your project or create a new one.
- In the navigation menu, go to Cloud Storage > Buckets.
- Click Create bucket.
Provide the following configuration details:
Setting Value Name your bucket Enter a globally unique name (for example, sfcc-logs)Location type Choose based on your needs (Region, Dual-region, Multi-region) Location Select the location (for example, us-central1)Storage class Standard (recommended for frequently accessed logs) Access control Uniform (recommended) Protection tools Optional: Enable object versioning or retention policy Click Create.
Collect Salesforce Commerce Cloud credentials
Configure WebDAV access
- Sign in to Business Manager for your Salesforce Commerce Cloud instance.
- Go to Administration > Organization > Roles & Permissions.
- Verify that your user account has the WebDAV File Access permission enabled.
- Note your SFCC instance hostname (for example,
development-yoursite-dw.demandware.net). Save the following credentials in a secure location:
- SFCC Host: Your instance hostname (for example,
development-yoursite-dw.demandware.net). - Username: Your Business Manager username.
- Password: Your Business Manager password.
- SFCC Host: Your instance hostname (for example,
Verify permissions
To verify the account has the required permissions:
- Sign in to Business Manager for your Salesforce Commerce Cloud instance.
- Go to Administration > Site Development > Development Setup.
- Click Log Files under the WebDAV section.
- If you can see log file directories, you have the required permissions.
- If you cannot see this option, contact your SFCC administrator to grant WebDAV access.
Test API access
Test your credentials before proceeding with the integration:
# Replace with your actual credentials SFCC_HOST="development-yoursite-dw.demandware.net" USERNAME="your-username" PASSWORD="your-password" # Test WebDAV access to log directory curl -v -u "${USERNAME}:${PASSWORD}" \ "https://${SFCC_HOST}/on/demandware.servlet/webdav/Sites/Logs/"
Create service account for Cloud Run function
The Cloud Run function needs a service account with permissions to write to GCS bucket and be invoked by Pub/Sub.
Create service account
- In the GCP Console, go to IAM & Admin > Service Accounts.
- Click Create Service Account.
- Provide the following configuration details:
- Service account name: Enter
sfcc-logs-collector-sa. - Service account description: Enter
Service account for Cloud Run function to collect Salesforce Commerce Cloud logs.
- Service account name: Enter
- Click Create and Continue.
- In the Grant this service account access to project section, add the following roles:
- Click Select a role.
- Search for and select Storage Object Admin.
- Click + Add another role.
- Search for and select Cloud Run Invoker.
- Click + Add another role.
- Search for and select Cloud Functions Invoker.
- Click Continue.
- Click Done.
These roles are required for:
- Storage Object Admin: Write logs to GCS bucket and manage state files
- Cloud Run Invoker: Allow Pub/Sub to invoke the function
- Cloud Functions Invoker: Allow function invocation
Grant IAM permissions on GCS bucket
Grant the service account write permissions on the GCS bucket:
- Go to Cloud Storage > Buckets.
- Click your bucket name (for example,
sfcc-logs). - Go to the Permissions tab.
- Click Grant access.
- Provide the following configuration details:
- Add principals: Enter the service account email (for example,
sfcc-logs-collector-sa@your-project.iam.gserviceaccount.com). - Assign roles: Select Storage Object Admin.
- Add principals: Enter the service account email (for example,
- Click Save.
Create Pub/Sub topic
Create a Pub/Sub topic that Cloud Scheduler will publish to and the Cloud Run function will subscribe to.
- In the GCP Console, go to Pub/Sub > Topics.
- Click Create topic.
- Provide the following configuration details:
- Topic ID: Enter
sfcc-logs-trigger. - Leave other settings as default.
- Topic ID: Enter
- Click Create.
Create Cloud Run function to collect logs
The Cloud Run function will be triggered by Pub/Sub messages from Cloud Scheduler to fetch logs from Salesforce Commerce Cloud WebDAV and write them to GCS.
- In the GCP Console, go to Cloud Run.
- Click Create service.
- Select Function (use an inline editor to create a function).
In the Configure section, provide the following configuration details:
Setting Value Service name sfcc-logs-collectorRegion Select region matching your GCS bucket (for example, us-central1)Runtime Select Python 3.12 or later In the Trigger (optional) section:
- Click + Add trigger.
- Select Cloud Pub/Sub.
- In Select a Cloud Pub/Sub topic, choose the topic
sfcc-logs-trigger. - Click Save.
In the Authentication section:
- Select Require authentication.
- Check Identity and Access Management (IAM).
Scroll down and expand Containers, Networking, Security.
Go to the Security tab:
- Service account: Select the service account
sfcc-logs-collector-sa.
- Service account: Select the service account
Go to the Containers tab:
- Click Variables & Secrets.
- Click + Add variable for each environment variable:
Variable Name Example Value Description GCS_BUCKETsfcc-logsGCS bucket name GCS_PREFIXsfccPrefix for log files STATE_KEYsfcc/state.jsonState file path SFCC_HOSTdevelopment-yoursite-dw.demandware.netSFCC instance hostname SFCC_USERNAMEyour-usernameBusiness Manager username SFCC_PASSWORDyour-passwordBusiness Manager password LOG_DIRSsecurity,error,warn,customerrorComma-separated log directories LOOKBACK_HOURS24Initial lookback period Scroll down in the Variables & Secrets tab to Requests:
- Request timeout: Enter
600seconds (10 minutes).
- Request timeout: Enter
Go to the Settings tab in Containers:
- In the Resources section:
- Memory: Select 512 MiB or higher.
- CPU: Select 1.
- Click Done.
- In the Resources section:
Scroll down to Execution environment:
- Select Default (recommended).
In the Revision scaling section:
- Minimum number of instances: Enter
0. - Maximum number of instances: Enter
100(or adjust based on expected load).
- Minimum number of instances: Enter
Click Create.
Wait for the service to be created (1-2 minutes).
After the service is created, the inline code editor will open automatically.
Add function code
- Enter main in Function entry point.
In the inline code editor, create two files:
First file - main.py:
import functions_framework from google.cloud import storage import json import os import urllib3 from datetime import datetime, timezone, timedelta import time import base64 import re # Initialize HTTP client with timeouts http = urllib3.PoolManager( timeout=urllib3.Timeout(connect=10.0, read=60.0), retries=False, ) # Initialize Storage client storage_client = storage.Client() # Environment variables GCS_BUCKET = os.environ.get('GCS_BUCKET') GCS_PREFIX = os.environ.get('GCS_PREFIX', 'sfcc') STATE_KEY = os.environ.get('STATE_KEY', 'sfcc/state.json') SFCC_HOST = os.environ.get('SFCC_HOST') SFCC_USERNAME = os.environ.get('SFCC_USERNAME') SFCC_PASSWORD = os.environ.get('SFCC_PASSWORD') LOG_DIRS = [d.strip() for d in os.environ.get('LOG_DIRS', 'security,error,warn,customerror').split(',') if d.strip()] LOOKBACK_HOURS = int(os.environ.get('LOOKBACK_HOURS', '24')) def parse_datetime(value: str) -> datetime: """Parse ISO datetime string to datetime object.""" if value.endswith("Z"): value = value[:-1] + "+00:00" return datetime.fromisoformat(value) @functions_framework.cloud_event def main(cloud_event): """ Cloud Run function triggered by Pub/Sub to fetch Salesforce Commerce Cloud logs via WebDAV and write to GCS. Args: cloud_event: CloudEvent object containing Pub/Sub message """ if not all([GCS_BUCKET, SFCC_HOST, SFCC_USERNAME, SFCC_PASSWORD]): print('Error: Missing required environment variables') return try: bucket = storage_client.bucket(GCS_BUCKET) # Load state state = load_state(bucket, STATE_KEY) now = datetime.now(timezone.utc) last_time = None if isinstance(state, dict) and state.get("last_event_time"): try: last_time = parse_datetime(state["last_event_time"]) except Exception as e: print(f"Warning: Could not parse last_event_time: {e}") if last_time is None: last_time = now - timedelta(hours=LOOKBACK_HOURS) print(f"Fetching logs since {last_time.isoformat()}") # Build auth header credentials = f"{SFCC_USERNAME}:{SFCC_PASSWORD}" encoded_credentials = base64.b64encode(credentials.encode('utf-8')).decode('utf-8') headers = { 'Authorization': f'Basic {encoded_credentials}', 'User-Agent': 'GoogleSecOps-SFCCCollector/1.0' } total_files = 0 webdav_base = f"https://{SFCC_HOST}/on/demandware.servlet/webdav/Sites/Logs" for log_dir in LOG_DIRS: print(f"Processing log directory: {log_dir}") files_processed = fetch_and_upload_logs( bucket=bucket, webdav_base=webdav_base, log_dir=log_dir, headers=headers, since=last_time, now=now, ) total_files += files_processed if total_files == 0: print("No new log files found.") else: print(f"Successfully processed {total_files} log files") save_state(bucket, STATE_KEY, now.isoformat()) except Exception as e: print(f'Error processing logs: {str(e)}') raise def load_state(bucket, key): """Load state from GCS.""" try: blob = bucket.blob(key) if blob.exists(): state_data = blob.download_as_text() return json.loads(state_data) except Exception as e: print(f"Warning: Could not load state: {e}") return {} def save_state(bucket, key, last_event_time_iso: str): """Save the last event timestamp to GCS state file.""" try: state = {'last_event_time': last_event_time_iso} blob = bucket.blob(key) blob.upload_from_string( json.dumps(state, indent=2), content_type='application/json' ) print(f"Saved state: last_event_time={last_event_time_iso}") except Exception as e: print(f"Warning: Could not save state: {e}") def list_webdav_files(webdav_url: str, headers: dict): """List files in a WebDAV directory using PROPFIND.""" backoff = 1.0 max_retries = 3 for attempt in range(max_retries): response = http.request('PROPFIND', webdav_url, headers={**headers, 'Depth': '1'}) if response.status == 429: retry_after = int(response.headers.get('Retry-After', str(int(backoff)))) print(f"Rate limited (429). Retrying after {retry_after}s...") time.sleep(retry_after) backoff = min(backoff * 2, 30.0) continue if response.status not in (200, 207): print(f"HTTP Error listing {webdav_url}: {response.status}") return [] content = response.data.decode('utf-8') # Parse file names from WebDAV PROPFIND XML response files = re.findall(r'<D:href>([^<]+)</D:href>', content) return [f for f in files if not f.endswith('/')] return [] def fetch_and_upload_logs(bucket, webdav_base: str, log_dir: str, headers: dict, since: datetime, now: datetime): """ Fetch log files from a WebDAV directory and upload to GCS. Args: bucket: GCS bucket object webdav_base: WebDAV base URL log_dir: Log directory name headers: HTTP headers with auth since: Only process files newer than this now: Current time for file naming Returns: Number of files processed """ dir_url = f"{webdav_base}/{log_dir}/" files = list_webdav_files(dir_url, headers) files_processed = 0 backoff = 1.0 for file_path in files: file_name = file_path.split('/')[-1] if not file_name: continue # Download file file_url = f"https://{SFCC_HOST}{file_path}" response = http.request('GET', file_url, headers=headers) if response.status == 429: retry_after = int(response.headers.get('Retry-After', str(int(backoff)))) print(f"Rate limited (429). Retrying after {retry_after}s...") time.sleep(retry_after) backoff = min(backoff * 2, 30.0) response = http.request('GET', file_url, headers=headers) if response.status != 200: print(f"Error downloading {file_name}: {response.status}") continue backoff = 1.0 content = response.data if not content: continue # Upload to GCS timestamp = now.strftime('%Y%m%d_%H%M%S') object_key = f"{GCS_PREFIX}/{log_dir}/{file_name}_{timestamp}" blob = bucket.blob(object_key) # Convert log lines to NDJSON lines = content.decode('utf-8', errors='replace').splitlines() records = [] for line in lines: line = line.strip() if line: try: record = json.loads(line) except json.JSONDecodeError: record = {'raw_log': line, 'log_dir': log_dir, 'source_file': file_name} records.append(record) if records: ndjson = '\n'.join([json.dumps(r, ensure_ascii=False) for r in records]) + '\n' blob.upload_from_string(ndjson, content_type='application/x-ndjson') print(f"Uploaded {len(records)} records from {file_name} to gs://{GCS_BUCKET}/{object_key}") files_processed += 1 return files_processedSecond file - requirements.txt:
functions-framework==3.* google-cloud-storage==2.* urllib3>=2.0.0
Click Deploy to save and deploy the function.
Wait for deployment to complete (2-3 minutes).
Create Cloud Scheduler job
Cloud Scheduler will publish messages to the Pub/Sub topic at regular intervals, triggering the Cloud Run function.
- In the GCP Console, go to Cloud Scheduler.
- Click Create Job.
Provide the following configuration details:
Setting Value Name sfcc-logs-collector-hourlyRegion Select same region as Cloud Run function Frequency 0 * * * *(every hour, on the hour)Timezone Select timezone (UTC recommended) Target type Pub/Sub Topic Select the topic sfcc-logs-triggerMessage body {}(empty JSON object)Click Create.
Schedule frequency options
Choose frequency based on log volume and latency requirements:
| Frequency | Cron Expression | Use Case |
|---|---|---|
| Every 5 minutes | */5 * * * * |
High-volume, low-latency |
| Every 15 minutes | */15 * * * * |
Medium volume |
| Every hour | 0 * * * * |
Standard (recommended) |
| Every 6 hours | 0 */6 * * * |
Low volume, batch processing |
| Daily | 0 0 * * * |
Historical data collection |
Test the integration
- In the Cloud Scheduler console, find your job (
sfcc-logs-collector-hourly). - Click Force run to trigger manually.
- Wait a few seconds and go to Cloud Run > Services > sfcc-logs-collector > Logs.
Verify the function executed successfully. Look for:
Fetching logs since YYYY-MM-DDTHH:MM:SS+00:00 Processing log directory: security Uploaded X records from filename.log to gs://sfcc-logs/sfcc/security/filename.log_YYYYMMDD_HHMMSS Successfully processed X log filesCheck the GCS bucket (
sfcc-logs) to confirm logs were written.
If you see errors in the logs:
- HTTP 401: Check SFCC credentials in environment variables
- HTTP 403: Verify account has WebDAV File Access permission in Business Manager
- HTTP 429: Rate limiting - function will automatically retry with backoff
- Missing environment variables: Check all required variables are set
Configure a feed in Google SecOps to ingest Salesforce Commerce Cloud logs
- Go to SIEM Settings > Feeds.
- Click Add New Feed.
- Click Configure a single feed.
- In the Feed name field, enter a name for the feed (for example,
Salesforce Commerce Cloud Logs). - Select Google Cloud Storage V2 as the Source type.
- Select Salesforce Commerce Cloud as the Log type.
Click Get Service Account. A unique service account email will be displayed, for example:
chronicle-12345678@chronicle-gcp-prod.iam.gserviceaccount.comCopy this email address. You will use it in the next step.
Click Next.
Specify values for the following input parameters:
Storage bucket URL: Enter the GCS bucket URI with the prefix path:
gs://sfcc-logs/sfcc/- Replace:
sfcc-logs: Your GCS bucket name.sfcc/: Prefix/folder path where logs are stored.
- Replace:
Source deletion option: Select the deletion option according to your preference:
- Never: Never deletes any files after transfers (recommended for testing).
- Delete transferred files: Deletes files after successful transfer.
Delete transferred files and empty directories: Deletes files and empty directories after successful transfer.
Maximum File Age: Include files modified in the last number of days (default is 180 days).
Asset namespace: The asset namespace.
Ingestion labels: The label to be applied to the events from this feed.
Click Next.
Review your new feed configuration in the Finalize screen, and then click Submit.
Grant IAM permissions to the Google SecOps service account
The Google SecOps service account needs Storage Object Viewer role on your GCS bucket.
- Go to Cloud Storage > Buckets.
- Click your bucket name (
sfcc-logs). - Go to the Permissions tab.
- Click Grant access.
- Provide the following configuration details:
- Add principals: Paste the Google SecOps service account email.
- Assign roles: Select Storage Object Viewer.
Click Save.
UDM mapping table
| Log Field | UDM Mapping | Logic |
|---|---|---|
auth.mechanism |
extensions.auth.mechanism |
Merged |
csv_format |
extensions.auth.mechanism |
Mapped: false → auth.mechanism |
event_id |
extensions.auth.mechanism |
Mapped: Login: Success → auth.mechanism |
mechanism |
extensions.auth.mechanism |
Merged |
LoginType |
extensions.auth.type |
Mapped: Application → AUTHTYPE_UNSPECIFIED |
csv_format |
extensions.auth.type |
Mapped: false → AUTHTYPE_UNSPECIFIED |
event_id |
extensions.auth.type |
Mapped values (6 total, e.g. ` "Login", "LoginAsEvent", "IdentityVerificationEvent", "LoginE... |
eventType.name |
metadata.description |
Directly mapped |
metadata_description |
metadata.description |
Directly mapped |
collected_timestamp |
metadata.event_timestamp |
Parsed as yyyyMMddHHmmss |
createdAt |
metadata.event_timestamp |
Parsed as UNIX_MS |
createdDate |
metadata.event_timestamp |
Parsed as yyyy-MM-ddTHH:mm:ss.SSS |
timestamp |
metadata.event_timestamp |
Parsed as yyyyMMddHHmmss |
ts_date |
metadata.event_timestamp |
Parsed as yyyy-MM-dd HH:mm:ss.SSSZ |
csv_format |
metadata.event_type |
Mapped: false → USER_LOGIN, false → USER_LOGOUT, false → `USER_RESOURCE_UPDATE_CON... |
event_id |
metadata.event_type |
Mapped: Login: Success → USER_LOGIN, Logout → USER_LOGOUT |
event_type |
metadata.event_type |
Directly mapped |
label |
metadata.ingestion_labels |
Merged |
resource_name |
metadata.ingestion_labels |
Mapped: `"ReportEvent","SessionHijackingEventStore","BulkApiResultEventStore","CredentialStu... |
attrs.cat |
metadata.product_event_type |
Renamed/mapped |
eventType.id |
metadata.product_event_type |
Directly mapped |
event_id |
metadata.product_event_type |
Directly mapped |
event_identifier |
metadata.product_log_id |
Directly mapped |
id |
metadata.product_log_id |
Directly mapped |
protocol |
network.application_protocol |
Directly mapped |
transaction_id |
network.dhcp.transaction_id |
Directly mapped |
referral_url |
network.http.referral_url |
Directly mapped |
request_status |
network.http.response_code |
Directly mapped |
attrs.Application |
principal.application |
Renamed/mapped |
enterpriseId |
principal.group.product_object_id |
Directly mapped |
attrs.src |
principal.ip |
Merged |
csv_format |
principal.ip |
Mapped: false → attrs.src |
event_id |
principal.ip |
Mapped: Login: Success → attrs.src |
Status_LK |
principal.labels |
Merged |
Status_LK |
principal.resource.attribute.labels |
Merged |
browser_name |
principal.resource.name |
Directly mapped |
memberId |
principal.resource.product_object_id |
Directly mapped |
principal_resource_type |
principal.resource.type |
Directly mapped |
attrs.usrName |
principal.user.email_addresses |
Merged |
csv_format |
principal.user.email_addresses |
Mapped: false → attrs.usrName |
src_email |
principal.user.email_addresses |
Merged |
attrs.USER_ID_DERIVED |
principal.user.product_object_id |
Renamed/mapped |
employee.employeeName |
principal.user.user_display_name |
Directly mapped |
user_display_name |
principal.user.user_display_name |
Directly mapped |
attrs.usrName |
principal.user.userid |
Directly mapped |
employee.userName |
principal.user.userid |
Directly mapped |
login_key |
principal.user.userid |
Directly mapped |
user_id |
principal.user.userid |
Directly mapped |
csv_format |
security_result |
Mapped: false → sec_result |
event_id |
security_result |
Mapped: Login: Success → sec_result |
sec_result |
security_result |
Merged |
sr |
security_result |
Merged |
action |
security_result.action |
Merged |
eventSource.name |
src.resource.name |
Directly mapped |
eventSource.id |
src.resource.product_object_id |
Directly mapped |
organization_id |
target.administrative_domain |
Directly mapped |
target_hostname |
target.asset.hostname |
Directly mapped |
device_id |
target.asset_id |
Directly mapped |
target_hostname |
target.hostname |
Directly mapped |
call_time |
target.resource.attribute.labels |
Merged |
cpu |
target.resource.attribute.labels |
Merged |
db_cpu |
target.resource.attribute.labels |
Merged |
db_type |
target.resource.attribute.labels |
Merged |
duration_time |
target.resource.attribute.labels |
Merged |
entry_p |
target.resource.attribute.labels |
Merged |
exe_time |
target.resource.attribute.labels |
Merged |
no_sql_que |
target.resource.attribute.labels |
Merged |
ope |
target.resource.attribute.labels |
Merged |
rows_proc |
target.resource.attribute.labels |
Merged |
run |
target.resource.attribute.labels |
Merged |
ses_level |
target.resource.attribute.labels |
Merged |
ss_type |
target.resource.attribute.labels |
Merged |
total_time |
target.resource.attribute.labels |
Merged |
user_ty |
target.resource.attribute.labels |
Merged |
verify_method |
target.resource.attribute.labels |
Merged |
attrs.AccountId |
target.resource.id |
Renamed/mapped |
attrs.CaseId |
target.resource.id |
Renamed/mapped |
attrs.ContactId |
target.resource.id |
Renamed/mapped |
eventSource.id |
target.resource.id |
Directly mapped |
request_id |
target.resource.id |
Directly mapped |
eventSource.name |
target.resource.name |
Directly mapped |
object.name |
target.resource.name |
Directly mapped |
resource_name |
target.resource.name |
Directly mapped |
object.id |
target.resource.product_object_id |
Directly mapped |
event_id |
target.resource.resource_type |
Mapped: PlatformEncryption → ACCESS_POLICY, ApexCallout → ACCESS_POLICY, `ApexTrigge... |
target_resource_type |
target.resource.resource_type |
Directly mapped |
event_id |
target.resource.type |
Mapped: (QueuedExecution/ApexExecution) → BATCH, ApexTrigger → DATABASE_TRIGGER, `Co... |
attrs.LoginUrl |
target.url |
Renamed/mapped |
attrs.attributes.url |
target.url |
Renamed/mapped |
uri |
target.url |
Directly mapped |
attrs.usrName |
target.user.email_addresses |
Merged |
csv_format |
target.user.email_addresses |
Mapped: false → attrs.usrName |
event_id |
target.user.email_addresses |
Mapped: Logout → attrs.usrName |
target_user_display_name |
target.user.user_display_name |
Directly mapped |
target_user_name |
target.user.userid |
Directly mapped |
| N/A | extensions.auth.auth_details |
Constant: ACTIVE |
| N/A | extensions.auth.type |
Constant: SSO |
| N/A | metadata.event_type |
Constant: GENERIC_EVENT |
| N/A | metadata.product_name |
Constant: SALESFORCE |
| N/A | metadata.vendor_name |
Constant: SALESFORCE |
| N/A | target.resource.resource_type |
Constant: ACCESS_POLICY |
| N/A | target.resource.type |
Constant: BATCH |
Need more help? Get answers from Community members and Google SecOps professionals.