Skip to main content

A secure OpenVPN authentication portal with Google OAuth2

Project description

๐Ÿ” OpenVPN Client Portal

Python 3.8+ Flask License: MIT codecov

A secure, user-friendly authentication portal for OpenVPN configuration distribution. This application provides Google OAuth2 authentication and domain-restricted access to OpenVPN configuration files.

OpenVPN Auth Portal

๐ŸŒŸ Features

  • ๐Ÿ”’ Secure Google OAuth2 authentication
  • ๐Ÿ‘ฅ Domain-restricted access control
  • ๐Ÿ“ฆ Automated OpenVPN config generation
  • ๐ŸŽจ Clean, responsive web interface
  • ๐Ÿš€ Easy deployment and configuration

๐Ÿ“ฆ Installation

Via pip

pip install gcp-ovpn-portal

Development Setup

  1. Clone the repository:
git clone https://github.com/ranson21/gcp-ovpn-portal
cd gcp-ovpn-portal
  1. Install with Poetry:
poetry install

๐Ÿ”ง Configuration

Google OAuth2 Setup

  1. Go to the Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Google OAuth2 API:
    • Go to "APIs & Services" > "Library"
    • Search for "Google OAuth2"
    • Click "Enable"
  4. Configure the OAuth consent screen:
    • Go to "APIs & Services" > "OAuth consent screen"
    • Choose "Internal" if using Google Workspace, or "External" if not
    • Fill in the application name and other required fields
    • Add the necessary scopes (email, profile)
  5. Create OAuth 2.0 credentials:
    • Go to "APIs & Services" > "Credentials"
    • Click "Create Credentials" > "OAuth client ID"
    • Choose "Web application"
    • Add authorized redirect URIs:
      • For local development: http://localhost:8081
      • For production: https://your-domain.com
    • Save your Client ID and Client Secret

Environment Variables

The following environment variables are required:

  • CLIENT_ID: Google OAuth2 client ID (obtained from steps above)
  • ALLOWED_DOMAIN: Authorized email domain (e.g., "company.com")
  • EXTERNAL_IP: VPN server's external IP address
  • OPENVPN_DIR: Directory containing OpenVPN configuration files (default: /etc/openvpn)

Create a .env file:

cp .env.example .env
# Edit .env with your configuration

Example .env file:

CLIENT_ID=your-google-client-id.apps.googleusercontent.com
ALLOWED_DOMAIN=yourcompany.com
EXTERNAL_IP=203.0.113.1
OPENVPN_DIR=/etc/openvpn

๐Ÿš€ Usage

Running as an installed package

# Run the VPN portal
ovpn-portal

Running in development mode

# Using Poetry
poetry run ovpn-portal

# Or using make
make run

๐Ÿ“ Project Structure

openvpn-auth-portal/
โ”œโ”€โ”€ ovpn_portal/
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ main/
|   โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
|   โ”‚   โ”‚   โ””โ”€โ”€ routes.py
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ config.py
โ”‚   โ”‚   โ”œโ”€โ”€ middleware.py
โ”‚   โ”‚   โ””โ”€โ”€ vpn.py
โ”‚   โ””โ”€โ”€ run.py
โ”œโ”€โ”€ static/
โ”‚   โ”œโ”€โ”€ css/
โ”‚   โ”œโ”€โ”€ images/
โ”‚   โ”œโ”€โ”€ js/
โ”‚   โ””โ”€โ”€ favicon.ico
โ”œโ”€โ”€ templates/
โ”‚   โ””โ”€โ”€ index.html
โ”œโ”€โ”€ tests/
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ .env.example
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md

๐Ÿ› ๏ธ Development

The project includes a Makefile to help with common development tasks:

First Time Setup

make dev-setup    # Install Poetry, initialize git, and install dependencies

Common Commands

make install      # Install project dependencies
make run         # Run development server
make test        # Run test suite
make coverage    # Run tests with coverage report
make format      # Format code with black and isort
make lint        # Run linting checks
make clean       # Clean temporary files and builds

Test Coverage

To run tests with coverage reporting:

make coverage

This will:

  • Run all tests with coverage tracking
  • Generate a terminal report showing missing lines
  • Create an HTML coverage report in coverage_html/

View the HTML coverage report:

make coverage-open  # On macOS
# Or open coverage_html/index.html in your browser

Package Management

make build       # Build package distribution
make develop     # Install package locally in editable mode

Publishing

make publish-test  # Publish to Test PyPI
make publish      # Publish to PyPI

You can also use Poetry directly for development tasks:

poetry install    # Install dependencies
poetry run pytest # Run tests
poetry run black . # Format code
poetry run flake8 # Lint code

๐Ÿ”’ Security Considerations

  • All authentication is performed through Google OAuth2
  • Configuration files are generated temporarily and immediately deleted after download
  • Domain restriction ensures only authorized users can access the portal
  • HTTPS is required in production

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ‘ค Author

Abigail Ranson

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gcp_ovpn_portal-0.1.0.tar.gz (215.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gcp_ovpn_portal-0.1.0-py3-none-any.whl (165.5 kB view details)

Uploaded Python 3

File details

Details for the file gcp_ovpn_portal-0.1.0.tar.gz.

File metadata

  • Download URL: gcp_ovpn_portal-0.1.0.tar.gz
  • Upload date:
  • Size: 215.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/5.10.0-32-cloud-amd64

File hashes

Hashes for gcp_ovpn_portal-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c995d61a2c1c79ee2e53cffba8028e383c5edb210a3076ee05be4680357e8250
MD5 28bac94e98f98457263ca4efaa2d6416
BLAKE2b-256 07ae46ea270f6e992dcc1da14df7a3240156c167bce2bb7c6fb1368c813bfcb9

See more details on using hashes here.

File details

Details for the file gcp_ovpn_portal-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gcp_ovpn_portal-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 165.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/5.10.0-32-cloud-amd64

File hashes

Hashes for gcp_ovpn_portal-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9abc22f509105df043f9aef9f6bc5808e46d512847d80720dae044b52a53de5
MD5 e5116ef63d847ad51437cab4e5e50348
BLAKE2b-256 4a8b2ba6087b7130ac1734d8ab99dc3028e9febe2ff3b03e2fe8acc0860be41e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page