• Stars
    star
    113
  • Rank 310,115 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ”‘๐Ÿ”โ˜๏ธ Serverless plugin to encrypt variables with KMS (DEPRECATED)

Serverless KMS Secrets (DEPRECATED)

A Serverless Plugin for the Serverless Framework which helps with encrypting service secrets using the AWS Key Management Service (KMS)

THIS MODULE IS NO LONGER MAINTAINED. The best practice for managing secrets, also supported out-of-the-box by Serverless Framework, is to use the AWS SSM parameter store. See https://serverless.com/framework/docs/providers/aws/guide/variables/#reference-variables-using-the-ssm-parameter-store

Introduction

This plugins does the following:

  • It provides commands to encrypt and decrypt secrets with KMS

Installation and configuration

In your service root, run:

npm install --save-dev serverless-kms-secrets

Add the plugin to serverless.yml:

plugins:
  - serverless-kms-secrets

Configure the plugin into the custom block in serverless.yml. For example:

custom:
  serverless-kms-secrets:
    secretsFile: kms-secrets.${opt:stage, self:provider.stage}.${opt:region, self:provider.region}.yml (optional)
  kmsSecrets: ${file(kms-secrets.${opt:stage, self:provider.stage}.${opt:region, self:provider.region}.yml)}

By default, the plugin creates secrets to the file kms-secrets.[stage].[region].yml. This can be overriden with the secretsFile parameter in the serverless-kms-secrets configuration.

Add Decrypt permissions to your lambda function with e.g. this block in IamRoleStatements:

    - Effect: Allow
      Action:
      - KMS:Decrypt
      Resource: ${self:custom.kmsSecrets.keyArn} 

Usage

Creating KMS Key

Create a KMS key in AWS IAM service, under Encryption keys. Collect the key id, which is the remaining part of the key ARN.

Encrypting Variables

To encrypt a variable using the key defined in the configuration, enter

sls encrypt -n VARIABLE_NAME -v myvalue [-k keyId]

e.g.

sls encrypt -n SLACK_API_TOKEN -v xoxp-1234567890-1234567890-123467890-a12346 -k 999999-9999-99999-999

The keyid (-k) parameter is mandatory for the first encrypted variable, but optional for the later ones (will be read from the secrets file). The encrypted variable is written to your secrets file (kms-secrets.[stage].[region].yml by default)

You may also pack multiple secrets into one KMS encrypted string. This simplifies consuming the secrets in the Lambda function since all secrets can be decrypted with one single KMS.Decrypt call. To encrypt multiple secrets into one single string, use the following notation:

sls encrypt -n VARIABLE_NAME:SECRET_NAME -v myvalue [-k keyId]

e.g.

sls encrypt -n SECRETS:SLACK_API_TOKEN -v xoxp-1234567890-1234567890-123467890-a12346 -k 999999-9999-99999-999

Would encrypt and add the SLACK_API_TOKEN into the (JSON) secret SECRETS.

NOTE: you may get warnings about the missing kms-secrets file when encrypting your first variables for a specific stage / region. The warning will go away once the file has been created by the plugin.

Decrypting Variables

The variables in the secrets file can be decrypted using

sls decrypt [-n VARIABLE_NAME]

The -n option is optional. Without that, all variables are decrypted and displayed in clear text on the console.

Using variables

Pass the variables stored in the secrets file e.g. as environment variables using

  environment:
    MY_VARIABLE: ${self:custom.kmsSecrets.secrets.MY_VARIABLE}

The variable must be decrypted in the Lambda function using the KMS decrypt method. E.g.

kms.decrypt({
  CiphertextBlob: Buffer(process.env.MY_VARIABLE, 'base64')
}).promise()
.then(data => {
  const decrypted = String(data.Plaintext)
})

If MY_VARIABLE consists of multiple variables, decode it using

  const secrets = JSON.parse(decrypted);

TODO

  • Add support for sls deploy (deploy as KMS encrypted environment variables)
  • Ease configuration (KeyIds / Arns in various places)

Release History

  • 2019/02/24 - v1.0.4 - Fix issue with serverless 1.33
  • 2017/09/09 - v1.0.0 - Add support for multisecret structures
  • 2017/05/13 - v0.9.0 - Initial version

License

Copyright (c) 2017 Nordcloud, licensed for users and contributors under MIT license. https://github.com/nordcloud/serverless-kms-secrets/blob/master/LICENSE

