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

Support SSH tunnel #869

Open
2 tasks done
oliviertassinari opened this issue Aug 29, 2022 · 1 comment
Open
2 tasks done

Support SSH tunnel #869

oliviertassinari opened this issue Aug 29, 2022 · 1 comment
Labels
feature: Connections PostgreSQL, MySQL, etc. new feature New feature or request priority: low To delay as much as possible scope: toolpad-studio Abbreviated to "studio" waiting for 👍 Waiting for upvotes

Comments

@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 29, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

Make it possible to connect to a database using a bastion.

Examples 🌈

Screenshot 2022-08-29 at 16 33 53

Screenshot 2022-10-13 at 22 53 09

Motivation 🔦

https://serverfault.com/questions/283172/is-it-safe-to-open-port-3306-in-firewall-for-external-mysql-connection

@oliviertassinari oliviertassinari added waiting for 👍 Waiting for upvotes priority: low To delay as much as possible feature: Connections PostgreSQL, MySQL, etc. labels Aug 29, 2022
@oliviertassinari oliviertassinari changed the title Add SSH tunnel support Support SSH tunnel Oct 24, 2022
@oliviertassinari oliviertassinari added the new feature New feature or request label Nov 30, 2022
@oliviertassinari
Copy link
Member Author

oliviertassinari commented Jan 27, 2023

I had this problem trying to access the MUI Store MySQL panel. Normally, we would use our Bastion with SSH tunnel. I couldn't so instead, I used https://api.ipify.org?format=json to find Toolpad's IP and whitelisted it to access MySQL.

Screenshot 2023-01-27 at 12 46 52

But on render.com, the IP of the instance is not stable, so I can't easily whitelist the IPs.


In pipedream, I'm doing it manually as they don't support it natively:

module.exports = defineComponent({
  props: {
    mysql: {
      type: "app",
      app: "mysql",
    }
  },
  async run({steps, $}) {
    const mysql = require('mysql2/promise');
    const SSH2Promise = require('ssh2-promise');

    const { host, port, username, password, database } = this.mysql.$auth

    const ssh = new SSH2Promise({
      host: bastionHost,
      port: bastionPort,
      username: bastionUsername,
      privateKey: bastionPipedreamPrivateKey,
    });

    const tunnel = await ssh.addTunnel({
      remoteAddr: host,
      remotePort: port,
    })

    const connection = await mysql.createConnection({
      host: 'localhost',
      port: tunnel.localPort,
      user: username,
      password,
      database,
    });

    const [rows] = await connection.execute(
      // Note - manually created orders might not have u.id if created as guest.
      // That's okay, as emailing a customer or reseller AP mailbox isn't helpful
      `SELECT
          post.id as orderID,
          post.post_date as date,`,
      [fromDateString, toDateString]
    );

    await connection.end();
    await ssh.close();

    return {};
  },
})

@prakhargupta1 prakhargupta1 added the scope: toolpad-studio Abbreviated to "studio" label Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: Connections PostgreSQL, MySQL, etc. new feature New feature or request priority: low To delay as much as possible scope: toolpad-studio Abbreviated to "studio" waiting for 👍 Waiting for upvotes
Projects
None yet
Development

No branches or pull requests

2 participants