Skip to content

Commit 45276dc

Browse files
author
Prabhakar Kumar
committed
Introducing Token-Based Authentication. See SECURITY.md for more details.
Deprecate python 3.6 Support Introduce python 3.10 Support Small Bug fixes Closes GH-2
1 parent fc7741a commit 45276dc

File tree

93 files changed

+1588
-677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1588
-677
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020-2021 The MathWorks, Inc
1+
# Copyright (c) 2020-2022 The MathWorks, Inc
22

33
name: Release to PyPI
44

@@ -39,10 +39,10 @@ jobs:
3939
with:
4040
ref: ${{github.sha}}
4141

42-
- name: Set up Python 3.6
42+
- name: Set up Python 3.7
4343
uses: actions/setup-python@v2
4444
with:
45-
python-version: 3.6
45+
python-version: 3.7
4646

4747
- name: Install dependencies
4848
# Installing wheel package will slightly speed-up installing dependencies.
@@ -66,10 +66,10 @@ jobs:
6666
with:
6767
ref: ${{github.sha}}
6868

69-
- name: Set up Python 3.6
69+
- name: Set up Python 3.7
7070
uses: actions/setup-python@v2
7171
with:
72-
python-version: 3.6
72+
python-version: 3.7
7373

7474
- name: Install Python build dependencies
7575
run: |
@@ -97,10 +97,10 @@ jobs:
9797
# with:
9898
# ref: ${{github.sha}}
9999

100-
# - name: Set up Python 3.6
100+
# - name: Set up Python 3.7
101101
# uses: actions/setup-python@v2
102102
# with:
103-
# python-version: 3.6
103+
# python-version: 3.7
104104

105105
# - name: Install Python build dependencies
106106
# run: |
@@ -120,5 +120,5 @@ jobs:
120120
# cd ./anaconda
121121
# conda skeleton pypi matlab-proxy
122122
# python parse_meta_file.py
123-
# conda build ./matlab-proxy --python 3.6 --output-folder ./build
123+
# conda build ./matlab-proxy --python 3.7 --output-folder ./build
124124
# $CONDA/bin/anaconda upload --label main ./build/linux-64/matlab*.tar.gz

.github/workflows/run-tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020-2021 The MathWorks, Inc
1+
# Copyright (c) 2020-2022 The MathWorks, Inc
22

33
name: Testing MATLAB Proxy
44

@@ -31,9 +31,10 @@ jobs:
3131

3232
python_tests:
3333
runs-on: ubuntu-latest
34+
continue-on-error: True
3435
strategy:
3536
matrix:
36-
python-version: [3.6, 3.7, 3.8, 3.9]
37+
python-version: [3.7, 3.8, 3.9, 3.10.x]
3738

3839
steps:
3940
- name: Checkout

Advanced-Usage.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Advanced Usage
2+
Copyright (c) 2020-2022 The MathWorks, Inc. All rights reserved.
23

34
This page lists some of the advanced manuevers that may be of specific interest to help configure the package for use in your environment.
45

