All Projects → nordcloud → cfn-encrypt

nordcloud / cfn-encrypt

Licence: Apache-2.0 License
🔑🔐☁️ Cloudformation custom resource that enables creation of KMS encrypted strings and SSM secure parameters

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to cfn-encrypt

go-localstack
Go Wrapper for using localstack
Stars: ✭ 56 (+330.77%)
Mutual labels:  lambda, cloudformation
takomo
Organize, parameterize and deploy your CloudFormation stacks
Stars: ✭ 27 (+107.69%)
Mutual labels:  cloudformation, stack
Hands-On-Serverless-Applications-with-Go
Hands-On Serverless Applications with Go, published by Packt.
Stars: ✭ 92 (+607.69%)
Mutual labels:  lambda, cloudformation
Awesome Aws
A curated list of awesome Amazon Web Services (AWS) libraries, open source repos, guides, blogs, and other resources. Featuring the Fiery Meter of AWSome.
Stars: ✭ 9,895 (+76015.38%)
Mutual labels:  lambda, cloudformation
cim
CIM takes the pain out of Infrastructure as Code and CloudFormation
Stars: ✭ 51 (+292.31%)
Mutual labels:  lambda, cloudformation
Lambstatus
[Maintenance mode] Serverless Status Page System
Stars: ✭ 1,323 (+10076.92%)
Mutual labels:  lambda, cloudformation
aws-cloudformation-cognito-identity-pool
A Lambda-backed Custom Resource for a Cognito Identity Pool in CloudFormation
Stars: ✭ 35 (+169.23%)
Mutual labels:  lambda, cloudformation
Serverless Domain Manager
Serverless plugin for managing custom domains with API Gateways.
Stars: ✭ 783 (+5923.08%)
Mutual labels:  lambda, cloudformation
qaz
qaz—A CLI tool for Templating & Managing stacks in AWS Cloudformation
Stars: ✭ 89 (+584.62%)
Mutual labels:  cloudformation, stack
lastkeypair
A serverless SSH certificate authority to control access to machines using IAM and Lambda
Stars: ✭ 39 (+200%)
Mutual labels:  lambda, kms
Aws Iot Certificate Vending Machine
The CVM allows a device to apply for its own certificate and installation.
Stars: ✭ 64 (+392.31%)
Mutual labels:  lambda, cloudformation
CloudWatch2S3
Logging infrastructure for exporting all CloudWatch logs from multiple accounts to a single S3 bucket
Stars: ✭ 31 (+138.46%)
Mutual labels:  lambda, cloudformation
Serverless Application
🍤 ALIS Media - Serverless Application
Stars: ✭ 52 (+300%)
Mutual labels:  lambda, cloudformation
Masuit.tools
ldqk.xyz/55
Stars: ✭ 2,539 (+19430.77%)
Mutual labels:  lambda, encryption
Aws Toolkit Vscode
AWS Toolkit for Visual Studio Code, an extension for working with AWS services including AWS Lambda.
Stars: ✭ 823 (+6230.77%)
Mutual labels:  lambda, cloudformation
aws-node-custom-user-pool
Serverless AWS Cognito Custom User Pool Example
Stars: ✭ 15 (+15.38%)
Mutual labels:  lambda, cloudformation
Cloudformation templates
AWS - CloudFormation Templates
Stars: ✭ 505 (+3784.62%)
Mutual labels:  lambda, cloudformation
Dawson Cli
A serverless web framework for Node.js on AWS (CloudFormation, CloudFront, API Gateway, Lambda)
Stars: ✭ 721 (+5446.15%)
Mutual labels:  lambda, cloudformation
aws-maven-plugin
Deploys resources to AWS using maven
Stars: ✭ 25 (+92.31%)
Mutual labels:  lambda, cloudformation
SecretsManagerwithCloudFormation
Implements a Lambda-backed CloudFormation Custom Resource for AWS Secrets Manager
Stars: ✭ 20 (+53.85%)
Mutual labels:  lambda, cloudformation

README

What is this repository for?

  • To encrypt values in cloudformation
  • To Create secure ssm parameters in cloudformation
  • To Retrieve secure ssm paramters in cloudformation

What does it do?

The repo provides two simple lambda functions

  • simple_encrypt.py: exposes the kms encrypt api to cloudformation. It does this by a custom resource called Encrypt.
  • ssm_parameter.py: Makes it possible to create ssm parameters of type SecureString in cloudformation. It does this by a custom resource called SecureParameter

Encrypt

The custom resource expects base64 encoded input and outputs base64 encrypted blob

It supports encryption context

SecureParameter

Takes name, value, description and KeyId

If the parameter name was not created in this stack update will fail

How do I get set up?

  • install the module in via pip
  pip install cfn-encrypt

template.py

This is the template that provision the lambda function.

It takes two parameters

Parameter: KmsKeyArn

