What is the most effective way to securely store a Token for Firebase cloud functions?

Currently, I have a Firebase cloud function that utilizes express middleware to generate an authToken and passes it through the routes. This token has a 24-hour lifespan, so to avoid overloading the service with excessive requests, I am looking to cache the result for a period before regenerating it.

Two approaches have been considered:

  1. Investigating how to cache the axios request while generating the token.
  2. Utilizing Firebase Secret Manager to store the value.

During my research on axios caching, I already had Secret Manager in use, so both methods are being implemented concurrently.

Secret Manager

The current implementation involves using Secret Manager to store and update the token. Whenever I need the token for the external API, I can retrieve it from Secret Manager directly.

A scheduled job is set up to create a new token and disable all previous secret versions before adding the latest token.

The token creation process uses axios to call the authentication endpoint of the external API.

Axios Caching

Regarding implementing caching for express in cloud functions, additional complexities like CDN or Redis solutions seem necessary. I've come across intermediate cache options like cachios, which seems to leverage local memory. Would this mean that each cloud function instance in different regions has its own unique local cache? Is this a potential issue, or is it a more lightweight option compared to setting up Redis?

My Dilemma

I'm wondering if relying on Secret Manager for this purpose is a bad idea since it's typically meant for storing long-lived values that don't change frequently. Having potentially multiple versions stored daily could accumulate clutter in Secret Manager. Alternatively, would opting for a CDN or implementing an express caching layer be a more standard approach? If so, is there any straightforward guidance on setting up an express caching layer tailored for Google Firebase cloud functions?

Answer №1

It is recommended to make 2 requests per day. For more information on rotating keys, please refer to the documentation provided at: https://cloud.google.com/secret-manager/docs/rotation-recommendations

Approach 2 & 3 suggest that valid use cases include fetching secrets upon each launch and continuously retrieving secrets. Making 2 requests per day falls within this frequency range.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Three instances of 'Socket.io: io.on('connection)' were repeated consecutively

Displayed below is a snippet of server side code found in the starting point of the application: const app = express() const chatServer = require('http').Server(app); chatServer.listen(3000) const io = require('socket.io')(chatServer); ...

What is preventing me from accessing my JavaScript files with Express.js/Node.js?

Recently, I decided to delve into the world of nodejs/expressjs/coffeescript and the jade view engine. The setup I have seems pretty standard based on examples I've come across. app = express.createServer().listen process.env.PORT app.config ...

Exploring the benefits of leveraging Express with SSL security features

I recently acquired a Comodo SSL certificate for setting up an SSL server with express. The certificates I have include: AddTrustExternalCARoot.crt COMODORSAAddTrustCA.crt COMODORSADomainValidationSecureServerCA.crt mysite.com.key mysite.com.csr mysite_co ...

Discovering the unique identifier of an item in Node.js is simple with these steps

I have a delete API which requires the item's unique ID to be passed in for deletion. How can I capture the ID of the item being deleted and send it to the API? Here is the API: app.post("/delete_product", function (req, res) { var data = { ...

When utilizing an Express application, what is the process for a JavaScript file within the public folder to interact with the database API located in the index.js file within

The main goal of this project is to enable the retrieval of data from a MySQL database located at localhost/phpmyadmin by simply clicking a button on the client side. The retrieved data will then be utilized to populate a table within the client interface. ...

Passing variables between different routes in Express

I'm facing an issue with sharing a variable between routes in my index.js file. Specifically, I need to access the variable "page" from the first route in the second route. Do I need to implement a closure for this purpose? Here are my two routes: Fi ...

Adding a characteristic to every item in an array of objects

Currently, I am utilizing Node.js along with Mongoose to interact with a MongoDB database and retrieve an array of objects from a specific collection. However, my aim is to add an additional property to each of these retrieved objects. Below, you can see t ...

Unable to retrieve the .attr() from a button that was created using handlebars

I am currently working on developing a web scraper as part of a homework task that involves using Express, Mongoose, Cheerio/axios, and Handlebars. In my "/" route, I retrieve the Mongoose objects and use Handlebars to display them on the page in individua ...

Upon completion of the user registration process, the req.isAuthenticated method is showing a false

I've encountered this issue in a few of my previous apps and I'm unsure what's causing it. When I navigate to the login page and successfully log in a user, everything works as expected and I have access to the logged-in user. However, when ...

Issues with parsing application/json data in NodeJS using Express

As a newcomer to setting up a NodeJS express JSON REST API, I am encountering challenges in retrieving the JSON data from both GET and POST requests. Here is the code snippet that I am currently working with: var bodyParser = require("body-parser"); con ...

Guide to sending a post request in Node.js using Mongoose

I recently tried to follow a tutorial (https://medium.com/weekly-webtips/building-restful-apis-with-node-js-and-express-a9f648219f5b) from 2 years ago to build an API. However, I'm struggling to update the code to work with more recent changes in the ...

Error in returnTo behavior. The URL is being deleted just before making the post request

I have implemented express-session and included a middleware that assigns the value of req.session.returnTo to the originalUrl. router.post( '/login', passport.authenticate('local', { failureFlash: true, failureRedirect: &ap ...

Transfer data from Node.js to J2ee via binary upload and receive a corresponding reply

I am in need of assistance with my Node express server. The server receives a binary file (pdf) from a client and I must send this binary file as it is to a Java servlet. Currently, I am using the following code snippet to accomplish this task by utilizing ...

Incremented value in MongoDB not increasing further after initial incrementation

Currently, I've been working on a project that involves creating a URL shortener. The main goal is to increment the 'views' count every time someone accesses the API or makes a GET request. However, I'm facing an issue where the views a ...

What is the most effective method for obtaining the deployed server version?

I typically monitor my server's version by referencing the version field in my package.json. It can be quite beneficial to have a /version route for quickly checking the deployed version. Here is what I am considering: app.get('/version', ...

Providing structured Express app to deliver HTML and JavaScript content

Currently, I am working with Express and facing a seemingly simple challenge. Here is the structure of my directories: |-config |---config.js |---routes.js |-server.js |-scripts |---controllers |------controllers.js |---directive ...

What steps should be followed in order to generate a child or item with no assigned key

Here is my TypeScript code designed to automatically record the time of data creation: import * as functions from 'firebase-functions'; export const onAccCreate = functions.database .ref('/Agent/{AgentID}') .onCreate((snapshot, contex ...

Node.js encountering issues with multiple concurrent connections to SQL servers in mssql due to interference between them

I am currently utilizing mssql in my Node.js express application to establish connections with multiple databases on various SQL servers. To illustrate the basic structure of my code, I have created the following example: app.get('/api/example') ...

The Google Drive API in Node.js is notifying the deletion of files

I encountered an issue with the Google Drive API in my application. Even after deleting files from Google Drive, the listfiles function still returns those deleted files. Is there a solution to prevent this from happening? Below is the function of my API: ...

What should I do when using _.extend() in express - override or add in fields?

When an object is extended by another object with values set for some of the extended fields, will it be rewritten or will the new values be added? For example: const PATCH_REQUEST_SCHEMA = { 'type': 'object', 'title' ...