From d1ba42348d4d32e8f3ace2d3891d40979e376b6e Mon Sep 17 00:00:00 2001 From: Jithin Roy Date: Wed, 20 Oct 2021 10:17:43 -0700 Subject: [PATCH 1/2] chore: Move lambda rotator to a generic location --- .../README.md | 95 +++++++++++++++++++ .../lambda_functions/__init__.py | 0 .../lambda_functions/src/__init__.py | 0 .../src/destination/__init__.py | 0 .../src/destination/circleci.py | 0 .../lambda_functions/src/handler.py | 0 .../lambda_functions/src/models/__init__.py | 0 .../src/models/destination_type.py | 0 .../src/models/source_type.py | 0 .../lambda_functions/src/requirements.txt | 0 .../src/source_data_generator/__init__.py | 0 .../aws_session_credential_source.py | 0 .../lambda_env_var_data_source.py | 0 .../secrets_data_source.py | 0 .../lambda_functions/src/utils/__init__.py | 0 .../lambda_functions/src/utils/retry.py | 0 .../src/utils/secrets_manager_helper.py | 0 .../lambda_functions/test/__init__.py | 0 .../test/test_aws_credential_rotator.py | 0 .../lambda_functions/test/test_circleci.py | 0 .../lambda_functions/test/test_retry.py | 0 .../test/test_secrets_data_source.py | 0 .../test/test_secrets_manager_helper.py | 0 .../test/test_static_data_source.py | 0 .../lambda_functions/tests.py | 0 .../credential_rotation/lambda_construct.py | 2 +- 26 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/generic_lambda_credentials_rotator/README.md rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/__init__.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/__init__.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/destination/__init__.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/destination/circleci.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/handler.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/models/__init__.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/models/destination_type.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/models/source_type.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/requirements.txt (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/source_data_generator/__init__.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/source_data_generator/aws_session_credential_source.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/source_data_generator/lambda_env_var_data_source.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/source_data_generator/secrets_data_source.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/utils/__init__.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/utils/retry.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/src/utils/secrets_manager_helper.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/test/__init__.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/test/test_aws_credential_rotator.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/test/test_circleci.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/test/test_retry.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/test/test_secrets_data_source.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/test/test_secrets_manager_helper.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/test/test_static_data_source.py (100%) rename src/{release_artifacts_resources/ios/cdk/cdk/credential_rotation => generic_lambda_credentials_rotator}/lambda_functions/tests.py (100%) diff --git a/src/generic_lambda_credentials_rotator/README.md b/src/generic_lambda_credentials_rotator/README.md new file mode 100644 index 0000000..6e19b1d --- /dev/null +++ b/src/generic_lambda_credentials_rotator/README.md @@ -0,0 +1,95 @@ +# Generic Lambda Credentials Rotator + +Generic Lambda Credentials Rotator is a AWS Lambda function that can be set up to move credentials and other artifacts from one source to another destination. Few use cases: + +1. Create temprorary AWS credentials and push the credentials to CircleCI environment variable. +2. Move values in lambda environment variable to CircleCI environment variable. +3. Move values in AWS Secrets Manager to CircleCI environment variable. + +## Destination supported: + +- CircleCI environment variable + +## Sources supported: + +- AWS Session Credentials +- Lambda environment Variables +- Secrets in AWS Secrets Manager + +## Input format: + +```cli +{ + "sources": [ + { + "type": "aws_session_cred", + "description": "Temporary AWS Credentials to upload the release artifacts to S3 and invalidate Cloudfront", + "configuration": { + "user_env_variable": "IAM_USERNAME", + "iam_role_env_variable": "IAM_ROLE" + }, + "destination": { + "specifier": "aws-sdk-ios-cci", + "mapping_to_destination": [ + { + "destination_key_name": "XCF_ACCESS_KEY_ID", + "result_value_key": "access_key_id" + }, + { + "destination_key_name": "XCF_SECRET_ACCESS_KEY", + "result_value_key": "secret_access_key" + }, + { + "destination_key_name": "XCF_SESSION_TOKEN", + "result_value_key": "session_token" + } + ] + } + }, + { + "type": "secrets_manager", + "description": "", + "configuration": { + "secret_key_env_variable": "GITHUB_CREDENTIALS_SECRET" + }, + "destination": { + "specifier": "aws-sdk-ios-cci", + "mapping_to_destination": [ + { + "destination_key_name": "GITHUB_SPM_TOKEN", + "result_value_key": "GITHUB_SPM_TOKEN" + }, + { + "destination_key_name": "GITHUB_SPM_USER", + "result_value_key": "GITHUB_SPM_USER" + } + ] + } + }, + { + "type": "lambda_env_variables", + "description": "", + "configuration": { + "lambda_env_var_key": "SPM_S3_BUCKET_NAME" + }, + "destination": { + "specifier": "aws-sdk-ios-cci", + "mapping_to_destination": [ + { + "destination_key_name": "XCF_S3_BUCKET_NAME" + } + ] + } + } + ], + "destinations": { + "aws-sdk-ios-cci": { + "type": "cci_env_variable", + "description": "Circle CI environment variable for AWS SDK iOS repo", + "github_path": "aws-amplify/aws-sdk-ios", + "circleci_api_token_secret_id_lambda_env_var_key": "CIRCLE_CI_IOS_SDK_API_TOKEN" + } + } + } + +``` \ No newline at end of file diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/__init__.py b/src/generic_lambda_credentials_rotator/lambda_functions/__init__.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/__init__.py rename to src/generic_lambda_credentials_rotator/lambda_functions/__init__.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/__init__.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/__init__.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/__init__.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/__init__.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/destination/__init__.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/destination/__init__.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/destination/__init__.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/destination/__init__.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/destination/circleci.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/destination/circleci.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/destination/circleci.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/destination/circleci.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/handler.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/handler.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/handler.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/handler.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/models/__init__.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/models/__init__.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/models/__init__.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/models/__init__.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/models/destination_type.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/models/destination_type.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/models/destination_type.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/models/destination_type.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/models/source_type.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/models/source_type.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/models/source_type.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/models/source_type.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/requirements.txt b/src/generic_lambda_credentials_rotator/lambda_functions/src/requirements.txt similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/requirements.txt rename to src/generic_lambda_credentials_rotator/lambda_functions/src/requirements.txt diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/source_data_generator/__init__.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/source_data_generator/__init__.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/source_data_generator/__init__.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/source_data_generator/__init__.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/source_data_generator/aws_session_credential_source.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/source_data_generator/aws_session_credential_source.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/source_data_generator/aws_session_credential_source.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/source_data_generator/aws_session_credential_source.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/source_data_generator/lambda_env_var_data_source.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/source_data_generator/lambda_env_var_data_source.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/source_data_generator/lambda_env_var_data_source.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/source_data_generator/lambda_env_var_data_source.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/source_data_generator/secrets_data_source.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/source_data_generator/secrets_data_source.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/source_data_generator/secrets_data_source.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/source_data_generator/secrets_data_source.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/utils/__init__.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/utils/__init__.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/utils/__init__.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/utils/__init__.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/utils/retry.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/utils/retry.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/utils/retry.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/utils/retry.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/utils/secrets_manager_helper.py b/src/generic_lambda_credentials_rotator/lambda_functions/src/utils/secrets_manager_helper.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/src/utils/secrets_manager_helper.py rename to src/generic_lambda_credentials_rotator/lambda_functions/src/utils/secrets_manager_helper.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/__init__.py b/src/generic_lambda_credentials_rotator/lambda_functions/test/__init__.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/__init__.py rename to src/generic_lambda_credentials_rotator/lambda_functions/test/__init__.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/test_aws_credential_rotator.py b/src/generic_lambda_credentials_rotator/lambda_functions/test/test_aws_credential_rotator.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/test_aws_credential_rotator.py rename to src/generic_lambda_credentials_rotator/lambda_functions/test/test_aws_credential_rotator.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/test_circleci.py b/src/generic_lambda_credentials_rotator/lambda_functions/test/test_circleci.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/test_circleci.py rename to src/generic_lambda_credentials_rotator/lambda_functions/test/test_circleci.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/test_retry.py b/src/generic_lambda_credentials_rotator/lambda_functions/test/test_retry.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/test_retry.py rename to src/generic_lambda_credentials_rotator/lambda_functions/test/test_retry.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/test_secrets_data_source.py b/src/generic_lambda_credentials_rotator/lambda_functions/test/test_secrets_data_source.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/test_secrets_data_source.py rename to src/generic_lambda_credentials_rotator/lambda_functions/test/test_secrets_data_source.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/test_secrets_manager_helper.py b/src/generic_lambda_credentials_rotator/lambda_functions/test/test_secrets_manager_helper.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/test_secrets_manager_helper.py rename to src/generic_lambda_credentials_rotator/lambda_functions/test/test_secrets_manager_helper.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/test_static_data_source.py b/src/generic_lambda_credentials_rotator/lambda_functions/test/test_static_data_source.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/test/test_static_data_source.py rename to src/generic_lambda_credentials_rotator/lambda_functions/test/test_static_data_source.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/tests.py b/src/generic_lambda_credentials_rotator/lambda_functions/tests.py similarity index 100% rename from src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_functions/tests.py rename to src/generic_lambda_credentials_rotator/lambda_functions/tests.py diff --git a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_construct.py b/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_construct.py index af7cafa..42ea0fb 100644 --- a/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_construct.py +++ b/src/release_artifacts_resources/ios/cdk/cdk/credential_rotation/lambda_construct.py @@ -20,7 +20,7 @@ def __init__( self.credential_rotator = aws_lambda_python.PythonFunction( self, "credential_rotation_lambda", - entry="cdk/credential_rotation/lambda_functions/src", + entry="../../../generic_lambda_credentials_rotator/lambda_functions/src", index="handler.py", runtime=aws_lambda.Runtime.PYTHON_3_7, role=iam_construct.lambda_role, From 9d11aae3efa02060216cbfce0676046fddb7772c Mon Sep 17 00:00:00 2001 From: Jithin Roy Date: Wed, 20 Oct 2021 10:34:14 -0700 Subject: [PATCH 2/2] Updated readme --- src/generic_lambda_credentials_rotator/README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/generic_lambda_credentials_rotator/README.md b/src/generic_lambda_credentials_rotator/README.md index 6e19b1d..409603a 100644 --- a/src/generic_lambda_credentials_rotator/README.md +++ b/src/generic_lambda_credentials_rotator/README.md @@ -1,6 +1,6 @@ # Generic Lambda Credentials Rotator -Generic Lambda Credentials Rotator is a AWS Lambda function that can be set up to move credentials and other artifacts from one source to another destination. Few use cases: +Generic Lambda Credentials Rotator is a AWS Lambda function that can be used to move credentials and other artifacts from one source to another destination. This package can be included into any cdk package to enable credential rotation. Few use cases: 1. Create temprorary AWS credentials and push the credentials to CircleCI environment variable. 2. Move values in lambda environment variable to CircleCI environment variable. @@ -9,6 +9,16 @@ Generic Lambda Credentials Rotator is a AWS Lambda function that can be set up t ## Destination supported: - CircleCI environment variable + - Input structure: + ``` + "": { + "type": "cci_env_variable", + "description": "", + "github_path": "/", + "circleci_api_token_secret_id_lambda_env_var_key": "" + } + ``` + - AWS Lambda requires api token from CircleCI to push values to CircleCI environment variable. This api key should be stored in AWS Secrets Manager, and the key for the secret should be stored as environment variable in lambda function. `circleci_api_token_secret_id_lambda_env_var_key` above stores the key info for this lambda environment variable. ## Sources supported: @@ -16,7 +26,7 @@ Generic Lambda Credentials Rotator is a AWS Lambda function that can be set up t - Lambda environment Variables - Secrets in AWS Secrets Manager -## Input format: +## Complete Input format: ```cli {