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.2.0.tar.gz (215.4 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.2.0-py3-none-any.whl (166.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gcp_ovpn_portal-0.2.0.tar.gz
  • Upload date:
  • Size: 215.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 1a65fdc9d6caf7c347040bee2eab9f4fd6fa7c81649eb7f6347871b90df1537c
MD5 1a34aeabfb216625336da8bbee1ec7ae
BLAKE2b-256 0814bb5dd65b39539f187284bf7ef32be321ceec53f736942894e4b9905b0a81

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gcp_ovpn_portal-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 166.1 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40b6f7cfc04b02adfdaa8bcc55c55466677f3747a2a1ccb86f03c1f1038e2816
MD5 0588b02cb269c4a1979d4a8acd2cffd0
BLAKE2b-256 60ccf4a8c374a00070724fd958eeaadf31db775aca85868e6d328490fc676fed

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