Skip to main content

A secure OpenVPN authentication portal with Google OAuth2

Project description

๐Ÿ” OpenVPN Authentication Portal

Python 3.8+ Flask License: MIT codecov Code Coverage

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.0.2.tar.gz (31.2 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.0.2-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gcp_ovpn_portal-0.0.2.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.8.20 Linux/5.10.0-32-cloud-amd64

File hashes

Hashes for gcp_ovpn_portal-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4b3d8d8f576127b1502b8c38a66a2901b2490093dfc59ca7b1f1ad99abdf94fe
MD5 886481dbe3a472b35a268981d4392811
BLAKE2b-256 4e7fa8f1322b1ce0787183e9c6925ed1687fcecfcaa67d8b2f8355966fe5be2d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for gcp_ovpn_portal-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a6f487b1ce2a7fbd7e22350de8f73486aecec8ee409ed7b4feb993d758117ad1
MD5 69e3288e80f71874d7e7441853ce6503
BLAKE2b-256 bf4233d790b03b244585b51af2faea366cac7d46256e172cc110b5f8bb973b11

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