Skip to main content

CF-Signer - CloudFormation Signing Utility

https://img.shields.io/pypi/v/cf-signer.svg https://img.shields.io/travis/avishayil/cf-signer.svg Documentation Status

Tool for signing and verifying the integrity of CloudFormation templates

Features

  • Signing CloudFormation templates by creating a sha256 hash of the file, encrypted with the user’s private key and store base64 form of the signature in the CloudFormation template Metadata section.

  • Verifying the integrity of CloudFormation templates by looking for the signature in the Metadata, extracting it and verifying.

  • Currently support JSON templates only. If you need to convert your template from YAML format, take a look on the CloudFormation Designer conversion or use a 3rd party utility.

Usage

Installation

To install cf-signer, run this command in your terminal:

pip install cf-signer

Preparation

First, the utility provides the prepare functionality that does the following:

  • Reading your template JSON file

  • Converting the template to Python dictionary object.

  • Converting the Python dictionary object back to a JSON file.

This is done to ensure that the tool will not tamper the template contents during the signing process.

To prepare a CloudFormation template to the signing process:

cf_signer --prepare --template cf.template

This will create a cf-prepared.template file you can sign using the cf-signer tool.

Getting Started

To sign a CloudFormation template using the cf-signer tool:

cf_signer --sign --template cf.template --key key.pem

To verify a signature of a CloudFormation template using the cf-signer tool:

cf_signer --verify --template cf-signed.template --key pubkey.pem

You can also use cf_signer in your Python code to sign templates on your scripts:

import cf_signer

def main():
    sign_result = create_signature(target_file_path='tests/cf.template', key_file_path='tests/key.pem') # Returns True

Signing Flow

The process of signing is based on the following flow:

  • Generate RSA private key:

    openssl genrsa -out key.pem 2048
  • Get public key from the RSA generated private key:

    openssl rsa -in key.pem -outform PEM -pubout -out pubkey.pem
  • Create a sha256 hash signature, encrypted with the private key:

    openssl dgst -sha256 -sign key.pem -out sign.sha256 cf.template
  • Convert the signature to base64 string:

    base64 -i sign.sha256 -o sign.b64
  • Attach the base64 signature to the CloudFormation template, under the Metadata block (creating one if it doesn’t exist).

Verification Flow

The process of signature verification is based on the following flow:

  • Detach the signature from the CloudFormation template

  • Convert the base64 detached signature string to binary format:

    base64 -d sign.b64 > sign.sha256
  • Validate the signature using the public key:

    openssl dgst -sha256 -verify pubkey.pem -signature sign.sha256 cf.template

Credits

History

0.0.1 (2021-06-22)

  • First release on PyPI.

0.0.2 (2021-06-22)

  • feat: prepare template before signing

  • feat: clear linter errors

  • chore: version bump and documentation updates regarding installation

0.0.3 (2021-06-23)

  • feat: added the usecase of using the library in python code, added pylint

Metadata

Release files for cf-signer 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cf-signer 0.0.3
File Size Uploaded
cf_signer-0.0.3.tar.gz 20.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cf-signer 0.0.3
File Interpreter ABI Platform
cf_signer-0.0.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 27.9 kB

Release files / cf_signer-0.0.3.tar.gz

Download URL cf_signer-0.0.3.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4a905e101749454f2c8940b9b8e99fa2d954893365e5166a81ccd9ea977e36df
BLAKE2b-256 checksum
How to use checksums
66fe5ab074124ea32936089cfa2e1d681914cf8c5c825c39233872a08c685172
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.7

Release files / cf_signer-0.0.3-py2.py3-none-any.whl

Download URL cf_signer-0.0.3-py2.py3-none-any.whl
Size 7.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f86042d26135ac19c6d97c57c2396a452e65c097dfa3650f0fa644cc07abbe53
BLAKE2b-256 checksum
How to use checksums
9ebde728ef76ed20f02231eb82008d57808ef981adbed79a56f385d05601e067
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.7

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page