4.1.4 • Published 9 days ago

mte-relay-server v4.1.4

Weekly downloads
-
License
ISC
Repository
github
Last release
9 days ago

MTE Relay Server

MTE Relay Server is one half of an end-to-end encryption system that protects all network requests with next-generation application data security, on prem or in the cloud. MTE Relay Server acts as a proxy-server that sits in front of your normal server, and communicates with an MTE Relay Client, encoding and decoding all network traffic. MTE Relay Server is highly customizable and can be configured to integrate with a number of other services through the use of custom adapters.

Installation

Please use the CLI command below to scaffold a new MTE Relay Server project.

cd ~/Desktop
npx create-mte-relay-server@latest

Quick Start Guide

  • Configure mte-relay-config.yaml file
  • Update the .npmrc file with your auth token. This can be found in the Eclypses Developer's Portal.
  • Install your MTE library package. This can be found in the Eclypses Developer's Portal.
    • Example: npm i mte@npm:@eclypses/my-mte-library
  • Run locally with npm run start

Config File

In the newly created directory is an mte-relay-config.yaml file with various configuration options for your instance of MTE Relay Server. Edit the file to match your application's requirements.

Configuration Options

The configuration file is a YAML file that contains the following properties. Examples are shown below.

  • upstream
    • Required
    • The upstream application that inbound requests will be proxied to.
  • licenseCompany
  • licenseKey
  • clientIdSecret
    • Required
    • A secret that will be used to sign the x-mte-client-id header. A 32+ character string is recommended.
  • corsOrigins
    • A list of URLs that will be allowed to make cross-origin requests to the server. Required by browsers to communicate with this server.
  • port
    • The port that the server will listen on.
    • Default: 8080.
  • debug
    • A flag that enables debug logging.
    • Default: false
  • passThroughRoutes
    • A list of routes that will be passed through to the upstream application without being MTE encoded/decoded.
  • mteRoutes
    • A list of routes that will be MTE encoded/decoded. If this optional property is included, only the routes listed will be MTE encoded/decoded, and any routes not listed here or in passThroughRoutes will 404. If this optional property is not included, all routes not listed in passThroughRoutes will be MTE encoded/decoded.
  • corsMethods
    • A list of HTTP methods that will be allowed to make cross-origin requests to the server.
    • Default: GET, POST, PUT, DELETE.
    • Note: OPTIONS and HEAD are always allowed.
  • headers
    • An object of headers that will be added to all request/responses.
  • maxPoolSize
    • The number of encoder objects and decoder objects held in a pool. A larger pool will consume more memory, but it will also handle more traffic more quickly. This number is applied to all four pools; the MTE Encoder, MTE Decoder, MKE Encoder, and MKE Decoder pools.
    • Default: 25

Minimal Configuration Example

upstream: https://api.my-company.com
licenseCompany: My Company, LLC.
licenseKey: 4vHSvWLTRvwx+JoThgT0p0kE
clientIdSecret: 2DkV4DDabehO8cifDktdF9elKJL0CKrk
corsOrigins:
  - https://www.my-company.com
  - https://dashboard.my-company.com

Full Configuration Example

upstream: https://api.my-company.com
licenseCompany: My Company, LLC.
licenseKey: 4vHSvWLTRvwx+JoThgT0p0kE
clientIdSecret: 2DkV4DDabehO8cifDktdF9elKJL0CKrk
corsOrigins:
  - https://www.my-company.com
  - https://dashboard.my-company.com
port: 3000
debug: true
passThroughRoutes:
  - /health
  - /version
