|
| 1 | +<!-- |
| 2 | + Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + or more contributor license agreements. See the NOTICE file |
| 4 | + distributed with this work for additional information |
| 5 | + regarding copyright ownership. The ASF licenses this file |
| 6 | + to you under the Apache License, Version 2.0 (the |
| 7 | + "License"); you may not use this file except in compliance |
| 8 | + with the License. You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, |
| 13 | + software distributed under the License is distributed on an |
| 14 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + KIND, either express or implied. See the License for the |
| 16 | + specific language governing permissions and limitations |
| 17 | + under the License. |
| 18 | +--> |
| 19 | + |
| 20 | +# GCP Security Analyzer |
| 21 | + |
| 22 | +This document describes the implementation of a security analyzer for Google Cloud Platform (GCP) resources. The analyzer is designed to enhance security monitoring within our GCP environment by capturing critical events and generating alerts for specific security-sensitive actions. |
| 23 | + |
| 24 | +## How It Works |
| 25 | + |
| 26 | +1. **Log Sinks**: The system uses [GCP Log Sinks](https://cloud.google.com/logging/docs/export/configure_export_v2) to capture specific security-related log entries. These sinks are configured to filter for events like IAM policy changes or service account key creation. |
| 27 | +2. **Log Storage**: The filtered logs are routed to a dedicated Google Cloud Storage (GCS) bucket for persistence and analysis. |
| 28 | +3. **Report Generation**: A scheduled job runs weekly, executing the `log_analyzer.py` script. |
| 29 | +4. **Email Alerts**: The script analyzes the logs from the past week, compiles a summary of security events, and sends a report to a configured email address. |
| 30 | + |
| 31 | +## Configuration |
| 32 | + |
| 33 | +The behavior of the log analyzer is controlled by a `config.yml` file. Here’s an overview of the configuration options: |
| 34 | + |
| 35 | +- `project_id`: The GCP project ID where the resources are located. |
| 36 | +- `bucket_name`: The name of the GCS bucket where logs will be stored. |
| 37 | +- `logging`: Configures the logging level and format for the script. |
| 38 | +- `sinks`: A list of log sinks to be created. Each sink has the following properties: |
| 39 | + - `name`: A unique name for the sink. |
| 40 | + - `description`: A brief description of what the sink monitors. |
| 41 | + - `filter_methods`: A list of GCP API methods to include in the filter (e.g., `SetIamPolicy`). |
| 42 | + - `excluded_principals`: A list of service accounts or user emails to exclude from monitoring, such as CI/CD service accounts. |
| 43 | + |
| 44 | +### Example Configuration (`config.yml`) |
| 45 | + |
| 46 | +```yaml |
| 47 | +project_id: your-gcp-project-id |
| 48 | +bucket_name: your-log-storage-bucket |
| 49 | + |
| 50 | +sinks: |
| 51 | + - name: iam-policy-changes |
| 52 | + description: Monitors changes to IAM policies. |
| 53 | + filter_methods: |
| 54 | + - "SetIamPolicy" |
| 55 | + excluded_principals: |
| 56 | + - "ci-cd-account@your-project.iam.gserviceaccount.com" |
| 57 | +``` |
| 58 | +
|
| 59 | +## Usage |
| 60 | +
|
| 61 | +The `log_analyzer.py` script provides two main commands for managing the security analyzer. |
| 62 | + |
| 63 | +### Initializing Sinks |
| 64 | + |
| 65 | +To create or update the log sinks in GCP based on your `config.yml` file, run the following command: |
| 66 | + |
| 67 | +```bash |
| 68 | +python log_analyzer.py --config config.yml initialize |
| 69 | +``` |
| 70 | + |
| 71 | +This command ensures that the log sinks are correctly configured to capture the desired security events. |
| 72 | + |
| 73 | +### Generating Weekly Reports |
| 74 | + |
| 75 | +To generate and send the weekly security report, run this command: |
| 76 | + |
| 77 | +```bash |
| 78 | +python log_analyzer.py --config config.yml generate-report |
| 79 | +``` |
| 80 | + |
| 81 | +This is typically run as a scheduled job (GitHub Action) to automate the delivery of weekly security reports. |
| 82 | + |
| 83 | + |
| 84 | + |
0 commit comments