Home Blog

Connecting to the UA VPN from Arch with NetworkManager

The University of Alabama's VPN is a Cisco AnyConnect server. OpenConnect, the open-source AnyConnect client, connects to it with:

sudo openconnect --authgroup=campus uavpn.ua.edu/campus

The username is [email protected]. The login form then asks for two passwords: your UA password, and the Okta Verify step, which is either the current 6-digit code or the word push. The server checks both together.

I wanted two things beyond that: a VPN I could toggle through NetworkManager like my other connections, without a root terminal left open, and a Waybar indicator showing when it is up. Both openconnect and networkmanager-openconnect were already installed on my ThinkPad.

Putting it in NetworkManager

The NetworkManager profile is one command:

nmcli con add type vpn con-name UA-VPN ifname -- vpn-type openconnect \
  vpn.data "protocol=anyconnect,gateway=uavpn.ua.edu/campus,authtype=password,enable_csd_trojan=no"

Activating it was harder. nmcli con up UA-VPN --ask fails with No valid secrets, and the NetworkManager log says No agents were available for this request. The openconnect plugin does not take a username and password. It runs an authentication dialog that walks through the server's login forms and returns a session cookie. That dialog is graphical, and the plugin does not support nmcli's text-mode prompts. Without something like nm-applet running to show the dialog, nothing can answer the request. I did not want a tray applet just for this.

OpenConnect can do the authentication step by itself. openconnect --authenticate runs the login interactively in the terminal, without root, and prints the result as shell variables:

COOKIE='...'
CONNECT_URL='https://...'
FINGERPRINT='pin-sha256:...'

Those are the three secrets the NetworkManager plugin wants: cookie, gateway and gwcert. Passing them with nmcli con up ... passwd-file did not work; nmcli's own agent declined the request, with the same "No agents" error. What did work was storing them in the profile just long enough to activate it, then wiping them.

Wiping took one more surprise. Setting vpn.secrets '' or removing the keys with -vpn.secrets left them in place. Changing the secrets' flags to 2 ("not saved") is what makes NetworkManager drop them from the stored profile.

The fish function

function uavpn --description 'Toggle UA VPN (uavpn.ua.edu/campus) via NetworkManager'
    set -l con UA-VPN

    if test "$argv[1]" = down; or begin; test -z "$argv[1]"; and nmcli -t -f NAME con show --active | string match -q $con; end
        nmcli con down $con
        set -l rc $status
        pkill -SIGRTMIN+7 waybar # refresh custom/wireguard
        return $rc
    end

    # Interactive login (username, password, Okta code or "push"); prints shell-style vars on stdout
    set -l out (openconnect --authenticate --authgroup=campus uavpn.ua.edu/campus)
    or return 1

    set -l cookie (string match -r "^COOKIE='(.*)'\$" -- $out)[2]
    set -l url (string match -r "^CONNECT_URL='(.*)'\$" -- $out)[2]
    set -l fp (string match -r "^FINGERPRINT='(.*)'\$" -- $out)[2]
    test -n "$url"; or set url (string match -r "^HOST='(.*)'\$" -- $out)[2]

    if test -z "$cookie"
        echo "uavpn: authentication did not return a cookie" >&2
        return 1
    end

    # nmcli's passwd-file agent declines openconnect secrets ("No agents were
    # available"), so store them in the profile just long enough to activate.
    # Flipping the flags back to 2 (not saved) is what wipes them; setting
    # vpn.secrets to '' or removing keys leaves them in place.
    nmcli con mod $con +vpn.data 'cookie-flags=0,gateway-flags=0,gwcert-flags=0' \
        vpn.secrets "cookie=$cookie,gateway=$url,gwcert=$fp"
    or return 1
    nmcli con up $con
    set -l rc $status
    nmcli con mod $con +vpn.data 'cookie-flags=2,gateway-flags=2,gwcert-flags=2'
    pkill -SIGRTMIN+7 waybar # refresh custom/wireguard
    return $rc
end

uavpn prompts for the username, password and Okta code, then connects. Running it again disconnects. The tunnel belongs to NetworkManager, so no terminal has to stay open, and nmcli con down UA-VPN works too. The session cookie sits in the profile, which only root can read, for the second or two that activation takes.

A plain nmcli con up UA-VPN still fails, since nothing is there to log in. That is the trade-off for not running an applet.

Waybar

I already had a Waybar pill for WireGuard connections, fed by a script that parses nmcli connection show. I extended it to plugin VPNs (type vpn). One detail: a WireGuard profile has a static ipv4.addresses, but the openconnect profile has none, so for vpn connections the script reads the address the server assigned, IP4.ADDRESS[1]. The rofi menu offers UA-VPN only when it is up, for disconnecting, since a bare nmcli up from the menu would just fail.

uavpn sends Waybar signal 7 after connecting or disconnecting, so the pill updates immediately instead of on the next 60-second poll.

The NetworkManager integration and the fish function were worked out in a Claude Code session, with me testing each step against the real server.

Versions

Laptop ThinkPad, Arch Linux
Kernel 7.2.11-arch1
NetworkManager 1.58.1
networkmanager-openconnect 1.2.10
OpenConnect 9.21
Server Cisco AnyConnect, uavpn.ua.edu/campus