Example code for working with Google Security Operations (SecOps)
Example code to implement security data pipeline health checks with Google SecOps.
Please refer to the following blog series for further details and context: Practical Techniques for Monitoring Your Security Data Pipeline (Part 1, Part 2)
This example code can be customized and executed in Google Cloud Run Functions, an automation tool, or a CI/CD pipeline to validate that your security logging, ingestion, search, detection, and alerting capabilities are working properly. Refer to the above blog series for additional context and examples.
Authenticates to GitHub's API and performs a basic read operation (retrieves the information for a GitHub organization) to generate an event in GitHub Enterprise's audit log.
- The name of the GitHub organization to retrieve
- The GitHub Personal Access Token that has the permissions required to retrieve information for the specified GitHub organization
Validates that the event generated by github/health-check-github-ping is searchable in Google SecOps.
- Set the
GOOGLE_SECOPS_API_BASE_URLvariable to your regional service endpoint for Google SecOps' REST API - For example, the base URL for the regional service endpoint in the US is https://us-chronicle.googleapis.com/v1alpha and the base URL for the regional service endpoint in Europe is https://eu-chronicle.googleapis.com/v1alpha
- Set the
GOOGLE_SECOPS_INSTANCEvariable as follows:projects/{google-cloud-project-id}/locations/{google-secops-instance-location}/instances/{google-secops-instance-id}- Replace the
{google-cloud-project-id}placeholder with your Google Cloud project ID that is linked to your Google SecOps instance. - Replace the
{google-secops-instance-location}placeholder with the location where your Google SecOps instance is running (e.g.usfor the United States). - Replace the
google-secops-instance-idplaceholder with the Customer ID for your Google SecOps instance. You can find this underSettings-SIEM Settings-Profilein Google SecOps's UI.
- Replace the
- Set the
GOOGLE_SECOPS_AUTHORIZATION_SCOPESvariable toAUTHORIZATION_SCOPES={"CHRONICLE_API":["https://www.googleapis.com/auth/cloud-platform"]} - Refer to the Authentication methods at Google documentation for information on OAuth 2.0 scopes
- Sets the start time to search for events in Google SecOps
- For example, a value of
1will specify a start time for the search that is 1 hour ago from the current time
- The service account key to authenticate to Google SecOps' REST API
Validates that github/health-check-github-ping triggered a detection & alert in Google SecOps.
- Set the
GOOGLE_SECOPS_API_BASE_URLvariable to your regional service endpoint for Google SecOps' REST API - For example, the base URL for the regional service endpoint in the US is https://us-chronicle.googleapis.com/v1alpha and the base URL for the regional service endpoint in Europe is https://eu-chronicle.googleapis.com/v1alpha
- Set the
GOOGLE_SECOPS_INSTANCEvariable as follows:projects/{google-cloud-project-id}/locations/{google-secops-instance-location}/instances/{google-secops-instance-id}- Replace the
{google-cloud-project-id}placeholder with your Google Cloud project ID that is linked to your Google SecOps instance. - Replace the
{google-secops-instance-location}placeholder with the location where your Google SecOps instance is running (e.g.usfor the United States). - Replace the
google-secops-instance-idplaceholder with the Customer ID for your Google SecOps instance. You can find this underSettings-SIEM Settings-Profilein Google SecOps's UI.
- Replace the
- Set the
GOOGLE_SECOPS_AUTHORIZATION_SCOPESvariable toAUTHORIZATION_SCOPES={"CHRONICLE_API":["https://www.googleapis.com/auth/cloud-platform"]} - Refer to the Authentication methods at Google documentation for information on OAuth 2.0 scopes
- The unique ID of your GitHub health check rule in Google SecOps (e.g.
ru_12345678-1234-1234-1234-abcd12345678)
- Sets the start time to search for detections and alerts generated by your health check rule in Google SecOps
- For example, a value of
1will specify a start time for the search that is 1 hour ago from the current time
- The service account key to authenticate to Google SecOps' REST API