This is the arn of the kms key you want to use for encryption. If the key is located in another AWS account make sure that it allows the account you create the stack in Encrypt action on the key.

Parameter: PlainText

This is just a string that will test the encryption and secure parameter functionality.

If the stack creation fails

Check the log group /aws/lambda/stack name

generate the template

 python template.py > /tmp/encrypt.template
  • create a stack using /tmp/encrypt.template
  • Make sure you do not rollback on failure, since that will delete the log group that might contain valuable information
  • Supply the KMS key arn that you want to use, and optionally a value that you want to encrypt.
  • outputs: KmsKeyArn, LambdaArn, EncryptedValue
  • exports: all outputs are exported and their names are prepended with the name of the stack

How do i use it other stacks?

Use the example template to provision the lambda function. The example template will export the arn of the lambdas

simple encrypt usage

Import the custom resource class

from cfn_encrypt import Encrypt, EncryptionContext

Create a parameter so you can reference to the template the lambda was created in

encrypt_lambda_stack = t.add_parameter(Parameter(
    "EncryptLambdaStack",
    Type="String",
    Description="Stack name of the encryption lambda"
))

Import KmsKeyArn and LambdaArn from the lambda stack

kms_key_arn = ImportValue(Sub("${EncryptLambdaStack}-KmsKeyArn"))
lambda_arn = ImportValue(Sub("${EncryptLambdaStack}-EncryptLambdaArn"))

Add a parameter for the value you want to encrypt, make sure you set NoEcho to True

my_secret = t.add_parameter(Parameter(
    "MySecret",
    Type="String",
    Description="Enter your secret",
    NoEcho=True
))

Invoke the lambda

encrypted_secret = t.add_resource(Encrypt(
    "EncryptedSecret",
    ServiceToken=lambda_arn,
    Base64Data=Base64(Ref(my_secret)),
    KmsKeyArn=kms_key_arn
))

If you want to use encryption context.

  • Note that encryption context should not be sensitive values.
 my_encrypted_value_with_context = t.add_resource(Encrypt(
    "MyEncryptedValueWithContext",
    ServiceToken=lambda_arn,
    Base64Data=Base64(Ref(plain_text)),
    KmsKeyArn=kms_key_arn,
    EncryptionContext=EncryptionContext(
        Name="Test",
        Value="Test"
    )
))

The the encrypted parameter can be retrieved base64 encoded using GetAtt

GetAtt(encrypted_secret, "CiphertextBase64"),

ssm parameter usage

Import the custom resource class

from cfn_encrypt import SecureParameter

Create a parameter so you can reference to the template the lambda was created in

encrypt_lambda_stack = t.add_parameter(Parameter(
    "EncryptLambdaStack",
    Type="String",
    Description="Stack name of the encryption lambda"
))

Import KmsKeyArn and LambdaArn from the lambda stack

kms_key_arn = ImportValue(Sub("${EncryptLambdaStack}-KmsKeyArn"))
lambda_arn = ImportValue(Sub("${EncryptLambdaStack}-EncryptLambdaArn"))

Add a parameter for the value you want to encrypt, make sure you set NoEcho to True

my_secret = t.add_parameter(Parameter(
    "MySecret",
    Type="String",
    Description="Enter your secret",
    NoEcho=True
))

Invoke the lambda


my_secure_parameter = t.add_resource(SecureParameter(
    "MySecureParameter",
    ServiceToken=lambda_arn,
    Name="MySecureParameter",
    Description="Testing secure parameter",
    Value=Ref(my_secret),
    KeyId=kms_key_arn
))

get ssm parameter

Import the custom resource class

from cfn_encrypt import GetSsmValue

Create a parameter so you can reference to the template the lambda was created in

encrypt_lambda_stack = t.add_parameter(Parameter(
    "EncryptLambdaStack",
    Type="String",
    Description="Stack name of the encryption lambda"
))

Import KmsKeyArn and LambdaArn from the lambda stack

kms_key_arn = ImportValue(Sub("${EncryptLambdaStack}-KmsKeyArn"))
lambda_arn = ImportValue(Sub("${EncryptLambdaStack}-EncryptLambdaArn"))

Invoke the lambda

my_decrypted_value = t.add_resource(GetSsmValue(
    "MyDecryptedValue",
    ServiceToken=lambda_arn,
    Name="/My/Parameter/Name",
    KeyId=kms_key_arn,
    Version=5 # Optional

))

Use GetAtt  to get information about the parameter
 'Name': 'string',
 'Type': 'String'|'StringList'|'SecureString',
 'KeyId': 'string',
'LastModifiedDate': datetime(2015, 1, 1),
'LastModifiedUser': 'string',
'Description': 'string',
'Value': 'string',
'AllowedPattern': 'string',
'Version': 123

How to contribute and report bugs

You can contribute by sending a PR to the repo.

  1. Fork the repository
  2. Make changes
  3. Issue a PR

Every PR should be backed by an issue requesting a change.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].