Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

fastify-secrets-gcp

Package Overview
Dependencies
Maintainers
5
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-secrets-gcp

Fastify secrets plugin for Google cloud platform secrets manager

latest
Source
npmnpm
Version
3.0.0
Version published
Maintainers
5
Created
Source

Fastify Secrets Gcp

ci

Fastify secrets plugin for Google cloud platform secrets manager

Installation

npm install --save fastify-secrets-gcp

Usage

Get permissions to access gcp secrets manager

In order to be able to read from gcp secrets manager you will need some permissions. You will also probably manage permissions in different ways in local dev and production environment.

Local dev environment

In general you may want to use a different secrets manager on your local machine (i.e. fastify-secrets-env to read secrets from env variables).

If you want run fastify-secrets-gcp in the local environment too you will need to follow these steps:

  • Create a GCP Service Account
  • Grant the new service account at least the role of "Secret Manager Secret Accessor"
  • Create key for the account
  • Download the key in json format
  • (optional) Place the key in the root of your project (make sure to add it to .gitignore to avoid commiting it)
  • Set the env variable GOOGLE_APPLICATION_CREDENTIALS to the absolute path of the downloaded key
  • You're ready to run your app

Production environment (on Cloud Run)

If you already have a custom Service Account for your service Clour Run you will need to give it access to Secrets Manager. Otherwise you will need to create a new custom Service Account with access to Secrets Manager and assign it to Cloud Run.

In any case you will need to grant the "Secret Manager Secret Accessor" role.

Add plugin to your fastify instance

const FastifySecrets = require('fastify-secrets-gcp')

fastify.register(FastifySecrets, {
  secrets: {
    dbPassword: 'projects/PROJECT-ID/secrets/SECRET-ID/versions/latest'
  }
})

Access you secrets

await fastify.ready()

console.log(fastify.secrets.dbPassword) // content of projects/PROJECT-ID/secrets/SECRET-ID/versions/latest

Plugin options

The plugin only expect the secrets object in the options.

It is a map of keys and resource ids for the secrets. fastify-secrets-gcp will decorate the fastify server with a secrets object where keys will be the same keys of the options and the value will be the content of the secret as fetched from GCP Secrets Manager

Contributing

See CONTRIBUTING.md

License

Copyright NearForm Ltd 2020. Licensed under the Apache-2.0 license.

Keywords

fastify

FAQs

Package last updated on 22 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts