Skip to main content

Static

Simplest secret storage that accept secrets at application start and keeps it in memory.

Simplest usage

You can create storage by providing secrets manually in the code

import {StaticSecretKeyStorage} from "@farbor/secret-key-storage";

const config: Configuration = {
secretKeyStorage: StaticSecretKeyStorage.fromObject({
// loads secrets from environment variables
key1: Buffer.from(process.env.SECRET_KEY1, 'hex'),
key2: Buffer.from(process.env.SECRET_KEY2, 'hex'),
})
}
warning

It is discouraged to use this method as it does not ensure that environment variables are defined or contains valid hex strings.

Try to use automatic loading from environment variables instead.

Loading from environment variables

All you need to do is to start app with environment variables in following format FARBOR_SECRET_[keyName] and their value set to hex string of at least 32 characters (16 bytes).

FARBOR_SECRET_key1=[some hex string] FARBOR_SECRET_key2=[some hex string] npm start 
info

There is no need to specify secretKeyStorage in configuration since it is default secret storage strategy

Modifying secrets

In order to modify secrets you obviously need to change environment variables and then restart the application.

Sometimes it might be just too cumbersome, especially where list of secrets is modified frequently. For such cases we encourage to use AWS DynamoDB secret key storage or implement custom secrets loader.