awacs (Amazon Web Access Control Subsystem)

repository·main·Indexed 18 days ago

https://github.com/cloudtools/awacs

A Python library for programmatically creating AWS Access Policy JSON with built-in type and property checking. It features the PolicyDocument class for defining policies and a generator tool to update AWS actions via documentation scraping.

Tokens
555
Snippets
3
Records
3
Agent score
14%

What's inside awacs

  1. How to update AWS actions via scraping

    main

    The repository includes a generator tool that scrapes AWS documentation to auto-generate new action files. To run the scraper (requires Python 3.7+), follow these steps:

    1. Install scraper requirements.
    2. Install the current package.
    3. Run the scrape script.
    4. Review changes with git diff.
    $ python3 -m pip install -r scrape/requirements.txt
    $ python3 -m pip install .
    $ python3 ./scrape/scrape.py
    $ git diff
  2. Create an AWS IAM Policy Document

    main

    Use the awacs.aws.PolicyDocument class to programmatically define AWS Access Policy JSON. This class provides property and type checking to catch errors early. Note that awacs.aws.Policy is deprecated in favor of awacs.aws.PolicyDocument.

    To generate the JSON representation of a policy, call the .to_json() method on your PolicyDocument instance.

    from awacs.aws import Action, Allow, PolicyDocument, Principal, Statement
    from awacs.iam import ARN as IAM_ARN
    from awacs.s3  import ARN as S3_ARN
    
    account = "123456789012"
    user = "user/Bob"
    
    pd = PolicyDocument(
        Version="2012-10-17",
        Id="S3-Account-Permissions",
        Statement=[
            Statement(
                Sid="1",
                Effect=Allow,
                Principal=Principal("AWS", [IAM_ARN(user, '', account)]),
                Action=[Action("s3", "*")],
                Resource=[S3_ARN("my_corporate_bucket/*",),
            ),
        ],
    )
    print(pd.to_json())