A lil python package to generate iam policies
Project description
IAM Builder
A python script to generate an IAM policy based on a yaml or json configuration.
To install:
# Most stable
pip install iam-builder
# OR directly from github
pip install git+git://github.com/moj-analytical-services/iam_builder.git#egg=iam_builder
To use the command line interface:
iam_builder -c examples/iam_config.yaml -o examples/iam_policy.json
-c
is the path to your iam configuration (either a yaml or json file).-o
is the path to your output iam policy (needs to be a json file).
Or to do the same thing in python:
import yaml
import json
from iam_builder.iam_builder import build_iam_policy
with open('examples/iam_config.yaml') as f:
config = yaml.load(f, Loader=yaml.FullLoader)
iam_policy = build_iam_policy(config)
with open('examples/iam_policy.json', "w+") as f:
json.dump(iam_policy, f, indent=4, separators=(',', ': '))
Both scripts will create the output iam_policy seen in the examples folder. You can also see more example configs by looking in the unit tests.
Your config file can be either a yaml or json file.
The example yaml (iam_config.yaml
) looks this:
iam_role_name: iam_role_name
athena:
write: false
glue_job: true
secrets: true
s3:
read_only:
- test_bucket_read_only/*
write_only:
- test_bucket_write_only/*
- test_bucket_read_only/write_only_folder/*
read_write:
- test_bucket_read_write/*
- test_bucket_read_only/write_folder/*
Whilst the example json (iam_config.json
) looks like this:
{
"iam_role_name": "iam_role_name",
"athena": {
"write": false
},
"glue_job": true,
"secrets": true,
"s3": {
"read_only": [
"test_bucket_read_only/*"
],
"write_only": [
"test_bucket_write_only/*",
"test_bucket_read_only/write_only_folder/*"
],
"read_write": [
"test_bucket_read_write/*",
"test_bucket_read_only/write_folder/*"
]
}
}
-
iam_role_name: The role name of your airflow job; required if you want to run glue jobs or access secrets.
-
athena: Only has one key value pair.
write
which is either true or false. Iffalse
then only read access to Athena (cannot create, delete or alter tables, databases and partitions). Iftrue
then the role will also have the ability to do stuff like CTAS queries,DROP TABLE
,CREATE DATABASE
, etc. -
glue_job: Boolean; must be set to
true
to allow role to run glue jobs. Iffalse
or absent role will not be able to run glue jobs. -
secrets: Boolean; must be set to
true
to allow role to access secrets from AWS Parameter Store. Iffalse
or absent role will not be able to access secrets. -
s3: Can have up to 3 keys:
read_only
,write_only
andread_write
. Each key describes the level of access you want your iam policy to have with each s3 path. More details below:-
read_only: A list of s3 paths that the iam_role should be able to access (read only). Each item in the list should either be a path to a object or finish with
/*
to denote that it can access everything within that directory. Note the S3 paths don't start withs3://
in the config. -
write_only: A list of s3 paths that the iam_role should be able to access (write only). Each item in the list should either be a path to a object or finish with
/*
to denote that it can access everything within that directory. Note the S3 paths don't start withs3://
in the config. -
read_write_s3_access: A list of s3 paths that the iam_role should be able to access (read and write). Each item in the list should either be a path to a object or finish with
/*
to denote that it can access everything within that directory. Note the S3 paths don't start withs3://
in the config.
-
How to update
When updating IAM builder, make sure to change the version number in pyproject.toml
and describe the change in CHANGELOG.md
.
If you have changed any dependencies in pyproject.yaml
, run poetry update
to update poetry.lock
.
Once you have created a release in GitHub, to publish the latest version to PyPI, run:
poetry build
poetry publish -u <username>
Here, you should substitute <username>
for your PyPI username. In order to publish to PyPI, you must be an owner of the project.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file iam_builder-4.0.0.tar.gz
.
File metadata
- Download URL: iam_builder-4.0.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.7.7 Darwin/18.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce6adc687b1ab24ec08ed66dc7e2bb18755613516ab503f2ad212345275a8ce4 |
|
MD5 | d3eec70fbe1ac9e91579e1441b52ddf6 |
|
BLAKE2b-256 | 0dbf730b29f32c7621f15bfc10695687e5286eec9061198bbf939a69d8240f9c |
File details
Details for the file iam_builder-4.0.0-py3-none-any.whl
.
File metadata
- Download URL: iam_builder-4.0.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.7.7 Darwin/18.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25fa62863fec6afd8edb4311940a817a3fcb78f5a7451d3ce6e84c8a4e046201 |
|
MD5 | f4c5d9166171f3e19d7a9cb00585fd10 |
|
BLAKE2b-256 | 464441dddd910157db643d5f4378db24acb4e22a8e5b936f86f8e0c83aa2e52d |