@mu-ts/kms

1.0.5 • Public • Published

AWS KMS

Simpler access to KMS.

References

Usage

Code....

import { decrypt, encrypt } from '@mu-ts/kms';

const context: {[key:string]: string} = { 'context': 'value' };
const key:string = 'key-arn' | 'key-id' | 'alias' | 'alias-arn';
const pulicSecret: string = '...';
const encryptedSecret: string = await encrypt(publicSecret, key, context);
const decryptedSecret: string = await decrypt(encryptedSecret, key, context);

Where possible, be sure to separate out your permissions so that the encryptor cant decrypt and the encryptor can't encrypt.

{
  "Effect": "Allow",
  "Principal": {
    "AWS": "arn:aws:iam::111122223333:role/RoleForExampleApp"
  },
  "Action": "kms:Decrypt",
  "Resource": "*",
  "Condition": {
    "ForAnyValue:StringEquals": {
      "kms:EncryptionContext:AppName": "ExampleApp"
    }
  }
}

KMS Key Creation

Declare your KMS key.

Type: AWS::KMS::Key
Properties:
  Description: Encryption key for transaction information.
  Enabled: true
  EnableKeyRotation: true
  KeyUsage: ENCRYPT_DECRYPT
  PendingWindowInDays: 30
  KeyPolicy:
    Version: '2012-10-17'
    Id: this-key-policy-name
    Statement:
    - Sid: Enable IAM User Permissions
      Effect: Allow
      Principal: # Or the specific role for the function (s) using the key
        AWS:
          Fn::Join:
          - ''
          - - 'arn:aws:iam::'
            - Ref: AWS::AccountId
            - :root
      Action: kms:*
      Resource: '*'
  Tags:
    - environment: production
    - service: my-service
    - stage: this-stage

Readme

Keywords

Package Sidebar

Install

npm i @mu-ts/kms

Weekly Downloads

0

Version

1.0.5

License

ISC

Unpacked Size

8.85 kB

Total Files

8

Last publish

Collaborators

  • jeff-authvia
  • matt-filion
  • strandedmusician