Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.0 #135

Draft
wants to merge 59 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
00ca52b
Make storage pluggable (#115)
patricksanders Aug 26, 2020
a90c32c
Create pluggable data retriever pattern (#118)
patricksanders Sep 10, 2020
d2b0110
Add preliminary v1 info to readme
patricksanders Sep 11, 2020
8563305
use setupmeta to clean up setup and metadata
patricksanders Sep 11, 2020
b74efa7
publish develop branch to pypi
patricksanders Sep 11, 2020
cabe4a8
explicitly define version
patricksanders Sep 11, 2020
16bbeb9
switch to dev versioning
patricksanders Sep 11, 2020
079c496
Merge branch 'master' into develop
patricksanders Sep 11, 2020
85a4762
upgrade requirements, fix broken test
patricksanders Jun 15, 2021
65933c3
Config migration (#122)
patricksanders Jul 21, 2021
3f3c8b5
Merge branch 'master' into develop
patricksanders Jul 22, 2021
66b37b6
Merge branch 'master' into develop
patricksanders Sep 11, 2024
503770b
upgrade deps, add test deps, update readme
patricksanders Sep 11, 2024
daf2730
add github workflow def
patricksanders Sep 11, 2024
f33903a
unpin it all, yolo
patricksanders Sep 11, 2024
c126862
drop 3.7, add 3.11 and 3.12
patricksanders Sep 11, 2024
5bfe481
do we even need bunch?
patricksanders Sep 11, 2024
87604b6
drop 3.12
patricksanders Sep 11, 2024
5f8ba1e
clean up from wonky rebase
patricksanders Sep 11, 2024
1d51f83
switch to pyproject.toml
patricksanders Sep 11, 2024
60c4cf7
more pyproject config
patricksanders Sep 11, 2024
2ca7e5b
add publish workflow
patricksanders Sep 11, 2024
0d444c4
fix test command
patricksanders Sep 11, 2024
696e618
fix lots of linting errors
patricksanders Sep 12, 2024
301da8e
fix test command
patricksanders Sep 12, 2024
59b0576
bump min python to 3.10
patricksanders Sep 12, 2024
0d356ca
re-add future imports
patricksanders Sep 12, 2024
a05bd8f
workflow tweaks
patricksanders Sep 12, 2024
17ee8a3
change release trigger
patricksanders Sep 12, 2024
4685fd9
disable conditions
patricksanders Sep 12, 2024
acee6c9
upgrade actions, change pypi env name
patricksanders Sep 12, 2024
867e6b3
blank
patricksanders Sep 12, 2024
13e699f
moar pypi tweaks
patricksanders Sep 12, 2024
3f9c839
try storing artifacts
patricksanders Sep 12, 2024
9c93fa0
set pypi repo url
patricksanders Sep 12, 2024
1e18b00
switch that other url back
patricksanders Sep 12, 2024
b86a876
wait for package to finish
patricksanders Sep 12, 2024
9865b96
update environment
patricksanders Sep 12, 2024
4e7a986
maybe this?
patricksanders Sep 12, 2024
0a426e5
idk man
patricksanders Sep 12, 2024
8073986
oh my god it was the file extension
patricksanders Sep 12, 2024
a3996df
add setuptools_scm to build env
patricksanders Sep 12, 2024
fe4e060
fetch tags
patricksanders Sep 12, 2024
f3af05e
set fetch depth
patricksanders Sep 12, 2024
ff01b1c
clean up release workflow
patricksanders Sep 12, 2024
632deb9
trigger on tags
patricksanders Sep 12, 2024
7dfc0af
ignore version file?
patricksanders Sep 12, 2024
e36cfa7
ignore version file better?
patricksanders Sep 12, 2024
e922069
ignore version file betterer?
patricksanders Sep 12, 2024
9f3238e
run git status
patricksanders Sep 12, 2024
9ba485c
set skip-worktree on version file
patricksanders Sep 12, 2024
66df7c3
add missing key
patricksanders Sep 12, 2024
9cd4fc9
try more things
patricksanders Sep 12, 2024
423276b
didnt work, do the other thing
patricksanders Sep 12, 2024
9d2bcf8
linting fixes, move things out of init
patricksanders Sep 12, 2024
52b20e4
update action triggers
patricksanders Sep 12, 2024
026b16f
update action triggers
patricksanders Sep 12, 2024
72657c5
test tweaks
patricksanders Sep 13, 2024
2dad4aa
Merge branch 'main' into develop
patricksanders Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
./.travis.yml
./.env
./docker-compose.yml
*.log
*.db
14 changes: 8 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: Publish

on:
release:
Expand All @@ -16,19 +16,21 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
# Fetch all commits and tags to make sure the version gets set right by hatch-vcs.
# This should be temporary; once these changes are merged into the primary branch it can
# probably be removed.
fetch-depth: 0
fetch-tags: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install dependencies
python-version: "3.10"
- name: Install hatch
run: |
python -m pip install -U pip build
python -m pip install -r requirements.txt .
python -m pip install hatch
- name: Build dist
run: |
python -m build
hatch build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Run tests

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

jobs:
test:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install hatch
run: |
python -m pip install hatch
- name: Lint
run: |
hatch fmt
- name: Test
run: |
hatch run +py=${{ matrix.python-version }} test:pytest
- name: Build dist
run: |
hatch build
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ wheels/
.installed.cfg
*.egg

# Auto generated during builds
aardvark/__version__.py

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down Expand Up @@ -106,4 +109,5 @@ ENV/
.mypy_cache/

# config
config.py
.secrets.yaml
settings.local.yaml.bak
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8
FROM python:3.10

RUN apt-get update -y \
&& apt-get upgrade -y \
Expand All @@ -15,10 +15,12 @@ WORKDIR /etc/aardvark
ENV AARDVARK_DATA_DIR=/data \
AARDVARK_ROLE=Aardvark \
ARN_PARTITION=aws \
AWS_DEFAULT_REGION=us-east-1
AWS_DEFAULT_REGION=us-east-1 \
FLASK_APP=aardvark

EXPOSE 5000

COPY ./settings.yaml .
COPY ./entrypoint.sh /etc/aardvark/entrypoint.sh

ENTRYPOINT [ "/etc/aardvark/entrypoint.sh" ]
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include setup.py README.md MANIFEST.in LICENSE
include pyproject.toml requirements.txt README.md MANIFEST.in LICENSE aardvark/config_default.yaml
recursive-include aardvark *.js
global-exclude *~
169 changes: 132 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,167 @@ Aardvark - Multi-Account AWS IAM Access Advisor API
[![NetflixOSS Lifecycle](https://img.shields.io/osslifecycle/Netflix/osstracker.svg)]()
[![Discord chat](https://img.shields.io/discord/754080763070382130?logo=discord)](https://discord.gg/9kwMWa6)

<img align="center" alt="Aardvark Logo" src="docs/images/aardvark_logo.jpg" width="10%" display="block">
![Aardvark Logo](docs/images/aardvark_logo_small.png)

Aardvark is a multi-account AWS IAM Access Advisor API (and caching layer).

## Install:
## New in `v1.0.0`

Ensure that you have Python 3.6 or later. Python 2 is no longer supported.
⚠️ Breaking change

```bash
✨ Enhancement

- ⚠️ Upgrade to Python 3.10+
- ⚠️ New configuration format
- ✨ Pluggable persistence layer
- ✨ Pluggable retrievers

## Install

Ensure that you have Python 3.10 or later.

Use pip install Aardvark:

```shell
pip install aardvark
```

Alternatively, clone the repository and install a development version:

```shell
git clone https://github.com/Netflix-Skunkworks/aardvark.git
cd aardvark
python3 -m venv env
. env/bin/activate
python setup.py develop
python3 -m venv venv
source venv/bin/activate
pip install -e .
```

### Known Dependencies
- libpq-dev
To run the test suite, you'll need to install the test requirements:

```shell
pip install -r requirements-test.txt
pytest test/
```

## Configure Aardvark

The Aardvark config wizard will guide you through the setup.
```
% aardvark config
```shell
aardvark config

Aardvark can use SWAG to look up accounts. https://github.com/Netflix-Skunkworks/swag-client
Do you use SWAG to track accounts? [yN]: no
ROLENAME: Aardvark
DATABASE [sqlite:////home/github/aardvark/aardvark.db]:
# Threads [5]:
Aardvark can use SWAG to look up accounts. See https://github.com/Netflix-Skunkworks/swag-client
Do you use SWAG to track accounts? [yN]: N
Role Name [Aardvark]: Aardvark
Database URI [sqlite:///aardvark.db]:
Worker Count [5]: 5
Config file location [settings.yaml]: settings.local.yaml

>> Writing to config.py
writing config file to settings.local.yaml
```
- Whether to use [SWAG](https://github.com/Netflix-Skunkworks/swag-client) to enumerate your AWS accounts. (Optional, but useful when you have many accounts.)
- The name of the IAM Role to assume into in each account.
- The Database connection string. (Defaults to sqlite in the current working directory. Use RDS Postgres for production.)
- The number of workers to create.

## Create the DB tables

```
```shell
aardvark create_db
```

## IAM Permissions:

Aardvark needs an IAM Role in each account that will be queried. Additionally, Aardvark needs to be launched with a role or user which can `sts:AssumeRole` into the different account roles.

AardvarkInstanceProfile:
### Hub role (`AardvarkInstanceProfile`):

- Only create one.
- Needs the ability to call `sts:AssumeRole` into all of the AardvarkRole's
- Needs the ability to call `sts:AssumeRole` into all of the `AardvarkRole`s

Inline policy example:

```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AssumeSpokeRoles",
"Effect": "Allow",
"Action": [
"sts:assumerole"
],
"Resource": [
"arn:aws:iam::*:role/AardvarkRole"
]
}
]
}
```

### Spoke roles (`AardvarkRole`):

AardvarkRole:
- Must exist in every account to be monitored.
- Must have a trust policy allowing `AardvarkInstanceProfile`.
- Has these permissions:

```
iam:GenerateServiceLastAccessedDetails
iam:GetServiceLastAccessedDetails
iam:listrolepolicies
iam:listroles
iam:ListRolePolicies
iam:ListRoles
iam:ListUsers
iam:ListPolicies
iam:ListGroups
```
Assume role policy document example (be sure to replace the account ID with a real one):

```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowHubRoleAssume",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::111111111111:role/AardvarkInstanceProfile"
]
},
"Action": "sts:AssumeRole"
}
]
}
```

Inline policy example:

```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "IAMAccess",
"Effect": "Allow",
"Action": [
"iam:GenerateServiceLastAccessedDetails",
"iam:GetServiceLastAccessedDetails",
"iam:ListRolePolicies",
"iam:ListRoles",
"iam:ListUsers",
"iam:ListPolicies",
"iam:ListGroups"
],
"Resource": [
"*"
]
}
]
}
```

So if you are monitoring `n` accounts, you will always need `n+1` roles. (`n` AardvarkRoles and `1` AardvarkInstanceProfile).
So if you are monitoring `n` accounts, you will always need `n+1` roles. (one `AardvarkInstanceProfile` and n `AardvarkRole`s).

Note: For locally running aardvark, you don't have to take care of the AardvarkInstanceProfile. Instead, just attach a policy which contains "sts:AssumeRole" to the user you are using on the AWS CLI to assume Aardvark Role. Also, the same user should be mentioned in the trust policy of Aardvark Role for proper assignment of the privileges.
Note: For locally running aardvark, you don't have to take care of the AardvarkInstanceProfile. Instead, just attach a policy which contains `sts:AssumeRole` to the user you are using on the AWS CLI to assume Aardvark Role. Also, the same user should be mentioned in the trust policy of Aardvark Role for proper assignment of the privileges.

## Gather Access Advisor Data

Expand All @@ -80,24 +173,30 @@ You'll likely want to refresh the Access Advisor data regularly. We recommend r

If you don't have SWAG you can pass comma separated account numbers:

aardvark update -a 123456789012,210987654321
aardvark update -a 123456789012 -a 210987654321

#### With SWAG:

Aardvark can use [SWAG](https://github.com/Netflix-Skunkworks/swag-client) to look up accounts, so you can run against all with:

aardvark update
```shell
aardvark update
```

or by account name/tag with:

aardvark update -a dev,test,prod
```shell
aardvark update -a dev -a test -a prod
```


## API

### Start the API

aardvark start_api -b 0.0.0.0:5000
```shell
FLASK_APP=aardvark flask run -b 0.0.0.0:5000
```

In production, you'll likely want to have something like supervisor starting the API for you.

Expand All @@ -106,7 +205,7 @@ In production, you'll likely want to have something like supervisor starting the
Swagger is available for the API at `<Aardvark_Host>/apidocs/#!`.

