npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aws-resource-based-policy-collector

v1.4.3

Published

Utility for collecting resource-based policies from an AWS account

Downloads

72

Readme

AWS resource-based policy collector

This library aims to collect resource-based policies from an AWS account.

Install

yarn add aws-resource-based-policy-collector

or

npm install aws-resource-based-policy-collector

Motivation

When removing an account from an AWS organisation special attention must be paid to resource-based policies. Specifically, the presence of the aws:PrincipalOrgID condition key will cause access issues once the account leaves it's parent organisation.

This library simply collects resources and their associated policies in an unopinionated manner. The actual analysis of the output is left to the consumers of this library.

Usage

Your environment must be configured with valid AWS credentials. See Setting credentials in Node.js. Your credentials must be authorised to perform read-only actions within your account. This can be achieved simply by creating a role in your account with the AWS managed ReadOnlyAccess policy. Naturally, your account must also not have read actions restricted by any service control policies in your organisation hierarchy.


import { collect } from 'aws-resource-based-policy-collector';

const main = async () => {
  const result = await collect();
  // ... Do something with result
};

main();

The AWS region defaults to that of your credentials however you may optionally set this explicitly.

const result = await collect({ region: 'us-east-1' });

The collect function returns an array of objects per-service where each service object contains an array of resource objects. The service object may also contain an optional error field if there was an issue listing resources. This typically ocurrs if your credentials do not have the required permissions to read the resources (or is blocked by an SCP).

Each resource object contains a type and id to uniquly identify the resource as well as a JSON encoded policy. The resource may also contain an optional error field if there was an issue querying the resource or it's policy.

[
  {
    serviceName: 's3',
    resources: [
      {
        type: 'AWS::S3::Bucket',
        id: 'my-bucket',
        policy: '', // Policy document
        error: '', // Only present if an error ocurred
      }
    ],
    error: '', // Only present if an error ocurred
  },
  ...
]

Only resources with policies or errors are included.

Supported services

This library currently collects resource-based policies for AWS services listed below.

This list of services is taken from the tables found at AWS services that work with IAM, specifically those services with a Yes or Partial in the Resource-based policies column.

  • [x] Lambda
  • [x] Serverless Application Repository
  • [x] ECR
  • [x] AWS Backup
  • [x] EFS
  • [x] S3 Glacier
  • [x] S3
  • [ ] S3 on AWS Outposts
  • [ ] Cloud9
  • [x] CodeArtifact
  • [x] CodeBuild
  • [x] IAM
  • [x] SecretsManager
  • [x] ACM Private Certificate Authority
  • [x] KMS
  • [ ] Lex v2
  • [x] CloudWatch Logs
  • [ ] Systems Manager Incident Manager
  • [ ] Systems Manager Incident Manager Contacts
  • [x] API Gateway
  • [x] VPC (endpoints)
  • [x] Elemental MediaStore
  • [x] OpenSearch
  • [x] Glue
  • [x] EventBridge
  • [x] EventBridge Schemas
  • [x] SNS
  • [x] SQS
  • [x] IoT
  • [ ] SES v2

Other services

AWS RAM

AWS RAM does not support resource-based policies however it is included as it is likely of interest as resources may be shared with the parent organisation.

Note the policy field for this resource type is NOT a JSON policy rather it is an arn of the principal the resource is shared with.

Troubleshooting

Access denied on S3 buckets

If you are getting AccessDenied errors on S3 bucket resources your bucket likely has a bucket policy preventing access. Remove the bucket policy or modify it to grant read access to your role.