More Repositories

1

serverless-mocha-plugin

Plugin for Serverless Framework which adds support for test-driven development using Mocha
JavaScript
160
star
2

serverless-jest-plugin

Plugin for Serverless Framework which adds support for test-driven development using Jest
JavaScript
120
star
3

serverless-plugin-additional-stacks

Additional Stacks Plugin for Serverless 1.x
JavaScript
101
star
4

cognitocurl

๐Ÿฆ‰๐Ÿค–Easily sign curl calls to API Gateway with Cognito authorization token.
TypeScript
90
star
5

serverless-boilerplate

Serverless project template
JavaScript
82
star
6

pat-frontend-template

React frontend template based on Vite for Nordcloud's Platform & Tools
TypeScript
58
star
7

assume-role-arn

๐Ÿค–๐ŸŽฉassume-role-arn allows you to easily assume an AWS IAM role in your CI/CD pipelines, without worrying about external dependencies.
Go
55
star
8

azure-pipelines-templates

Templates to be reused in our Azure Pipelines projects
31
star
9

lambda-wrapper

Wrapper for running lambda modules locally during development
JavaScript
30
star
10

GNUI

๐Ÿ’… Nordcloud's design system for SaaS products.
TypeScript
30
star
11

cognito-authorizer

Build your AWS API Gateway custom authorizer lambda without the need to handle tokens by yourself. Just implement the logic...
Go
24
star
12

aws-assume-role

GitHub action to assume subsequent AWS roles
Shell
23
star
13

aws-codepipeline-cfn-provider

โ˜๏ธโœจโš™๏ธAWS Codepipeline Lambda to deploy stuff using AWS CloudFormation.
Python
23
star
14

azure-tag-manager

Azure Tag Manager, enforce tags at scale.
Go
21
star
15

codepipeline-datadog-events

Tool for monitoring AWS CodePipeline status and pushing events to Datadog, Slack and Cloudwatch.
TypeScript
20
star
16

cognito-go-auth

Simple library to sign requests using cognito Google federated authentication.
Go
17
star
17

cfn-encrypt

๐Ÿ”‘๐Ÿ”โ˜๏ธ Cloudformation custom resource that enables creation of KMS encrypted strings and SSM secure parameters
Python
13
star
18

cfn-datadog

๐Ÿ•โš™๏ธCloudformation custom resources that integrate with datadog
Python
10
star
19

mfacli

Go
9
star
20

azure-go-example

๐Ÿ––Example app in go Azure SDK
Go
8
star
21

terraform-provider-imagefactory

ImageFactory terraform provider
Go
7
star
22

aws-rds-manager

โ˜๏ธ๐Ÿ› โœจ Provides utilities for the management of RDS snapshots
Python
6
star
23

ncerrors

An error wrapping library with an ability to add arbitrary fields to errors and record stack trace.
Go
4
star
24

mca-cli

CLI to help automating MCA work
TypeScript
4
star
25

mca-monitoring

Separate library for MCA monitoring generated with MCA CLI.
TypeScript
3
star
26

serverless.fi

serverless.fi website
HTML
2
star
27

klarity-scanner-vmware-cli

Klarity self-hosted scanner for your VMware environments
Go
2
star
28

klarity-apps-examples

Klarity apps examples, free to use
1
star
29

cloudtrail-activity-events

1
star
30

serverless-tdd-plugin

serverless-mocha-plugin reborn.
JavaScript
1
star
31

nordcloud-webassembly-lambda-demo

Nordcloud WebAssembly Lambda Demo
TypeScript
1
star
32

eslint-config-pat

Shareable ESLint config for PAT projects
JavaScript
1
star
33

log-forwarder

Golang based application to consume exported Cloud Logging entries via Pub/Sub subscription and log the entries on configured, central GCP Project.
Go
1
star
34

pytanko-bot

โ‰๏ธ Pytanko bot to post questions into a graphQL api (check https://github.com/nordcloud/pytanko-ui)
Go
1
star
35

lambdas-presentation-2018

JavaScript
1
star
36

aksworkshop

1
star
37

supermaestro-manifest-example

1
star
38

azure-cloud-foundation

1
star
39

kubernetes-fast-track-program

The Kubernetes Fast-Track program is an initiative to fast-track Nordcloud engineers onto Kubernetes. This Github project provides the necessary materials and tools to practice using Docker containers and Kubernetes.
Dockerfile
1
star