Search code examples
google-cloud-platformexpress-sessiongoogle-cloud-memorystore

Redis(Memorystore) clearing out keys


I am using express-sessions and Redis(Memorystore) 5.0 to save sessions and it appears Redis is clearing out all the keys(randomly and not at intervals) way before the TTL on a key runs out. Leaving only a couple of backup entries

here is a screenshot

This entry should be valid for another week judging from the TTL.

I have never configured a Redis instance before and it is likely I misconfigured this one, some insight would be appreciated.

Also, this is what I get when I run monitor

enter image description here


Solution

  • Avoid exposing your Memorystore instance through the external IP of your Compute Engine. Combined with the fact that Memorystore instances currently requires no authentication, this will lead to a vulnerability that will allow anyone to read, write and execute scripts on your instance. On the worst case scenario, it will allow someone to mine cryptocurrency using your instance, hence causing a suspension on your project or account unfortunately.

    There are multiple guides online to connect to Memorystore remotely. I suggest connecting through SSH by following this thread: Accessing GCP Memorystore from local machines

    For reference, I will paste the answer here (credits to the person who posted it):

    "If your Redis machine has internal IP address 10.0.0.3 you'd do:

    gcloud compute instances create redis-forwarder --machine-type=f1-micro
    gcloud compute ssh redis-forwarder -- -N -L 6379:10.0.0.3:6379
    

    As long as you keep the ssh tunnel open you can connect to localhost:6379"