Package: cloudchain
# cloudchain: Easy, Secure Secretscloudchain is designed to make it easy to store and retrieve secrets using AWS. cloudchain relies on the AWS Identity and Access Management (IAM) [Key Management Service][1] (KMS) to securely store and manage access to encryption keys, and stores the encrypted secret in a [DynamoDB][2] table.There are three steps in the process. First, cloudchain retrieves an encryption key from KMS and uses it to encrypt the plain text secret. The boto3 library used returns a dictionary with a “Ciphertext” entry containing the encrypted key. cloudchain then base64 encodes the encrypted key into a string, and saves that string to a DynamoDB table named, by default, “safedb”.## SetupInstall with pip:pip install cloudchainA new encryption key should be created in KMS. Using the console makes this easy, and sets up permissions to the key using IAM users or Roles. IAM users should be given permission individually, while instances launching in AWS should be identified by a role.A new DynamoDB table should be created as well. Run this command using the AWS CLI tools:aws dynamodb create-table –table-name safedb –attribute-definitions AttributeName=Service,AttributeType=S AttributeName=Username,AttributeType=S –key-schema AttributeName=Service,KeyType=HASH AttributeName=Username,KeyType=RANGE –provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1This will create the DynamoDB table with two attributes: Service and Username. cloudchain assumes that the combination of a service and a username will require a unique secret. The first time a secret is written to the table the third “Secret” attribute is created.## ConfigurationThe cloudchain cli,cchain, looks for a configuration file at~/.cchainrc. This should be a standard Python ConfigParser compatible file with the following format:[dynamo]
region_name = us-east-1
endpoint_url =https://dynamodb.us-east-1.amazonaws.comtablename = safedb[IAMKMS]
keyalias = alias/keyThe “keyalias” should be the name of the KMS encryption key created during the setup, prefixed by “alias/”. The “endpoint_url” should point at the closest HTTPS endpoint, or at localhost if using a local development environment.## Import cloudchain as a ModuleBoth thetest.pyunit tests and thecchaincli importcloudchain.py. After importing, cloudchain expects four variables to be set:region_nameendpoint_urltablenamekeyaliasReasonable defaults are mentioned in the configuration section above, but thekeyaliasmust be unique.After importing, cloudchain can be called on to encrypt and decrypt secrets:To Encrypt:cloudchain.savecreds(args[‘service’], args[‘user’], args[‘save’])To Decrypt:cloudchain.readcreds(args[‘service’], args[‘user’])Where:service = The service name the username and secret are associated withuser = The usernamesave = The unencrypted secret to encrypt## Command Line UseThe command line script supports five arguments:-h,--helpshow this help message and exit-uUSER,--userUSERUser name-eSERVICE,--serviceSERVICEService or application-sSAVE,--saveSAVESave password to the safe-r,--readRead password from the safeThe–saveand–readarguments are mutually exclusive, and cannot be used at the same time.–saveexpects the unencrypted secret as an argument, and requires both–userand–serviceflags.–userexpects the username as an argument.–serviceexpects the service name as an argument.–readrequires no arguments, and requires both–userand–serviceflags.### ExamplesTo save a secret:cchain -u testuser –service testservice –save testsecreetTo retrieve a secret:cchain -u testuser –service testservice –read[1]:https://aws.amazon.com/kms/?tag=duckduckgo-osx-20[2]:https://aws.amazon.com/dynamodb/