occlum/demos/python/flask
2024-05-29 16:55:02 +08:00
..
build_occlum_instance.sh Update demos to enable EDMM features 2023-11-07 09:26:20 +08:00
flask.yaml Add flask tls server demo 2022-03-07 16:05:08 +08:00
gen-cert.sh Signed-off-by: 景涛 <jingtao3@hust.edu.cn> 2023-04-18 13:12:37 +08:00
install_python_with_conda.sh [demos] Fix flask demo run failure 2024-05-29 16:55:02 +08:00
README.md Add flask tls server demo 2022-03-07 16:05:08 +08:00
rest_api.py Add flask tls server demo 2022-03-07 16:05:08 +08:00
run_flask_on_occlum.sh Add flask tls server demo 2022-03-07 16:05:08 +08:00

Flask TLS demo on Occlum

This project demonstrates how Occlum enables unmodified Python program flask running in SGX enclaves, which is based on glibc.

Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications.

Sample Code: Flask TLS demo in Python

To make the sample code more realistic, we choose to start a simple Flask TLS server by flask-restful. The sample code can be found here.

How to Run

This tutorial is written under the assumption that you have Docker installed and use Occlum in a Docker container.

  • Step 1: Download miniconda and install python to prefix position.
bash ./install_python_with_conda.sh
  • Step 2: Generate sample cert/key
bash ./gen-cert.sh
  • Step 3: Build Flask TLS Occlum instance
bash ./build_occlum_instance.sh
  • Step 4: Start the Flask TLS server on Occlum
bash ./run_flask_on_occlum.sh

It starts a sample Flask server like below:

occlum run /bin/rest_api.py
 * Serving Flask app "rest_api" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on all addresses.
   WARNING: This is a development server. Do not use it in a production deployment.
 * Running on https://localhost:4996/ (Press CTRL+C to quit)
  • Step 5: Write some customers' info, such as
# curl --cacert flask.crt -X PUT https://localhost:4996/customer/1 -d "data=Tom"
# curl --cacert flask.crt -X PUT https://localhost:4996/customer/2 -d "data=Jerry"
  • Step 6: Read the customers' info back
# curl --cacert flask.crt -X GET https://localhost:4996/customer/1
# curl --cacert flask.crt -X GET https://localhost:4996/customer/2