@@ -19,11 +20,13 @@ The following table describes all the environment variables that you can set to
1920
| **MWI_APP_PORT** | integer | `8080` | Specify the port for the HTTP server to listen on. |
2021
| **MWI_LOG_LEVEL** | string | `"CRITICAL"` | Specify the Python log level to be one of the following `NOTSET`, `DEBUG`, `INFO`, `WARN`, `ERROR`, or `CRITICAL`. For more information on Python log levels, see [Logging Levels](https://docs.python.org/3/library/logging.html#logging-levels) .<br />The default value is `INFO`. |
2122
| **MWI_LOG_FILE** | string | `"/tmp/logs.txt"` | Specify the full path to the file where you want debug logs from this integration to be written. |
22-
| **MWI_WEB_LOGGING_ENABLED** | string | `"True"` | Set this value to `"true"` to see additional web server logs. |
23+
| **MWI_ENABLE_WEB_LOGGING** | string | `"True"` | Set this value to `"True"` to see additional web server logs. |
2324
| **MWI_CUSTOM_HTTP_HEADERS** | string |`'{"Content-Security-Policy": "frame-ancestors *.example.com:*"}'`<br /> OR <br />`"/path/to/your/custom/http-headers.json"` |Specify valid HTTP headers as JSON data in a string format. <br /> Alternatively, specify the full path to the JSON file containing valid HTTP headers instead. These headers are injected into the HTTP response sent to the browser. </br> For more information, see the [Custom HTTP Headers](#custom-http-headers) section.|
2425
| **TMPDIR** or **TMP** | string | `"/path/for/MATLAB/to/use/as/tmp"` | Set either one of these variables to control the temporary folder used by MATLAB. `TMPDIR` takes precedence over `TMP` and if neither variable is set, `/tmp` is the default value used by MATLAB. |
25-
| **MWI_SSL_CERT_FILE** | string | `"/path/to/certificate.pem"` | The certfile string must be the path to a single file in PEM format containing the certificate as well as any number of CA certificates needed to establish the certificate’s authenticity. |
26-
| **MWI_SSL_KEY_FILE** | string | `"/path/to/keyfile.key"` | The keyfile string, if present, must point to a file containing the private key in. Otherwise the private key will be taken from certfile as well. |
26+
| **MWI_SSL_CERT_FILE** | string | `"/path/to/certificate.pem"` | The certfile string must be the path to a single file in PEM format containing the certificate as well as any number of CA certificates needed to establish the certificate’s authenticity. See [SSL Support](./SECURITY.md#ssl-support) for more information.|
27+
| **MWI_SSL_KEY_FILE** | string | `"/path/to/keyfile.key"` | The keyfile string, if present, must point to a file containing the private key. Otherwise the private key will be taken from certfile as well. |
28+
| **MWI_ENABLE_TOKEN_AUTH** | string | `"True"` | When set to `True`, matlab-proxy will require users to provide the security token to access the proxy. <br />The default value is `False` . See [Token-Based Authentication](./SECURITY.md#token-based-authentication) for more information.|
29+
| **MWI_AUTH_TOKEN** | string (optional) | `"AnyURLSafeToken"` | Optionally, provide a custom `token` for use with `MWI_ENABLE_TOKEN_AUTH`. A token can safely contain any combination of alpha numeric text along with the following permitted characters: `- . _ ~`.<br />When absent matlab-proxy will generate a random URL safe token. |
2730

2831

2932
## Custom HTTP Headers

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The files in this GitHub repository refer to commercial software products and se
44

55
The following license terms apply only to the files in this GitHub repository, including files in this folder and its subfolders, and do not apply to MathWorks Programs. References to “software” and “code” in the following license terms refer to the files in this GitHub repository.
66

7-
Copyright (c) 2020, The MathWorks, Inc.
7+
Copyright (c) 2020-2022, The MathWorks, Inc.
88

99
All rights reserved.
1010

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
# MATLAB Proxy
2-
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/mathworks/matlab-proxy/Testing%20MATLAB%20Proxy?logo=github)](https://github.com/mathworks/matlab-proxy/actions) [![PyPI badge](https://img.shields.io/pypi/v/matlab-proxy.svg?logo=pypi)](https://pypi.python.org/pypi/matlab-proxy) [![codecov](https://codecov.io/gh/mathworks/matlab-proxy/branch/main/graph/badge.svg?token=ZW3SESKCSS)](https://codecov.io/gh/mathworks/matlab-proxy)
32

4-
Copyright (c) 2021 The MathWorks, Inc. All rights reserved.
3+
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/mathworks/matlab-proxy/Testing%20MATLAB%20Proxy?logo=github)](https://github.com/mathworks/matlab-proxy/actions) &nbsp; [![PyPI badge](https://img.shields.io/pypi/v/matlab-proxy.svg?logo=pypi)](https://pypi.python.org/pypi/matlab-proxy) &nbsp; [![codecov](https://codecov.io/gh/mathworks/matlab-proxy/branch/main/graph/badge.svg?token=ZW3SESKCSS)](https://codecov.io/gh/mathworks/matlab-proxy) &nbsp; [![Downloads](https://static.pepy.tech/personalized-badge/matlab-proxy?period=month&units=international_system&left_color=grey&right_color=blue&left_text=PyPI%20downloads/month)](https://pepy.tech/project/matlab-proxy)
4+
5+
Copyright (c) 2020-2022 The MathWorks, Inc. All rights reserved.
56

67
----
8+
79
`matlab-proxy` is a Python® package which enables you to launch MATLAB® and access it from a web browser.
810

911
Installation of this package creates an executable `matlab-proxy-app`, which launches MATLAB and provides a URL to access it.
1012

1113
The MATLAB Proxy is under active development. For support or to report issues, see the [Feedback](#feedback) section.
1214

1315
----
16+
17+
**Table of Contents**
18+
- [Requirements](#requirements)
19+
- [Installation](#installation)
20+
- [PyPI](#pypi)
21+
- [Building From Sources](#building-from-sources)
22+
- [Usage](#usage)
23+
- [Examples](#examples)
24+
- [Limitations](#limitations)
25+
- [Security](#security)
26+
- [Feedback](#feedback)
27+
1428
## Requirements
1529
* Linux® operating system
1630

@@ -34,7 +48,7 @@ The MATLAB Proxy is under active development. For support or to report issues, s
3448

3549
$ sudo yum install xorg-x11-server-Xvfb
3650
```
37-
* Python versions: **3.6** | **3.7** | **3.8** | **3.9**
51+
* Python versions: **3.7** | **3.8** | **3.9** | **3.10**
3852
* [Browser Requirements](https://www.mathworks.com/support/requirements/browser-requirements.html)
3953

4054
## Installation
@@ -120,6 +134,13 @@ The following options are available in the status panel (some options are only a
120134
This package supports the same subset of MATLAB features and commands as MATLAB® Online, except there is no support for Simulink® Online.
121135
[Click here for a full list of Specifications and Limitations for MATLAB Online](https://www.mathworks.com/products/matlab-online/limitations.html).
122136

137+
## Security
138+
We take your security concerns seriously, and will attempt to address all concerns.
139+
`matlab-proxy` uses several other python packages, and depend on them to fix their own vulnerabilities.
140+
141+
All security patches will be released as a new version of the package.
142+
Patches are never backported to older versions or releases of the package.
143+
Using the latest version will provide the latest available security updates or patches.
123144

124145
## Feedback
125146

SECURITY.md

Lines changed: 203 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,206 @@
1-
Reporting Security Vulnerabilities
2-
==================================
1+
# Security
2+
Copyright (c) 2020-2022 The MathWorks, Inc. All rights reserved.
3+
4+
----
5+
**Table of Contents:**
6+
- [Reporting Security Vulnerabilities](#reporting-security-vulnerabilities)
7+
- [Security Features](#security-features)
8+
- [**SSL Support**](#ssl-support)
9+
- [**Token-Based Authentication**](#token-based-authentication)
10+
- [**Use with auto-generated tokens**](#use-with-auto-generated-tokens)
11+
- [**Specify your own token**](#specify-your-own-token)
12+
- [**Use Token Authentication with SSL enabled**](#use-token-authentication-with-ssl-enabled)
13+
- [**Token Recovery**](#token-recovery)
14+
- [**Recover tokens from the machine**](#recover-tokens-from-the-machine)
15+
- [**Recover token from a previously authenticated browser session**](#recover-token-from-a-previously-authenticated-browser-session)
16+
- [Security Best Practices](#security-best-practices)
17+
18+
## Reporting Security Vulnerabilities
319
If you believe you have discovered a security vulnerability, please report it to
420
[email protected] instead of GitHub. Please see
521
[MathWorks Vulnerability Disclosure Policy for Security Researchers](https://www.mathworks.com/company/aboutus/policies_statements/vulnerability-disclosure-policy.html)
6-
for additional information.
22+
for additional information.
23+
24+
----
25+
26+
## Security Features
27+
The following features are available in `matlab-proxy` to provide secure access to MATLAB:
28+
- [SSL Support](#ssl-support)
29+
- [Token-Based Authentication](#token-based-authentication)
30+
31+
----
32+
33+
## **SSL Support**
34+
Configure `matlab-proxy` to use SSL by providing the desired SSL certificates using the following environment variables at server launch:
35+
The following environment variables must be set to enable `matlab-proxy` to run on SSL:
36+
1. *MWI_SSL_CERT_FILE*
37+
38+
A string with the full path to a single file in PEM format containing the certificate as well as any number of CA certificates needed to establish the certificate’s authenticity.
39+
40+
2. *MWI_SSL_KEY_FILE*
41+
42+
A string with the full path to a file containing the private key. If absent, the private key must be present in the certfile provided with *MWI_SSL_CERT_FILE*.
43+
44+
Example:
45+
```bash
46+
# Launch matlab-proxy with SSL enabled
47+
$ env MWI_SSL_CERT_FILE="/path/to/certificate.pem" MWI_SSL_KEY_FILE="/path/to/keyfile.key" matlab-proxy-app
48+
49+
# The access link is presented in the terminal upon startup like follows:
50+
==================================================================================================
51+
MATLAB can be accessed at:
52+
https://127.0.0.1:37109
53+
==================================================================================================
54+
55+
# NOTE: The server is running HTTP(S) !
56+
57+
```
58+
59+
----
60+
61+
## **Token-Based Authentication**
62+
63+
`matlab-proxy` is a web server and that allows one to launch and access MATLAB on the machine the server is running on.
64+
By default anyone with access to the server can access MATLAB and thereby the machine on which its running.
65+
66+
When `Token-Based Authentication` is enabled, the server will require a token to authenticate access.
67+
This token can be provided to the server in 2 ways:
68+
69+
1. Through the [URL parameter](https://www.rfc-editor.org/rfc/rfc3986#section-3.4) : `mwi_auth_token`. Example:
70+
```html
71+
https://localhost:8888/?mwi_auth_token=abcdef...
72+
```
73+
Once provided, this information is cached in the browser and will be used in subsequent interactions
74+
75+
2. Through the password field on the page that is presented when the user is not already logged in.
76+
<p align="left">
77+
<img width="600" src="./img/token_authentication_page.png">
78+
</p>
79+
80+
**NOTE** : Its highly recommended to use this feature along with SSL enabled as shown [here](#use-token-authentication-with-ssl-enabled).
81+
82+
### **Use with auto-generated tokens**
83+
84+
Enable `Token-Based Authentication` by setting the environment variable `MWI_ENABLE_TOKEN_AUTH` to `True` on server launch.
85+
86+
When enabled, `matlab-proxy` will require the URL to specify the access token using the [query component](https://www.rfc-editor.org/rfc/rfc3986#section-3.4) `mwi_auth_token`.
87+
88+
Example:
89+
90+
```bash
91+
92+
# Launch matlab-proxy with Token-Based Authentication enabled
93+
$ env MWI_ENABLE_TOKEN_AUTH=True matlab-proxy-app
94+
95+
# The access link is presented in the terminal upon startup like follows:
96+
==================================================================================================
97+
MATLAB can be accessed at:
98+
http://127.0.0.1:37109?mwi_auth_token=SY78vUw5qyf0JTJzGK4mKJlk_exkzL_SMFJyilbGtNI
99+
==================================================================================================
100+
```
101+
In this example `SY78vUw5qyf0JTJzGK4mKJlk_exkzL_SMFJyilbGtNI` is the token that the server would need for all future communication.
102+
103+
After initial access, this token is cached by the browser, and all subsequent access from the same browser to the server will not require this token.
104+
You will however need this token to access the server from a new browser session or if you have cleared cookies or have cookies disabled.
105+
106+
### **Specify your own token**
107+
108+
*Optionally*, you can also specify your own secret token using the environment variable `MWI_AUTH_TOKEN`.
109+
Ensure that your custom token is url safe.
110+
A token can safely contain any combination of alpha numeric text along with the following permitted characters: `- . _ ~`
111+
112+
See [URI Specification RFC3986](https://www.ietf.org/rfc/rfc3986.txt) for more information on URL safe characters.
113+
114+
Example:
115+
```bash
116+
117+
# Launch matlab-proxy with Token-Based Authentication enabled, and with custom token with a value of "MyCustomSecretToken"
118+
$ env MWI_ENABLE_TOKEN_AUTH=True MWI_AUTH_TOKEN=MyCustomSecretToken matlab-proxy-app
119+
120+
# The access link is presented in the terminal upon startup like follows:
121+
==================================================================================================
122+
MATLAB can be accessed at:
123+
http://127.0.0.1:37109?mwi_auth_token=MyCustomSecretToken
124+
==================================================================================================
125+
```
126+
127+
### **Use Token Authentication with SSL enabled**
128+
129+
It is recommended to enable both `Token-Based Authentication` and `SSL` to secure your access to MATLAB via matlab-proxy. As an example, the following command enables access to MATLAB using HTTPS and token-based authentication
130+
131+
For example, the following command launches the server to deliver content on `HTTPS` along with Token-Based Authentication enabled:
132+
```bash
133+
# Launch matlab-proxy with Token-Based Authentication & SSL enabled with custom token with a value of "asdf"
134+
$ env MWI_SSL_CERT_FILE="/path/to/certificate.pem" MWI_SSL_KEY_FILE="/path/to/keyfile.key" MWI_ENABLE_TOKEN_AUTH=True MWI_AUTH_TOKEN=asdf matlab-proxy-app
135+
136+
# The access link is presented in the terminal upon startup like follows:
137+
==================================================================================================
138+
MATLAB can be accessed at:
139+
https://127.0.0.1:37109?mwi_auth_token=asdf
140+
==================================================================================================
141+
142+
# NOTE: This server is running HTTP(S) !
143+
144+
```
145+
146+
### **Token Recovery**
147+
148+
To recover tokens for a previously launched server, you will need access to either:
149+
150+
1. The machine on which the server was launched, while being logged in as the user that launched the server.
151+
2. An authenticated browser session launched for the same user.
152+
153+
#### **Recover tokens from the machine**
154+
155+
1. Login to the machine on which the servers are running, as the user that launched matlab-proxy.
156+
1. Activate the python environment from which the server was launched.
157+
* This should be the same environment from which the server was launched.
158+
* Run the executable `matlab-proxy-app-list-servers`
159+
160+
Example:
161+
```bash
162+
163+
# Connect to the machine on which the server was started:
164+
$ ssh test-user@usermachine
165+
166+
# Running this command should print all running servers!
167+
(usermachine) $ matlab-proxy-app-list-servers
168+
169+
-------------------------------------------------------------------------------------------------------------------
170+
Your running servers are:
171+
-------------------------------------------------------------------------------------------------------------------
172+
1. https://127.0.0.1:46525/asdf?mwi_auth_token=asdfasdf
173+
2. http://127.0.0.1:39057/test?mwi_auth_token=_qNJIXEbnXwrj9nxZwbJiWno0YqYSh8BMdQOR6K67y0
174+
3. http://127.0.0.1:35647/test?mwi_auth_token=r6djdrcf591PttYlDZcVL78xIa1XgCviM9dQD-BrqDE
175+
4. http://127.0.0.1:36537/test?mwi_auth_token=HdQ-9tooAzA0A0CrpUxP1e5crQBErMQC3tPGTkTtrVo
176+
5. http://127.0.0.1:35433/test
177+
-------------------------------------------------------------------------------------------------------------------
178+
Thank you.
179+
-------------------------------------------------------------------------------------------------------------------
180+
```
181+
182+
For servers for which `Token-Based Authentication` were enabled, the URLs above will include their tokens.
183+
You can use them to gain access to your server as described in the [Introduction](#introduction).
184+
185+
#### **Recover token from a previously authenticated browser session**
186+
187+
1. Navigate to a browser window in which you had previously used the server.
188+
```bash
189+
# Lets assume this was the server:
190+
http://127.0.0.1:36537/test
191+
```
192+
1. Edit the URL to access the endpoint `mwi_auth_token`
193+
```html
194+
http://127.0.0.1:36537/test/get_mwi_auth_token
195+
```
196+
This should take you to a screen which prints the `mwi_auth_token` for that server, as shown below:
197+
<p align="left">
198+
<img width="600" src="./img/recover_mwi_auth_token.png">
199+
</p>
200+
201+
## Security Best Practices
202+
203+
* Never share access to your server
204+
Never share URLs from `matlab-proxy` with others. Doing so is equivalent to sharing your user account.
205+
206+
* System administrators who launch `matlab-proxy` for other users, must launch the proxy as the user for whom the server is intended.

0 commit comments

Comments
 (0)