Skip to main content

Construct to create a private asset S3 bucket. A cognito token can be used to allow access to he S3 asset.

Project description

NPM version PyPI version .NET version Release

cdk-private-asset-bucket

A construct to create a private asset S3 bucket. Cognito will be used for token validation with Lambda@Edge.

Architecture

Diagram

Example

import { ProwlerAudit } from 'cdk-prowler';
...
    const app = new core.App();

    const stack = new core.Stack(app, 'PrivateAssetBucket-stack2', {
      env: {
        account: '981237193288',
        region: 'us-east-1',
      },
    });

    const userPool = new cognito.UserPool(stack, 'userPool', {
      removalPolicy: core.RemovalPolicy.DESTROY,
    });

    const userPoolWebClient = new cognito.UserPoolClient(stack, 'userPoolWebClient', {
      userPool: userPool,
      generateSecret: false,
      preventUserExistenceErrors: true,
      authFlows: {
        adminUserPassword: true,
        userPassword: true,
      },
      oAuth: {
        flows: {
          authorizationCodeGrant: false,
          implicitCodeGrant: true,
        },
      },
    });

    const privateAssetBucket = new PrivateAssetBucket(stack, 'privateAssetBucket', {
      userPoolId: userPool.userPoolId,
      userPoolClientId: userPoolWebClient.userPoolClientId,
    });

    new core.CfnOutput(stack, 'AssetBucketName', {
      value: privateAssetBucket.assetBucketName,
    });

    new core.CfnOutput(stack, 'AssetBucketCloudfrontUrl', {
      value: privateAssetBucket.assetBucketCloudfrontUrl,
    });

Properties

API.md

Test PrivateBucketAsset

If you forged / cloned that repo you can test directly from here. Don't forget to init with:

yarn install

Create a test cdk stack with one of the following:

yarn cdk deploy
yarn cdk deploy --watch
yarn cdk deploy --require-approval never
  • Upload a picture named like pic.png to the private asset bucket
  • Create a user pool user and get / save the token:
USER_POOL_ID=us-east-1_0Aw1oPvD6
CLIENT_ID=3eqcgvghjbv4d5rv32hopmadu8
USER_NAME=martindev
USER_PASSWORD=M@rtindev1
REGION=us-east-1
CFD=d1f2bfdek3mzi7.cloudfront.net

aws cognito-idp admin-create-user --user-pool-id $USER_POOL_ID --username $USER_NAME --region $REGION
aws cognito-idp admin-set-user-password --user-pool-id $USER_POOL_ID --username $USER_NAME --password $USER_PASSWORD  --permanent --region $REGION
ACCESS_TOKEN=$(aws cognito-idp initiate-auth --auth-flow USER_PASSWORD_AUTH --client-id $CLIENT_ID --auth-parameters USERNAME=$USER_NAME,PASSWORD=$USER_PASSWORD  --region $REGION | jq -r '.AuthenticationResult.AccessToken')

echo "curl --location --request GET "https://$CFD/pic.png" --cookie "Cookie: token=$ACCESS_TOKEN""
  • You can use the curl for importing in Postman. but it looks like Postman can't import the cookie. So you need to set the cookie manually in Postman!
  • In Postman you should see your picture :)

Planned Features

  • Support S3 bucket import ootb.
  • Support custom authorizer

Thanks To

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdk-private-asset-bucket-1.143.3.tar.gz (9.4 MB view details)

Uploaded Source

Built Distribution

File details

Details for the file cdk-private-asset-bucket-1.143.3.tar.gz.

File metadata

  • Download URL: cdk-private-asset-bucket-1.143.3.tar.gz
  • Upload date:
  • Size: 9.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for cdk-private-asset-bucket-1.143.3.tar.gz
Algorithm Hash digest
SHA256 65701a8138e9e6c23e26c2bffe8e2eed8ed97b0588352443c20789cfdf2938e8
MD5 c1018e3b7fcbbe2bbc4e1e1ef54a210f
BLAKE2b-256 0f2cb44be3775aebc9ad8cc139a01f45b4c5f4cf11c596abbbafaea71a554d08

See more details on using hashes here.

File details

Details for the file cdk_private_asset_bucket-1.143.3-py3-none-any.whl.

File metadata

  • Download URL: cdk_private_asset_bucket-1.143.3-py3-none-any.whl
  • Upload date:
  • Size: 9.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for cdk_private_asset_bucket-1.143.3-py3-none-any.whl
Algorithm Hash digest
SHA256 23fa1ecbf4e34c0981bed2c104cc9b719b16023831cdda99f2168c1ff964a865
MD5 f1bba15c37880f0b4fa26ffe0c007c43
BLAKE2b-256 4b7f637cf88a6eac1fa6a0d235aae656864ce45f89bc52875d5933fcdfcbf709

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page