mteRoutes:
  - /api/v1/*
  - /api/v2/*
corsMethods:
  - GET
  - POST
  - DELETE
headers:
  x-service-name: mte-relay

Local Implementation

To run MTE Relay Server locally on your hardware, follow these instructions:

  • Install your MTE library package. This can be found in the Eclypses Developer Portal.
    • Example: npm i mte@npm:@eclypses/my-mte-library
  • Start the proxy server with npm run start

Docker Implementation

To run MTE Relay Server in a Docker container, follow these instructions:

  • Update the .npmrc file with youR auth token. This can be found in the Eclypses Developer Portal.
  • Update the Dockerfile with your MTE library package name
  • Update the docker-compose.yml file with
    • A local directory that can be used to persist application data
    • The absolute path to your mte-relay-config.yaml file
  • Build the Docker image with docker build . -t mte-relay-server
  • Run the Docker container with the command docker compose up

Settings Adapter

If you don't want to (or can't) use a yaml file to load settings, you can write your own settings adapter. The settings adapter must export a function that returns a promise that resolves to a settings object with all the required settings (see Configuration Options).

module.exports = async function () {
  /* Load settings from somewhere... */
  const settings = loadSettings();
  return settings;
};

Then, you need to use a CLI flag to point to that settings file when starting the server.

npm run start -- --settings-adapter /path_to/settings-adapter.js

See more examples in the examples/settings-adapters directory.

MTE State Cache Adapter

By default, MTE State is saved in-memory. This means that if the server is restarted, all MTE State will be lost. To persist MTE State across server restarts, or to share MTE state between multiple containers, you can use an external cache by writing your own cache adapter.

A cache adapter is a file that exports a function that returns a Promise that resolves to an object with the following methods:

module.exports = async function () {
  return {
    takeState: async function (key) {
      // Return the MTE State for the given key
    },
    saveState: async function (key, state) {
      // Save the MTE State for the given key
    },
  };
};

Then, you need to use a CLI flag to point to that cache adapter file when starting the server.

npm run start -- --cache-adapter /path_to/cache-adapter.js

See examples in the examples/cache-adapters directory.

Log Adapter

MTE Relay Server is built on Fastify, which uses Pino for logging. By default, logs are written to the /data/mte-relay-server.log file. To change this, you can use a log adapter. You may write your own Pino log transport, or use an existing Pino log transport.

A log adapter is a file that exports a function that returns a Promise that resolves a Pino Transport:

Example:\

const path = require("path");

module.exports = async function () {
  return {
    transport: {
      target: "pino/file",
      options: {
        destination: path.join(process.cwd(), "/path_to/custom.log"),
      },
    },
  };
};

Then, you need to use a CLI flag to point to that log adapter file when starting the server.

npm run start -- --log-adapter /path_to/log-adapter.js

See examples in the examples/log-adapters directory.

Startup Scripts

If you need to run some logic on server start up, you may do so by passing the --startup-script <path_to/file.js> flag to the start command. The file should export a function that returns a promise that resolves when you're done with your custom startup logic.

npm run start -- --startup-script /path_to/startup.js

See examples in the examples/startup-scripts directory.

Local Development

  • Follow the quick start guide to configure requires files and install dependencies.
  • Run npm run dev to start the server in development mode.
4.1.4

9 days ago

4.1.3

13 days ago

4.1.2

1 month ago

4.1.1

1 month ago

4.1.0

2 months ago

4.0.1

2 months ago

4.0.0

2 months ago

4.0.0-beta.6

2 months ago

4.0.0-beta.5

2 months ago

4.0.0-beta.4

2 months ago

4.0.0-beta.3

3 months ago

4.0.0-beta.2

3 months ago

3.4.3

3 months ago

3.4.2

3 months ago

3.4.1

3 months ago

4.0.0-beta.1

3 months ago

3.4.0

4 months ago

3.3.0

5 months ago

3.2.1

5 months ago

3.2.0

5 months ago

3.1.2

8 months ago

3.0.2

8 months ago

3.0.1

8 months ago

3.0.0-beta.1

9 months ago

3.0.0-beta.0

9 months ago

3.0.0-beta.3

9 months ago

3.0.0-beta.2

9 months ago

2.1.2

10 months ago

2.1.1

10 months ago

2.1.4

10 months ago

2.1.3

10 months ago

2.1.6

10 months ago

2.1.8

10 months ago

2.1.7

10 months ago

2.0.0-beta.2

11 months ago

2.0.0-beta.1

11 months ago

2.0.0-beta.0

11 months ago

2.1.0

10 months ago

2.0.0

11 months ago

2.0.0-beta.3

11 months ago

3.0.0

9 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

1.0.3

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago