Skip to content

shiftcmd/GCP_audit

Repository files navigation

🍊 Citrus IO - GCP Infrastructure Audit Tool

A comprehensive Google Cloud Platform (GCP) infrastructure auditing tool

   _______ __                     ________ 
  / ____(_) /________  _______   /  _/ __ \
 / /   / / __/ ___/ / / / ___/   / // / / /
/ /___/ / /_/ /  / /_/ (__  )  _/ // /_/ / 
\____/_/\__/_/   \__,_|____/  /___/\____/  

✨ Features

  • πŸš€ Auto-discovery: Automatically finds all accessible GCP projects
  • πŸ” Comprehensive auditing: Covers IAM, compute, storage, networking, and more
  • πŸ“Š Detailed reporting: Generates JSON reports with timestamped data
  • πŸ“ Organized output: Creates structured audit reports directory

πŸ› οΈ What Gets Audited

Project-Level Resources

  • βœ… Enabled APIs and services
  • βœ… IAM policies and bindings
  • βœ… Service accounts and configurations

Compute Resources

  • βœ… Virtual Machine instances
  • βœ… Instance metadata and configurations
  • βœ… Compute zones and regions

Storage & Databases

  • βœ… Cloud Storage buckets
  • βœ… Cloud SQL instances
  • βœ… Storage policies and permissions

Networking

  • βœ… VPC networks and subnetworks
  • βœ… Firewall rules and priorities
  • βœ… Network routing configurations

Container Services

  • βœ… Google Kubernetes Engine (GKE) clusters
  • βœ… Node pools and configurations

πŸš€ Quick Start

Prerequisites

  • Python 3.7+
  • Google Cloud SDK (gcloud)
  • GCP project access with appropriate permissions

Installation

  1. Clone the repository:

    git clone <your-repo-url>
    cd GCP_audit
  2. Install dependencies:

    pip install -r requirements.txt
  3. Authenticate with GCP:

    gcloud auth application-default login

Usage

Audit all accessible projects:

python gcp_audit_script.py

Audit specific projects:

python gcp_audit_script.py --projects project-1 project-2

Use service account credentials:

python gcp_audit_script.py --credentials /path/to/service-account-key.json

πŸ“Š Sample Output

[19:10:39] πŸš€ Initializing GCP Auditor...
[19:10:39] πŸ” Using Application Default Credentials
[19:10:39] πŸ”§ Initializing GCP clients...
[19:10:51] βœ… All clients initialized successfully

   _______ __                     ________ 
  / ____(_) /________  _______   /  _/ __ \
 / /   / / __/ ___/ / / / ___/   / // / / /
/ /___/ / /_/ /  / /_/ (__  )  _/ // /_/ / 
\____/_/\__/_/   \__,_|____/  /___/\____/  

[19:10:51] πŸš€ Starting GCP Infrastructure Audit...
[19:10:51] πŸ“‹ Will audit 3 projects
[19:10:51] πŸ“Š [1/3] Processing project: production-app
[19:10:51] πŸ” Auditing project: production-app
[19:10:51]   πŸ”Œ Getting enabled APIs for production-app
[19:10:51]     βœ… Found 25 enabled APIs
[19:10:51]   πŸ” Getting IAM policy for production-app
[19:10:52]     βœ… Found 12 IAM bindings
[19:10:52]   πŸ’» Getting compute instances for production-app
[19:10:53]     βœ… Found 5 compute instances

πŸ” Required Permissions

The tool requires the following IAM roles:

For Read-Only Auditing

roles/viewer
roles/iam.securityReviewer
roles/serviceusage.serviceUsageViewer

For Organization-Level Access

roles/resourcemanager.organizationViewer
roles/resourcemanager.folderViewer

πŸ“ Output Structure

Reports are saved in the audit_reports/ directory:

audit_reports/
└── gcp_audit_report_20241227_191051.json

Report Format

{
  "audit_metadata": {
    "timestamp": "2024-12-27T19:10:51",
    "auditor_version": "1.0.0",
    "projects_audited": 3
  },
  "projects": {
    "project-id": {
      "project_id": "project-id",
      "enabled_apis": [...],
      "iam_policy": {...},
      "service_accounts": [...],
      "compute_instances": [...],
      "storage_buckets": [...],
      "network_info": {...}
    }
  }
}

πŸ›‘οΈ Security Features

  • Credential Protection: Never logs or stores credentials
  • Safe Defaults: Read-only operations by default
  • Error Handling: Graceful handling of permission errors
  • Audit Trail: Comprehensive logging of all operations

πŸ”§ Configuration

Environment Variables

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account-key.json
export GOOGLE_CLOUD_PROJECT=default-project-id

Command Line Options

python gcp_audit_script.py --help

optional arguments:
  --credentials PATH    Path to service account JSON file
  --projects [PROJECT_IDS ...]  Specific project IDs to audit
  --output FILENAME     Output file name (default: timestamped)

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

--⚠️ Important: This tool performs read-only operations by default. Always test in non-production environments first.

About

Pull (most) GCP permissions and setting from a Google Cloud Platform project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages