npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aws-credstash

v3.0.1

Published

Node.js credstash using AWS DynamoDB and KMS. Fork of nodecredstash

Downloads

1,347

Readme

aws-credstash

Use credstash in NodeJS

Drop-in replacement for nodecredstash, API fully compatible (largely unmodified fork of nodecredstash).

Why this fork:

  • Allows your module to enforce the version of aws-sdk: is now a peer dependency
  • Types are updated by package maintainer

See Release Changelog for more information

Installation

$ npm install aws-credstash

Usage

Store and retrieve a secret:

import Credstash from "aws-credstash";

const credstash = new Credstash({
  table: "credential-store",
  awsOpts: { region: "us-west-2" },
});

(async () => {
  const name = "Death Star vulnerability";
  const context = { app: "db", enviroment: "production" };
  const version = await credstash.incrementVersion({ name });
  await credstash.putSecret({ name, secret: "Exhaust vent", version, context });
  console.log("Secret updated!");

  const secret = await credstash.getSecret({ name, context });
  console.log(secret); // 'Exhaust vent'
})();

API

Credstash(CredstashConfig)

Returns a new credstash instance

CredstashConfig

Type: object

table

Type: string
Default: credential-store

The DynamoDB table to store credentials

kmsKey

Type: string
Default: alias/credstash

The name of the KMS key created for credstash.

awsOpts

Type: AWS.KMS.ClientConfiguration

Options to be passed to the aws-sdk instance for DynamoDB and KMS Specifig configurations can be found for DynamoDB and KMS. region can be sent in as a parameter, or you can follow other AWS conventions for setting the region

Example:

{
  "region": "us-east-1"
}

dynamoOpts

Options that are specific to the DynamoDB configuration. Defaults can still be assigned in awsOpts, but they can be overridden just for dynamoDb here

kmsOpts

Options that are specific to the KMS configuration. Defaults can still be assigned in awsOpts, but they can be overridden just for kms here

Common Options

name

The name of the secret that will be stored in DynamoDB

version

Can be a string or number. If it is a number, then aws-credstash will pad it with 0s so it can be sorted.

context

Used to get the encryption key from KMS.

Type: object

callback

An optional callback function when you don't want to use promises;

credstash.getSecret(
  {
    name: "Death Star plans",
    context: { rebelShip: "true" },
  },
  function (err, res) {
    if (err) {
      throw new Error("The Death Star plans are not in the main computer.");
    }
  }
);

credstash

Credstash instance

.createDdbTable([cb])

Create the table in DynamoDB using the table option

.putSecret({name, secret, [version], [context]}, [cb])

Encode a secret and place it in DynamoDB.

credstash.putSecret({
  name: "Death Star Vulnerability",
  secret: "Exhaust vent",
  context: { rebel: "true" },
});

DynamoDB will now contain a record for this entry that looks like:

{
  "name": "Death Star Vulnerability", //
  "key": "...", // The value sent to KMS to retrieve the decryption key
  "version": "0000000000000000001", // The version string, should be sorteable
  "hmac": "...", // An HMAC validation value
  "contents": "..." // The AES 128 encrypted value
}

getHighestVersion({name}, [cb])

Returns the first sorted result for the given name key.

incrementVersion({name}, [cb])

Returns the next incremented version version for the given name key.

.getSecret({ name, [version], [context] }, [cb])

Retrieve a decrypted secret from DynamoDB

.getAllSecrets({[version], [context], [startsWith]}, [cb])

Retrieve all decrypted secrets from DynamoDB.

The startsWith option will filter the response

credstash
  .getAllSecrets({ context: { rebel: "true" } })
  .then((secrets) => console.log(JSON.stringify(secrets, null, 2)));
{
  "Death Star vulnerability": "Exhaust vent"
}

.getAllVersions({name, [limit]}, [cb])

Retrieve all or the last N(limit) versions of a secret.

credstash
  .getAllVersions({
    name: "Death Star vulnerability",
    limit: 2,
    context: { rebel: "true" },
  })
  .then((secrets) => console.log(JSON.stringify(secrets, null, 2)));
[
  { version: "0000000000000000006", secret: "Exhaust vent" },
  { version: "0000000000000000005", secret: "Destroy vent" },
];

.listSecrets([cb])

Retrieve all stored secrets and their highest version

credstash
  .listSecrets()
  .then((list) => console.log(JSON.stringify(list, null, 2)));
[
  {
    name: "Death Star",
    version: "0000000000000000001",
  },
  {
    name: "Death Star vulnerability",
    version: "0000000000000000001",
  },
];

.deleteSecret({name, version}, [cb])

Delete the desired secret by version from DynamoDB


credstash.deleteSecret({name: 'Death Star', version: 1})
// 'Deleting Death Star -- version 0000000000000000001'
  .then(() => credstash.list())
  .then(list => console.log(JSON.stringify(list, null, 2));
[
  {
    name: "Death Star vulnerability",
    version: "0000000000000000001",
  },
];

.deleteSecrets(name)

Deletes all of the versions of name


credstash.deleteSecrets({name: 'Death Star vulnerability'})
// 'Deleting Death Star vulnerability -- version 0000000000000000001'
  .then(() => credstash.listSecrets())
  .then(list => console.log(JSON.stringify(list, null, 2));
[];