Skip to content

Commit 9d94aa5

Browse files
author
Sindre Lindstad
committed
Initial commit post refactor
1 parent 42592cc commit 9d94aa5

27 files changed

+1072
-471
lines changed

.gitignore

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,42 @@
1-
*.pyc
2-
31
# IDE
42
*.iml
53

4+
# Compiled Python bytecode
5+
*.py[cod]
6+
*.pyc
7+
8+
# Log files
9+
*.log
10+
11+
# JetBrains IDE
12+
.idea/
13+
14+
# Unit test reports
15+
TEST*.xml
16+
17+
# Generated by MacOS
18+
.DS_Store
19+
20+
# Generated by Windows
21+
Thumbs.db
22+
23+
# Applications
24+
*.app
25+
*.exe
26+
*.war
27+
28+
# Large media files
29+
*.mp4
30+
*.tiff
31+
*.avi
32+
*.flv
33+
*.mov
34+
*.wmv
35+
36+
# Application specific
37+
*.pem
38+
*.tmp
639
cache
740
*.csv
841
csv
9-
*.sh
10-
*.html
42+
*.html

Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3-alpine
2+
3+
RUN addgroup -g 2000 app && adduser -u 2000 --disabled-password --gecos '' app --ingroup app
4+
WORKDIR /usr/src/app
5+
6+
COPY src/ ./src
7+
COPY entrypoint.sh .
8+
9+
RUN pip install --no-cache-dir -r src/requirements.txt
10+
11+
RUN chown -R app:app /home/app
12+
USER app
13+
14+
EXPOSE 8080
15+
16+
CMD ["/bin/sh", "entrypoint.sh"]

LICENSE

+2-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2017 Marcin Kolda
190+
Copyright 2021 Sindre Lindstad
190191

191192
Licensed under the Apache License, Version 2.0 (the "License");
192193
you may not use this file except in compliance with the License.

README.md

+88-25
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,106 @@
1-
# gcp-iam-collector
2-
Python scripts for collecting and visualising [Google Cloud Platform](https://cloud.google.com/) IAM permissions
1+
# GCP IAM Visualizer
32

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.
54

6-
[![Example graph](https://raw.githubusercontent.com/marcin-kolda/gcp-iam-collector/master/example_graph.png)](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/).
76

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
914

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+
![Example overview](src/assets/img/example_overview.png)
16+
![Example graph](src/assets/img/example_graph.png)
1617

17-
IAM graph currently supports:
18-
* GCP projects and their permissions,
19-
* Service accounts and their permissions
18+
# Getting started
2019

21-
# Setup
20+
## Initial steps
2221

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
2428
```
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**
2633
```
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
2935
```
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
3171
```
3272

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).
3474

35-
Command below dumps all IAM to csv files
75+
This message means data collection is finished, and that the webserver is ready:
3676
```
37-
python collector.py
77+
Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...
3878
```
79+
</details>
80+
<details>
81+
<summary>Python (development)</summary>
3982

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
4188
```
42-
python create_iam_graph.py
89+
90+
### 2. Create the graph
91+
4392
```
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.

collector.py

-117
This file was deleted.

0 commit comments

Comments
 (0)