# carta-node-server

> NodeJS-based server for CARTA

Latest version **1.4.1** (published 2021-01-22) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install carta-node-server
pnpm add carta-node-server
yarn add carta-node-server
bun add carta-node-server
```

Provides the command `carta-node-server`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.4.1 |
| Published | 2021-01-22 |
| First published | 2020-07-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 24 |
| Unpacked size | 210.5 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | veggiesaurus, ajpm |

## Links

- npm: https://www.npmjs.com/package/carta-node-server
- Repository: https://github.com/CARTAvis/carta-node-server
- Homepage: http://cartavis.github.io/
- Issues: https://github.com/CARTAvis/carta-node-server/issues
- npm.io page: https://npm.io/package/carta-node-server

## Dependencies (24)

- [ms](https://npm.io/package/ms.md) ^2.1.2
- [ajv](https://npm.io/package/ajv.md) ^6.12.3
- [pug](https://npm.io/package/pug.md) ^3.0.0
- [cors](https://npm.io/package/cors.md) ^2.8.5
- [uuid](https://npm.io/package/uuid.md) ^8.3.0
- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [hjson](https://npm.io/package/hjson.md) ^3.2.1
- [yargs](https://npm.io/package/yargs.md) ^15.4.1
- [moment](https://npm.io/package/moment.md) ^2.27.0
- [userid](https://npm.io/package/userid.md) ^1.0.0-beta.8
- [@pm2/io](https://npm.io/package/@pm2/io.md) ^4.3.5
- [express](https://npm.io/package/express.md) ^4.17.1
- [mongodb](https://npm.io/package/mongodb.md) ^3.6.0
- [http-proxy](https://npm.io/package/http-proxy.md) ^1.18.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0
- [compression](https://npm.io/package/compression.md) ^1.7.4
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.5
- [ldapauth-fork](https://npm.io/package/ldapauth-fork.md) ^4.3.3
- [tcp-port-used](https://npm.io/package/tcp-port-used.md) ^1.0.1
- [carta-frontend](https://npm.io/package/carta-frontend.md) ^1.4.0
- [google-auth-library](https://npm.io/package/google-auth-library.md) ^6.0.6
- [@types/tcp-port-used](https://npm.io/package/@types/tcp-port-used.md) ^1.0.0
- [express-bearer-token](https://npm.io/package/express-bearer-token.md) ^2.4.0

## Recent versions

- 1.4.1 (latest) — 2021-01-22
- 2.0.0-dev.21.2.8 (dev) — 2021-02-08
- 1.4.0-rc.2 (rc) — 2020-09-18
- 1.4.0-beta.8 (beta) — 2020-09-13
- 1.0.6-alpha.0 (alpha) — 2020-08-13
- 2.0.0-dev.21.1.22 — 2021-01-22
- 2.0.0-dev.3 — 2020-12-11
- 2.0.0-dev.2 — 2020-10-29
- 2.0.0-dev.0 — 2020-09-25
- 1.4.0 — 2020-09-21
- 1.4.0-rc.1 — 2020-09-18
- 1.4.0-rc.0 — 2020-09-16
- 1.1.0-beta.7 — 2020-09-12
- 1.1.0-beta.6 — 2020-09-12
- 1.1.0-beta.4 — 2020-09-04
- … 13 more at https://npm.io/package/carta-node-server/versions

## README

# CARTA Server
[![carta version](https://img.shields.io/badge/CARTA%20Version-1.4.0-brightgreen)](https://github.com/CARTAvis/carta-backend/releases/tag/v1.4.0)
[![npm version](http://img.shields.io/npm/v/carta-node-server.svg?style=flat)](https://npmjs.org/package/carta-node-server "View this project on npm")
![last commit](https://img.shields.io/github/last-commit/CARTAvis/carta-node-server)
![commit activity](https://img.shields.io/github/commit-activity/m/CARTAvis/carta-node-server)

## Introduction

The CARTA server provides a simple dashboard which authenticates users and allows them to manage their CARTA backend processes. It also serves static frontend code to clients, and dynamically redirects authenticated client connections to the appropriate backend processes. The server can either handle authentication itself, or delegate it to an external OAuth2-based authentication server.

## Dependencies

To allow the server to serve CARTA sessions, you must give it access to an executable CARTA backend, which can be either a compiled executable or a container. If you want to use a non-standard version of the CARTA frontend, you must also build it, and adjust the server configuration to point to it. You should use the `v1.4.0` tag of [`carta-backend`](https://github.com/CARTAvis/carta-backend).

By default, the server runs on port 8000. It should be run behind a proxy, so that it can be accessed via HTTP and HTTPS. 

MongoDB is required for storing user preferences, layouts and (in the near future) server metrics. You also need a working [NodeJS LTS](https://github.com/nvm-sh/nvm#long-term-support) installation with NPM. Use `npm install` to install all Node dependencies.

## Installation

You can install the CARTA server from NPM by running `npm install -g carta-node-server` and then running `carta-node-server`.
You can also install the server from GitHub by cloning this repository, running `npm install` and then `npm run start`.

## Authentication support

The CARTA server supports three modes for authentication. All three modes use refresh and access tokens, as described in the [OAuth2 Authorization flow](https://tools.ietf.org/html/rfc6749#section-1.3.1), stored in [JWT](https://jwt.io/) format. The modes are:
- **LDAP-based authentication**: An existing LDAP server is used for user authentication. After the user's username and password configuration are validated by the LDAP server, `carta-node-server` returns a long-lived refresh token, signed with a private key, which can be exchanged by the CARTA dashboard or the CARTA frontend client for a short-lived access token.
- **Google authentication**: Google's authentication libraries are used for handling authentication. You must create a new web application in the [Google API console](https://console.developers.google.com/apis/credentials). You will then use the  client ID provided by this application in a number of places during the configuration.
- **External authentication**: This allows users to authenticate with some external OAuth2-based authentication system. This requires a fair amount of configuration, and has not been well-tested. It is assumed that the refresh token passed by the authentication system is stored as an `HttpOnly` cookie.

You can generate a private/public key pair in PEM format using `openssl`:
```shell script
openssl genrsa -out carta_private.pem 4096
openssl rsa -in carta_private.pem -outform PEM -pubout -out carta_public.pem
```

## Server Configuration
Server configuration is handled by a configuration file in JSON format, adhering to the [CARTA config schema](config/config_schema.json). Additional details can be found in the auto-generated config documentation in the `docs` folder, or the [example config](config/example_config.json). By default, the server assumes the config file is located at `/etc/carta/config.json`, but you can change this with the `--config` or `-c` command line argument when running the server. 

For external authentication systems, you may need to translate a unique ID (such as email or username) from the authenticated user information to the system user. You can do this by providing a [user lookup table](config/usertable.txt.stub), which is watched by the server and reloaded whenever it is updated.

You can alter the server's dashboard appearance by adjusting the `dashboard` field in the config file. You can change the banner image and background, and add login instructions or institutional notices.

## System Configuration

The user under which the CARTA server is running (assumed to be `carta`) must be given permission to use `sudo` to start `carta_backend` processes as any authenticated user and stop running `carta_backend` processes belonging to authenticated users. We provide a [kill script](scripts/carta_kill_script.sh) which is only able to kill processes matching the name `carta_backend`. This makes it possible to restrict what processes the `carta` user is permitted to kill.

To provide the `carta` user with these privileges, you must make modifications to the [sudoers configuration](https://www.sudo.ws/man/1.9.0/sudoers.man.html). An [example sudoers config](config/example_sudoers_conf.stub) is provided. This example allows the `carta` user to run `carta_backend` only as users belonging to a specific group (assumed to be `carta-users`), in order to deny access to unauthorized accounts.

**Please only edit your sudoers configuration with `visudo` or equivalent.**

We strongly suggest serving over HTTPS and redirecting HTTP traffic to HTTPS, especially if handling authentication internally. If you use [nginx](https://www.nginx.com/) as a proxy, you can use [this configuration example](config/example_nginx.conf.stub) as a starting point to redirect incoming traffic from port 443 to port 8000.

You can also use other HTTP servers, such as Apache. Please ensure that they are set up to forward both standard HTTP requests and WebSocket traffic to the correct port.

By default, the server attempts to write log files to the `/var/log/carta` directory. Please ensure that this directory exists and that the `carta` user has write permission.

## Running the server

- Checkout and build [carta-backend](https://github.com/CARTAvis/carta-backend) using the `v1.4.0` tag (or create the appropriate container). Detailed instructions for Ubuntu 20.04 are available [here](docs/ubuntu_focal_detailed_install.md).
- Edit the server configuration file at `/etc/carta/config.json`
- Perform system configuration:
    - Ensure `/var/log/carta` exists and is writeable by the appropriate user    
    - Adjust the sudoers configuration
    - Redirect traffic to port 8000

After you have built the backend and edited the server configuration, you can start the server with `npm run start` (if cloning from the git repository) or just running `carta-node-server` (if installing from NPM). You can use a utility such as [forever](https://github.com/foreversd/forever) or [pm2](https://pm2.keymetrics.io/) to keep the server running.

## Getting help

If you encounter a problem with the server or documentation, please submit an issue in this repo. If you need assistance in configuration or deployment, please contact the [CARTA helpdesk](mailto:carta_helpdesk@asiaa.sinica.edu.tw).

## TODO

Still to be implemented:
- Better error feedback
- More flexibility with external auth

---
_Source: https://npm.io/package/carta-node-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
