|
1 |
| -# gcp-iam-collector |
2 |
| -Python scripts for collecting and visualising [Google Cloud Platform](https://cloud.google.com/) IAM permissions |
| 1 | +# GCP IAM Visualizer |
3 | 2 |
|
4 |
| -GCP IAM graph is created using [vis.js](http://visjs.org/) and it's static HTML page, see [example interactive graph](https://storage.googleapis.com/gcp-iam-collector/iam_graph_example.html) |
| 3 | +Creates an interactive graph of Google Cloud Platform (GCP) IAM policies, allowing for easier exploration of complex IAM structures. |
5 | 4 |
|
6 |
| -[](https://storage.googleapis.com/gcp-iam-collector/iam_graph_example.html) |
| 5 | +Uses Python 3 to construct a static HTML page using [vis.js](http://visjs.org/). |
7 | 6 |
|
8 |
| -## Features |
| 7 | +Currently supports: |
| 8 | +* IAM policies assigned to folders |
| 9 | +* IAM policies assigned to projects |
| 10 | +* User Accounts (members) |
| 11 | +* Service Accounts |
| 12 | +* Groups |
| 13 | +* Filtering by users, user types, groups and roles |
9 | 14 |
|
10 |
| -GCP IAM collector iterates over projects using [Google Cloud Resource Manager API](https://cloud.google.com/resource-manager/reference/rest/v1/projects/list) and dumps to CSV files: |
11 |
| -* all available GCP projects, |
12 |
| -* projects IAM permissions, |
13 |
| -* projects service account and their keys, |
14 |
| -* BigQuery dataset ACLs, |
15 |
| -* Cloud Storage bucket ACLs |
| 15 | + |
| 16 | + |
16 | 17 |
|
17 |
| -IAM graph currently supports: |
18 |
| -* GCP projects and their permissions, |
19 |
| -* Service accounts and their permissions |
| 18 | +# Getting started |
20 | 19 |
|
21 |
| -# Setup |
| 20 | +## Initial steps |
22 | 21 |
|
23 |
| -1. Install dependencies: |
| 22 | +### 1. Install dependencies |
| 23 | +* [Google Cloud CLI](https://cloud.google.com/sdk/gcloud/) |
| 24 | + |
| 25 | +### 2. Configure [Google Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials) |
| 26 | +``` |
| 27 | +gcloud auth application-default login |
24 | 28 | ```
|
25 |
| -pip install -r requirements.txt |
| 29 | + |
| 30 | +If necessary, set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to point to the location of the created credentials file. |
| 31 | + |
| 32 | +**Example** |
26 | 33 | ```
|
27 |
| -2. Install [gcloud](https://cloud.google.com/sdk/gcloud/) CLI tool. |
28 |
| -3. Setup [Google Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials): |
| 34 | +export GOOGLE_APPLICATION_CREDENTIALS=~/.config/gcloud/application_default_credentials.json |
29 | 35 | ```
|
30 |
| -gcloud auth application-default login |
| 36 | + |
| 37 | +### 3. Set the collection scope |
| 38 | + |
| 39 | +Set the environment variable `IAM_GRAPH_SCOPE` to determine the hierarchical starting point from where policies should be collected. This must be a folder or an organization. Use the standard Google API format, e.g. `organizations/93823423523` or `folders/9382372422`. |
| 40 | + |
| 41 | +**Example** |
| 42 | +``` |
| 43 | +export IAM_GRAPH_SCOPE='organizations/83747734232' |
| 44 | +``` |
| 45 | + |
| 46 | +By setting the scope to an organization or folder, IAM policies for all contained folders and projects will be collected, recursively. |
| 47 | + |
| 48 | +# Run it |
| 49 | +The easiest way is to run it as an ephemeral Docker container. |
| 50 | + |
| 51 | +<details open> |
| 52 | + <summary>Docker</summary> |
| 53 | + |
| 54 | +### 1. Install dependencies |
| 55 | +* [Docker](https://docs.docker.com/get-docker/) |
| 56 | + |
| 57 | +### 2. Build it and run it |
| 58 | + |
| 59 | +``` |
| 60 | +# Build the Docker image |
| 61 | +docker build -t gcp-iam-graph . |
| 62 | +
|
| 63 | +# Run the Docker image |
| 64 | +docker run -it --rm \ |
| 65 | +--name gcp-iam-graph \ |
| 66 | +-e IAM_GRAPH_SCOPE="${IAM_GRAPH_SCOPE}" \ |
| 67 | +-e GOOGLE_APPLICATION_CREDENTIALS=/tmp/keys/credentials.json \ |
| 68 | +-v $GOOGLE_APPLICATION_CREDENTIALS:/tmp/keys/credentials.json:ro \ |
| 69 | +-p 8080:8080 \ |
| 70 | +gcp-iam-graph |
31 | 71 | ```
|
32 | 72 |
|
33 |
| -# Run Instructions |
| 73 | +This will first start data collection, construct the graph, then serve it on a local webserver on [localhost:8080](http://localhost:8080). |
34 | 74 |
|
35 |
| -Command below dumps all IAM to csv files |
| 75 | +This message means data collection is finished, and that the webserver is ready: |
36 | 76 | ```
|
37 |
| -python collector.py |
| 77 | +Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ... |
38 | 78 | ```
|
| 79 | +</details> |
| 80 | +<details> |
| 81 | + <summary>Python (development)</summary> |
39 | 82 |
|
40 |
| -Creating interactive graph: |
| 83 | +### 1. Install dependencies |
| 84 | +**Requires Python 3 and PIP.** |
| 85 | + |
| 86 | +``` |
| 87 | +pip install --no-cache-dir -r src/requirements.txt |
41 | 88 | ```
|
42 |
| -python create_iam_graph.py |
| 89 | + |
| 90 | +### 2. Create the graph |
| 91 | + |
43 | 92 | ```
|
| 93 | +python3 src/create_graph.py ${IAM_GRAPH_SCOPE} index.html |
| 94 | +``` |
| 95 | + |
| 96 | +### 3. Start a simple Python webserver (optional) |
| 97 | +You can also open the HTML file in a browser. |
| 98 | + |
| 99 | +``` |
| 100 | +python3 -m http.server 8080 |
| 101 | +``` |
| 102 | +</details> |
| 103 | + |
| 104 | + |
| 105 | +# Attributions |
| 106 | +This project is based on [gcp-iam-collector](https://github.com/marcin-kolda/gcp-iam-collector) by Marcin Kolda. |
0 commit comments