Connect to private Google Cloud SQL instance through Cloud SQL Auth Proxy running in Kubernetes.

Overview

google-cloud-sql

google-cloud-sql CLI Version Build Status

A CLI app which establishes a connection to a private Google Cloud SQL instance and port-forwards it to a local machine.

Connection is established by running a Google Cloud SQL Auth Proxy pod in a Google Kubernetes Engine cluster which runs in the same VPC network as the private Cloud SQL instance. Connection is then port-forwarded to the local machine, where a user can connect to the instance on localhost. Corresponding workload identity has to be configured in the cluster, with service account which has Cloud SQL Client role on the given SQL instance. Configurations in the app can be saved for practical future usage.

The app relies on local gcloud and kubectl commands which have to be configured and authenticated with the proper Google Cloud user and GKE Kubernetes cluster.

screenshot

Install

Homebrew

brew install edosrecki/tools/google-cloud-sql

# Update
brew upgrade google-cloud-sql

Releases

Download a corresponding distribution from Releases and add the executable to your PATH.

Build from source

Build the app from source by building and packaging it manually: see Build and Package sections.

Use

Prerequisites

  • Install gcloud tool

  • Install kubectl tool

  • Authenticate to Google Cloud: gcloud auth login

  • Get GKE cluster credentials: gcloud container clusters get-credentials

  • Configure workload identity in GKE namespace(s) and assign Cloud SQL Client role in IAM for Cloud SQL instances that you want to use

  • Enable Cloud SQL Admin API for project(s) that host Cloud SQL instances that you want to use: gcloud services enable sqladmin.googleapis.com --project=$PROJECT

Run

# Help
google-cloud-sql help

# Create (or override existing) configuration
google-cloud-sql configurations create

# Run configuration (interactive mode)
google-cloud-sql configurations run

# Run configuration (non-interactive mode)
google-cloud-sql configurations run $NAME

# HINT: Add alias
alias myDbProd="google-cloud-sql configurations run $NAME"

## Connect to the instance on localhost
psql -h localhost -p $LOCAL_PORT -U $USER

# Export configurations (and share :-])
cat $(google-cloud-sql configurations path)

Build

npm run clean
npm run build

Package

Pre-configured

Package the app for Node.JS 16 on MacOS, Linux, and Windows.

npm run bundle

Manual

See pkg for details.

npx pkg <NODE_RANGE>-<PLATFORM>-<ARCH>

Deploy

To deploy a new version of google-cloud-sql app, manually run a "Continuous Deployment" worklow in GitHub Actions.

Todo

  • Add snap for Linux

  • Add completions

  • Cache user’s running pods, and alert user on next startup if they were not cleaned up on previous app exit.

You might also like...

ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used

Jan 3, 2023

Lovefield is a relational database for web apps. Written in JavaScript, works cross-browser. Provides SQL-like APIs that are fast, safe, and easy to use.

Lovefield Lovefield is a relational database written in pure JavaScript. It provides SQL-like syntax and works cross-browser (currently supporting Chr

Jan 3, 2023

An SQL-friendly ORM for Node.js

Objection.js Objection.js is an ORM for Node.js that aims to stay out of your way and make it as easy as possible to use the full power of SQL and the

Jan 5, 2023

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.

Please use version 1.x as prior versions has a security flaw if you use user generated data to concat your SQL strings instead of providing them as a

Jan 9, 2023

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server & SQLite

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server & SQLite

Prisma Quickstart • Website • Docs • Examples • Blog • Slack • Twitter • Prisma 1 What is Prisma? Prisma is a next-generation ORM that consists of the

Jan 2, 2023

An adapter-based ORM for Node.js with support for mysql, mongo, postgres, mssql (SQL Server), and more

An adapter-based ORM for Node.js  with support for mysql, mongo, postgres, mssql (SQL Server), and more

Waterline is a next-generation storage and retrieval engine, and the default ORM used in the Sails framework. It provides a uniform API for accessing

Jan 4, 2023

Microsoft SQL Server client for Node.js

node-mssql Microsoft SQL Server client for Node.js Supported TDS drivers: Tedious (pure JavaScript - Windows/macOS/Linux, default) Microsoft / Contrib

Jan 4, 2023

TypeScript clients for databases that prevent SQL Injection

Safe From HTML Injection Using tagged template literals for queries, e.g. db.query(sql`SELECT * FROM users WHERE id=${userID}`); makes it virtually im

Dec 21, 2022

Conjure SQL from GraphQL queries 🧙🔮✨

Conjure SQL from GraphQL queries 🧙🔮✨

Sqlmancer Conjure SQL from your GraphQL queries 🧙 🔮 ✨ ⚠️ This project is currently on hiatus. I am hoping to resume working on Sqlmancer once I have

Oct 30, 2022
Releases(v1.8.0)
Owner
Dinko Osrecki
Dinko Osrecki
Avocano is a sample dropship/fake product website with Cloud Run, Cloud SQL and Cloud Build

Avocano - A Fake Product Website Avocano is a sample dropship/fake product website, combining: Firebase Hosting front end, written with Lit, Cloud Run

Google Cloud Platform 9 Dec 9, 2022
Azure Data Studio is a data management tool that enables you to work with SQL Server, Azure SQL DB and SQL DW from Windows, macOS and Linux.

Azure Data Studio is a data management tool that enables working with SQL Server, Azure SQL DB and SQL DW from Windows, macOS and Linux.

Microsoft 7k Dec 31, 2022
An in memory postgres DB instance for your unit tests

pg-mem is an experimental in-memory emulation of a postgres database. ❤ It works both in Node or in the browser. ⭐ this repo if you like this package,

Olivier Guimbal 1.2k Dec 30, 2022
Mercurius Auth Plugin

mercurius-auth Mercurius Auth is a plugin for Mercurius that adds configurable Authentication and Authorization support. Features: Define auth directi

null 71 Dec 23, 2022
Auth model created by Using nodeJs for backend & reactJs for frontend with the help of TailwindCss in styling

The Universal Auth System Using The MERN Stack Including Mysql --> The project is divded to two separte projects 1- The Client side -> containing the

m.bebars 1 Aug 22, 2022
A starter template for Nest.js with MongoDB, GraphQL, JWT Auth, and more!

A progressive Node.js framework for building efficient and scalable server-side applications. Description Nest framework TypeScript starter repository

Michael Guay 19 Dec 25, 2022
Basic Dapp showing how a React Dapp can connect to Cronos using MetaMask and Crypto.com Defi Wallet

cronos-dapp-basic Basic Dapp showing how a React Dapp can connect to Cronos using MetaMask and Crypto.com Defi Wallet You need to have node version 14

Acclrate 1 Dec 31, 2021
ConnectNOW - Live web application that allows you to connect with people around the world!

connectNOW Live web application that allows you to connect with people around the world! You can share images, quotes, and anything on your mind! It a

Isha Chaudhry 1 Jan 3, 2022
An easy-to-use multi SQL dialect ORM tool for Node.js

Sequelize Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features solid transaction s

Sequelize 27.3k Jan 4, 2023