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.4.6.tar.gz (142.7 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.4.6-py3-none-any.whl (155.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gcp_ovpn_portal-0.4.6.tar.gz
  • Upload date:
  • Size: 142.7 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.4.6.tar.gz
Algorithm Hash digest
SHA256 368b761a929604fa63805439069d7a612d723306bf8d0e0f937db0963465d770
MD5 cf750852c573cd8ae81b3009ddc4ee0f
BLAKE2b-256 3c282f5e63413c9aef6e623de75f877749749ebbdbc94cc46d8e7c4efe4892e2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gcp_ovpn_portal-0.4.6-py3-none-any.whl
  • Upload date:
  • Size: 155.9 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.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2b86971cc87434d57e89f3c99ee48849f63261b81da9074c76157e2f7969f4a3
MD5 56c9a67a318b6941ccc4929c45388d9a
BLAKE2b-256 6cd8a8b7e0e718f9fab2e01bdd858fa0c9e4475b7ad1454cf13ab3f53d04df4d

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