Aardvark responds to get/post requests. All results are paginated and pagination can be controlled by passing `count` and/or `page` arguments. Here are a few example queries:
```bash
```shell
curl localhost:5000/api/1/advisors
curl localhost:5000/api/1/advisors?phrase=SecurityMonkey
curl localhost:5000/api/1/advisors?arn=arn:aws:iam::000000000000:role/SecurityMonkey&arn=arn:aws:iam::111111111111:role/SecurityMonkey
Expand Down Expand Up @@ -143,7 +242,7 @@ Once this file is created, then build the containers and start the services. Aar
- API Server - This is the HTTP webserver will serve the data. By default, this is listening on [http://localhost:5000/apidocs/#!](http://localhost:5000/apidocs/#!).
- Collector - This is a daemon that will fetch and cache the data in the local SQL database. This should be run periodically.

```bash
```shell
# build the containers
docker-compose build

Expand All @@ -153,7 +252,7 @@ docker-compose up

Finally, to clean up the environment

```bash
```shell
# bring down the containers
docker-compose down

Expand Down Expand Up @@ -209,7 +308,7 @@ if __name__ == "__main__":

This file can now be invoked in the same way as `manage.py`:

```bash
```shell
python signals_example.py update -a cool_account
```

Expand All @@ -230,7 +329,3 @@ INFO: Thread #1 FINISHED persisting data for account 123456789012
|-------|---------|
| `manage.UpdateAccountThread` | `on_ready`, `on_complete`, `on_failure` |
| `updater.AccountToUpdate` | `on_ready`, `on_complete`, `on_error`, `on_failure` |

## TODO:

See [TODO](TODO.md)
3 changes: 0 additions & 3 deletions TODO.md

This file was deleted.

Loading
Loading