Skip to content

Miso-K/lxd-api-gateway

Repository files navigation

lxd-api-gateway

RESTful API for LXD with USER access limitations

Use it with Dashboard

Python version


Installation

For installation actual version of lxdmanager-api-gateway you can use install.sh script.

# Download the script
curl https://raw.githubusercontent.com/Miso-K/lxd-api-gateway/master/install.sh > install.sh
# Set execution permissions
chmod +x install.sh
# Run script to install program
./install.sh

Manual installation

git clone --recursive https://github.com/Miso-K/lxd-api-gateway

Install requirements

# Installation require Redis DB for storing jwt tokens 
apt install redis-server

# install python dependencies
apt update
apt install python3-pip python3-dev build-essential libssl-dev libffi-dev python3-setuptools
apt install python3-venv

cd lxd-api-gateway

# create virtual env
python3 -m venv lgw-env

# activate env
source lgw-env/bin/activate

pip install -r requirements.txt

Change secret key to unique

nano config/default.py

Update lxdconfig.conf

nano lxdconfig.conf

Create database

python3 install/setup.py

LXD host settings

Change "example.com" to your domain. * would make it accessible from everywhere.

sudo lxc config set core.https_address [::]:8443
sudo lxc config set core.https_allowed_origin "*.example.com"
sudo lxc config set core.https_allowed_methods "GET, POST, PUT, DELETE, OPTIONS"
sudo lxc config set core.https_allowed_headers "Content-Type"
sudo service lxd restart # sometimes is required

Generate authentication certificates (Self Signed)

openssl genrsa -out lxd.key 4096 # Generate a private key.
openssl req -new -key lxd.key -out lxd.csr # Create a certificate request.
openssl x509 -req -days 3650 -in lxd.csr -signkey lxd.key -out lxd.crt # Generate an auto signed certificate.
lxc config trust add lxd.crt # Tells LXC to use this certificate for auth.

Copy lxd.crt and lxd.key to installation folder and edit lxdconfig.conf settings.


Run the server

Werkzeug (dev only)

python3 run.py

Gunicorn

gunicorn --bind :5000 app:app

uWSGI

uwsgi --socket :5000 --protocol=http --wsgi app:app

Usage

Requests

Set headers :

key value
Content-Type application/json
Authorization Bearer <token>

Documentation

Configuration

You can store instance configuration in instance/config.py

or

Set your own env var :

export LWP_CONFIG_FILE='/path/to/config/production.py'

About

LXD API gateway that adds user management options and provide API backend for lxdmanager

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published