OpenVPN Access ServerをRaspberry Pi 4Bに構築してみました。
今回はPortainerのGUI画面からOpenVPN Access ServerのDockerコンテナを生成しました。2コネクションまでは無償利用可能なようです。

環境

  • Raspbeyy Pi 4B
    • Ubuntu 24.04 LTS (Arm64)
      • Docker 28.5.2
        • Portainer-CE 2.33.3
        • OpenVPN Access Server 3.0.1

構築

Docker

  • 構築済のものを使用

Portainer

  • 構築済のものを使用

OpenVPN関連パラメタの整理

  • 指定するパラメタ

    項目 値(例)
    外部公開IPアドレス xxx.xxx.xxx.xxx
    外部公開ポート番号 60000
    外部からアクセスしたいLANサブネット 192.168.1.0/24

PortainerでDockerコンテナを作成

  1. Portainerにログイン
    https://192.168.11.24:9443

  2. ContainersメニューでAdd Container

  3. 以下のパラメタを指定してDeploy the container

    分類 項目
      Name openvpn-as
    Image Configuration Image openvpn/openvpn-as:latest
    Network ports configuration Port mapping 943, 943, tcp
        <公開ポート番号>, <公開ポート番号>, tcp
    Advanced container settings Restart Policy Unless stopped
      Capabilities NET_ADMIN
  4. Cotainers > openvpn-asを選択

  5. Container details > Container status > Logs を選択

  6. Container logsでopenvpnアカウントのパスワードを確認する。

    • 検索条件

      検索条件 指定値
      Search pass
      Lines 1000
    • 検索結果

      Auto-generated pass = "i2vTb42zklZu". Setting in db...

OpenVPN Access Serverの設定

  1. OpenVPN Access Serverにユーザ名openvpnでログイン
    https://192.168.11.2:943/admin

    ログから検索したパスワードを指定する。

  2. アカウントopenvpnのパスワードを更新
    Users > openvpn > User Settings > Authentication > New password

  3. VPNサーバのパラメタ設定
    VPN Server > Network Settings で以下を設定

    項目
    Server Address / Hostname (or IP address) <外部公開IPアドレス>
    OpenVPN daemons / Protocol TCP
    TCP Port <外部公開ポート番号>
  4. ユーザを作成
    UsersメニューでAdd New User
    User01を追加

  5. ユーザのパスワードを設定
    Users / User01 / User Settings / Authentication / New password

  6. ユーザのプロファイルを作成
    Certificate Management > VPN Client Certificates > New Connection Profile > Username > User01
    Download

  7. ファイル名変更
    profile-userlocked.ovpnprofile-User01.opvn

  8. LANへの接続を許可
    Access Controls > Global Access Rules > NAT > Subnet
    + Add new subnet
    192.168.11.0/24
    Save

  9. Restart

Status画面のwarningについて

  • CPU AES acceleration not available
    OpenVPN Access Server was not able to detect AES acceleration instruction on the CPU (AES-NI on x86_64/ARMv8 AES extensions). This often caused by virtualization not passing through the CPU features.

    Raspberry Pi 4Bには、専用のAESハードウェアアクセラレーション機能は搭載されていません。しかし、CPUの命令セットの一部である「ARMv8」にはAESをサポートする拡張命令(NEON)が含まれており、これを利用することでソフトウェア的に高速なAES暗号化が可能です。
    なのでそのままにする。
    カスタマイズしたい場合は以下を操作すればよいかもしれない。

    VPN Server > Security / Encryption > Data-channel ciphers

  • OpenVPN data-channel offloading was requested but failed to activate
    OpenVPN data-channel offloading was requested but failed to activate. This typically happens if there is a configuration option that is incompatible with DCO or if the DCO kernel module could not be loaded.

    以下で抑止できる。
    VPN Server > Data Channel Offload > Use DCO if possible
    Off

クライアントの設定

  1. OpenVPN Connectアプリをインストール
  2. OpenVPN Connectアプリでprofile-User01.opvn をインポート

ルータの設定

  • ポート変換
    インターネットからの<外部公開ポート番号>宛ての通信をRaspberry Pi 4BのIPアドレスの<外部公開ポート番号>宛てに変換

Ubuntuのファイアウォール設定

  • 受信設定
    <外部公開ポート番号>/tcp、943/tcpへの受信許可を追加

docker composeでコンテナを生成するとしたら

  • おそらくこんな感じ
    docker-compose.yaml
    services:
    openvpn-as:
    image: openvpn/openvpn-as
    container_name: openvpn-as
    devices:
    - /dev/net/tun:/dev/net/tun
    cap_add:
    - NET_ADMIN
    - MKNOD
    ports:
    - 943:943
    - <公開ポート番号>:<公開ポート番号>
    volumes:
    - <path to data>:/openvpn
    restart: unless-stopped