Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to prod memcache #1472

Open
snarfed opened this issue Nov 12, 2024 · 6 comments
Open

Access to prod memcache #1472

snarfed opened this issue Nov 12, 2024 · 6 comments
Labels

Comments

@snarfed
Copy link
Owner

snarfed commented Nov 12, 2024

This would help my local manual datastore edits take effect more quickly. Should be straightforward, except exposing the memcache instance externally, not sure what that will take.

@snarfed snarfed removed the now label Dec 15, 2024
@snarfed snarfed changed the title Connect local Python shell to prod memcache Access to prod memcache Dec 20, 2024
@snarfed
Copy link
Owner Author

snarfed commented Dec 20, 2024

Added a custom HTTP tunnel ^ through the app itself, works ok (not great, just ok) for manual commands. Local Python shell still isn't connected though.

@snarfed snarfed added the now label Jan 21, 2025
@snarfed
Copy link
Owner Author

snarfed commented Jan 21, 2025

Getting more important, this is making manual datastore changes unreliable or not usable.

@snarfed
Copy link
Owner Author

snarfed commented Jan 22, 2025

This has the most comprehensive set of options I've seen so far for connecting to Memorystore from outside GCP: https://blog.stackademic.com/connect-to-google-cloud-memorystore-redis-from-a-local-machine-and-use-redis-in-next-js-5e5a534d45b6

Currently trying the IAP TCP forwarding route, https://cloud.google.com/iap/docs/tcp-forwarding-overview

@snarfed
Copy link
Owner Author

snarfed commented Jan 24, 2025

So one catch here is that ideally I'd set up the tunnel directly to the Memorystore instance, not to a generic Compute Engine VM. That seems uncommon, but maybe possible? At least https://stackoverflow.com/a/71428305/186123 says so. Here's what I've tried, based on the docs and posts above and that SO answer:

$ gcloud compute firewall-rules create allow-ingress-from-iap \
  --direction=INGRESS \
  --action=allow \
  --rules=tcp:11211 \
  --source-ranges=35.235.240.0/20

$ gcloud compute networks subnets update default \
  --region=us-central1 \
  --enable-private-ip-google-access

$ gcloud iap tcp dest-groups create memorystore-memcached \
  --region=us-central1 \
  --ip-range-list=10.126.144.0/24

$ gcloud iap tcp dest-groups add-iam-policy-binding \
  --member=user:[email protected] \
  --role=roles/iap.tunnelResourceAccessor \
  --dest-group=memorystore-memcached \
  --region=us-central1

$ gcloud compute start-iap-tunnel 10.126.144.3 11211 \
  --region=us-central1 \
  --network=projects/bridgy-federated/global/networks/default \
  --local-host-port=localhost:11211

...
ERROR: (gcloud.compute.start-iap-tunnel) While checking if a connection can be made: Error while connecting [4033: 'not authorized'].

...where 10.126.144.3 there is the memcache discovery IP. Not sure that's quite what I want.

https://blog.stackademic.com/securely-connect-to-google-cloud-memorystore-redis-from-your-local-machine-using-vm-and-iap-3556a6d53ab0 is relevant, but assumes I'm tunneling to a Compute Engine VM. google-github-actions/ssh-compute#44 also has this error, but no obvious answer other than IAM roles, which I've added.

@snarfed
Copy link
Owner Author

snarfed commented Jan 24, 2025

Progress maybe, changed --network and added --dest-group:

gcloud compute start-iap-tunnel 10.126.144.3 11211 \
  --region=us-central1 \
  --network=default \
  --dest-group=memorystore-memcached \
  --local-host-port=localhost:11211

...
ERROR: (gcloud.compute.start-iap-tunnel) While checking if a connection can be made: Error while connecting [4003: 'failed to connect to backend']. (Failed to connect to port 11211)

Sounds like it's setting up the tunnel, but then failing to connect to Memorystore.

@snarfed snarfed removed the now label Jan 24, 2025
@snarfed
Copy link
Owner Author

snarfed commented Jan 24, 2025

Other ideas:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant