Skip to content

Support for UNIX socket as alternative to host-port style of connection. #172

Open
@aberba

Description

@aberba

UNIX sockets provide a way to securely connect in an enclosed/isolated environment without exposing connection externally. This is used in my our microservice infrastructure on: we connect to our db instance using a proxy and its the recommended approach in microservices.

Its a very common security practice. The default approach on Google Cloud. I would do the same for any db I want to prevent external access to. If mysql-native doesn't support it then its missing a big piece of a puzzle. Database libs like mysql-native could benefit from vibe.D's implementation to support UNIX socket connection that integrates well with vibe.d.

// Vibe.d: examples/unix_socket_server/source/app.d 
auto settings = new HTTPServerSettings;
settings.bindAddresses = ["/tmp/vibe.sock"];
listenHTTP(settings, router);

Then the "/tmp/vibe.sock" will be the path to the database socket connection. An example style of this approach is in the Google Cloud SQL Nodejs demo here where they connect to the database using a proxy (UNIX socket connection) using the nodejs mysql package. Here is a snippet from the page:

const config = {
  user: process.env.SQL_USER,
  password: process.env.SQL_PASSWORD,
  database: process.env.SQL_DATABASE
};

if (process.env.INSTANCE_CONNECTION_NAME && process.env.NODE_ENV === 'production') {
  config.socketPath = `/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}`;
}

// Connect to the database
const knex = Knex({
  client: 'mysql',
  connection: config
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions