Merge remote-tracking branch 'origin/main' into feat/auth-callback-handler

This commit is contained in:
Kevin Yue committed 2026-09-01 15:42:25 +08:00
commit e2a64ed7d4
12 files changed
+463 -52

No files matched your search

+118
View File
@@ -0,0 +1,118 @@
name: Nix
on:
pull_request:
paths:
- "flake.nix"
- "flake.lock"
- "nix/**"
- ".github/workflows/nix.yaml"
push:
branches:
- main
paths:
- "flake.nix"
- "flake.lock"
- "nix/**"
- ".github/workflows/nix.yaml"
permissions:
contents: read
jobs:
standalone-package:
name: standalone-package (${{ matrix.platform.system }})
strategy:
fail-fast: false
matrix:
platform:
- runner: ubuntu-latest
system: x86_64-linux
- runner: ubuntu-24.04-arm
system: aarch64-linux
runs-on: ${{ matrix.platform.runner }}
steps:
- name: Checkout GlobalProtect-openconnect
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
- name: Build standalone prebuilt package
run: |
nix build .#prebuilt \
--extra-experimental-features "nix-command flakes" \
--print-build-logs
- name: Inspect prebuilt package
run: |
test -x result/bin/gpclient
test -x result/bin/gpauth
test -x result/bin/gpservice
test -x result/bin/gpgui-helper
test -x result/bin/gpgui
nixos-module:
name: nixos-module (${{ matrix.platform.system }}, ${{ matrix.nixpkgs }})
strategy:
fail-fast: false
matrix:
platform:
- runner: ubuntu-latest
system: x86_64-linux
- runner: ubuntu-24.04-arm
system: aarch64-linux
nixpkgs:
- nixos-25.11
- nixos-26.05
- nixpkgs-unstable
runs-on: ${{ matrix.platform.runner }}
steps:
- name: Checkout GlobalProtect-openconnect
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
- name: Build package through host NixOS module
env:
NIXPKGS_URL: github:NixOS/nixpkgs/${{ matrix.nixpkgs }}
NIX_SYSTEM: ${{ matrix.platform.system }}
run: |
nix build \
--impure \
--extra-experimental-features "nix-command flakes" \
--print-build-logs \
--expr '
let
gp = builtins.getFlake (toString ./.);
hostNixpkgs =
builtins.getFlake (builtins.getEnv "NIXPKGS_URL");
hostSystem = hostNixpkgs.lib.nixosSystem {
system = builtins.getEnv "NIX_SYSTEM";
modules = [
gp.nixosModules.default
{
programs.globalprotect-openconnect.enable = true;
system.stateVersion = "25.11";
}
];
};
package =
hostSystem.config.programs.globalprotect-openconnect.package;
in
assert builtins.elem package
hostSystem.config.environment.systemPackages;
assert hostSystem.config.services.ayatana-indicators.enable;
package
'
- name: Inspect module package
run: |
test -x result/bin/gpclient
test -x result/bin/gpauth
test -x result/bin/gpservice
test -x result/bin/gpgui-helper
test -x result/bin/gpgui
+30 -15
View File
@@ -24,6 +24,11 @@ jobs:
- name: Install Nix
uses: cachix/install-nix-action@v31
- name: Update Nixpkgs lock
run: |
nix flake update nixpkgs \
--extra-experimental-features "nix-command flakes"
- name: Update flake hashes
env:
RELEASE_VERSION: ${{ inputs.version }}
@@ -39,7 +44,9 @@ jobs:
uses: actions/upload-artifact@v7
with:
name: updated-flake
path: flake.nix
path: |
flake.nix
flake.lock
if-no-files-found: error
validate-nix-prebuilt:
@@ -48,22 +55,22 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-latest
nixpkgs: nixos-25.11
- runner: ubuntu-latest
nixpkgs: nixos-26.05
runner:
- ubuntu-latest
- ubuntu-24.04-arm
nixpkgs:
- locked
- nixos-25.11
- nixos-26.05
- nixpkgs-unstable
exclude:
- runner: ubuntu-24.04-arm
nixpkgs: nixos-25.11
- runner: ubuntu-24.04-arm
nixpkgs: nixos-26.05
nixpkgs: locked
name: validate-nix-prebuilt (${{ matrix.nixpkgs }}, ${{ matrix.runner }})
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout GlobalProtect-openconnect
uses: actions/checkout@v6
with:
submodules: recursive
- name: Download updated flake
uses: actions/download-artifact@v8
@@ -75,11 +82,19 @@ jobs:
uses: cachix/install-nix-action@v31
- name: Build prebuilt Nix package
env:
NIXPKGS: ${{ matrix.nixpkgs }}
run: |
nix build .#prebuilt \
--override-input nixpkgs "github:NixOS/nixpkgs/${{ matrix.nixpkgs }}" \
--extra-experimental-features "nix-command flakes" \
--print-build-logs
if [[ "$NIXPKGS" == "locked" ]]; then
nix build .#prebuilt \
--extra-experimental-features "nix-command flakes" \
--print-build-logs
else
nix build .#prebuilt \
--override-input nixpkgs "github:NixOS/nixpkgs/$NIXPKGS" \
--extra-experimental-features "nix-command flakes" \
--print-build-logs
fi
- name: Inspect prebuilt Nix package
run: |
+1
View File
@@ -1,4 +1,5 @@
.idea
.DS_Store
/target
.pnpm-store
.env
Generated
+1
View File
@@ -1924,6 +1924,7 @@ dependencies = [
"tempfile",
"tokio",
"uuid",
"uzers",
"whoami",
"xmltree",
]
+6 -3
View File
@@ -241,7 +241,10 @@ This repository includes a flake for NixOS integration.
#### Installation Steps
Add the flake input and package to your `flake.nix`:
Add the flake input and NixOS module to your `flake.nix`:
The module builds the package with your NixOS configuration's `pkgs`, so the
GlobalProtect GUI and the system use the same Nixpkgs dependency versions.
```nix
{
@@ -260,11 +263,11 @@ Add the flake input and package to your `flake.nix`:
modules = [
./configuration.nix
globalprotect-openconnect.nixosModules.default
{
services.ayatana-indicators.enable = true;
programs.globalprotect-openconnect.enable = true;
environment.systemPackages = [
globalprotect-openconnect.packages.${system}.default
nixpkgs.legacyPackages.${system}.gnomeExtensions.appindicator
];
}
+1
View File
@@ -31,6 +31,7 @@ compile-time.workspace = true
netdev.workspace = true
xmltree.workspace = true
uuid = { workspace = true, features = ["v5"] }
uzers.workspace = true
[features]
default = ["webview-auth"]
+184
View File
@@ -40,6 +40,19 @@ struct RealTimeProtection {
value: bool,
}
#[derive(Debug, Clone)]
struct UfwInfo {
version: String,
is_enabled: bool,
}
#[derive(Debug, Clone)]
struct ClamAvInfo {
version: String,
definitions_version: Option<String>,
real_time_protection: bool,
}
/// Host information for HIP reporting
struct HostInfo {
/// Common for all OSes, e.g., "Apple", "Microsoft", "Linux"
@@ -55,6 +68,8 @@ struct HostInfo {
domain: String,
network_interfaces: Vec<NetworkInterface>,
defender: Option<DefenderInfo>,
clamav: Option<ClamAvInfo>,
ufw: Option<UfwInfo>,
}
impl HostInfo {
@@ -286,6 +301,8 @@ impl<'p, 'a> HostInfoCollector<'p, 'a> {
domain: self.domain_for_profile(),
network_interfaces: interfaces,
defender: self.defender_for_profile(),
clamav: self.clamav_for_profile(),
ufw: self.ufw_for_profile(),
}
}
@@ -339,6 +356,126 @@ impl<'p, 'a> HostInfoCollector<'p, 'a> {
ClientOs::Mac | ClientOs::Windows => None,
}
}
fn clamav_for_profile(&self) -> Option<ClamAvInfo> {
match self.profile.client_os() {
ClientOs::Linux => detect_clamav(),
ClientOs::Mac | ClientOs::Windows => None,
}
}
fn ufw_for_profile(&self) -> Option<UfwInfo> {
match self.profile.client_os() {
ClientOs::Linux => detect_ufw(),
ClientOs::Mac | ClientOs::Windows => None,
}
}
}
fn detect_clamav() -> Option<ClamAvInfo> {
let version_out = Command::new("clamscan").arg("--version").output().ok()?;
if !version_out.status.success() {
debug!("clamscan not found or failed");
return None;
}
let version_str = String::from_utf8(version_out.stdout).ok()?;
let (version, definitions_version) = parse_clamav_version(&version_str)?;
let rtp_out = Command::new("systemctl")
.args(["is-active", "clamav-onaccess.service"])
.output()
.ok()?;
let real_time_protection = rtp_out.status.success();
Some(ClamAvInfo {
version,
definitions_version,
real_time_protection,
})
}
fn detect_ufw() -> Option<UfwInfo> {
let version_out = Command::new("ufw").arg("version").output().ok()?;
if !version_out.status.success() {
debug!("ufw not found or failed");
return None;
}
let version_str = String::from_utf8(version_out.stdout).ok()?;
let version = parse_ufw_version(&version_str)?;
let is_root = uzers::get_effective_uid() == 0;
let status_out = ufw_status_command(is_root).output().ok()?;
if !status_out.status.success() {
if is_root {
log::warn!("ufw status failed while running as root");
} else {
log::warn!("sudo -n ufw status failed. You may need to configure sudoers to allow execution without a password.");
}
return None;
}
let status_str = String::from_utf8(status_out.stdout).ok()?;
let is_enabled = parse_ufw_status(&status_str)?;
Some(UfwInfo { version, is_enabled })
}
fn ufw_status_command(is_root: bool) -> Command {
let mut command = if is_root {
Command::new("ufw")
} else {
let mut command = Command::new("sudo");
command.args(["-n", "ufw"]);
command
};
command.arg("status").env("LC_ALL", "C");
command
}
fn parse_clamav_version(output: &str) -> Option<(String, Option<String>)> {
let mut output_parts = output.split_whitespace();
if output_parts.next()? != "ClamAV" {
return None;
}
let mut version_parts = output_parts.next()?.split('/');
let version = version_parts.next()?;
if version.is_empty() {
return None;
}
let definitions_version = version_parts
.next()
.filter(|definitions_version| !definitions_version.is_empty())
.map(str::to_string);
Some((version.to_string(), definitions_version))
}
fn parse_ufw_version(output: &str) -> Option<String> {
let mut output_parts = output.split_whitespace();
if output_parts.next()? != "ufw" {
return None;
}
output_parts.next().map(str::to_string)
}
fn parse_ufw_status(output: &str) -> Option<bool> {
let status = output
.lines()
.find_map(|line| line.trim().strip_prefix("Status:"))?
.trim();
match status {
"active" => Some(true),
"inactive" => Some(false),
_ => None,
}
}
fn detect_microsoft_defender_blocking() -> Option<DefenderInfo> {
@@ -438,6 +575,7 @@ fn derive_windows_network_name(host_id: &str, iface: &NetworkInterface) -> Strin
mod tests {
use super::*;
use gpapi::os_profile::runtime_client_os;
use std::ffi::OsStr;
fn make_hip_args(client_os: Os) -> HipArgs {
HipArgs {
@@ -577,4 +715,50 @@ mod tests {
fn rejects_invalid_microsoft_defender_health_json() {
assert!(parse_defender_info("{}").is_none());
}
#[test]
fn parses_clamav_version() {
let version =
parse_clamav_version("ClamAV 1.4.3/27562/Sun Aug 31 10:23:42 2026").expect("ClamAV version should parse");
assert_eq!(version, ("1.4.3".to_string(), Some("27562".to_string())));
}
#[test]
fn parses_clamav_version_without_definitions_version() {
assert_eq!(parse_clamav_version("ClamAV 1.4.3"), Some(("1.4.3".to_string(), None)));
}
#[test]
fn parses_ufw_version() {
assert_eq!(parse_ufw_version("ufw 0.36.2\n"), Some("0.36.2".to_string()));
assert_eq!(parse_ufw_version("unexpected output\n"), None);
}
#[test]
fn parses_ufw_status() {
assert_eq!(parse_ufw_status("Status: active\n"), Some(true));
assert_eq!(parse_ufw_status("Status: inactive\n"), Some(false));
assert_eq!(parse_ufw_status("Status: unknown\n"), None);
}
#[test]
fn runs_ufw_status_directly_as_root() {
let command = ufw_status_command(true);
assert_eq!(command.get_program(), OsStr::new("ufw"));
assert!(command.get_args().eq(["status"].into_iter().map(OsStr::new)));
}
#[test]
fn runs_ufw_status_through_non_interactive_sudo_as_non_root() {
let command = ufw_status_command(false);
assert_eq!(command.get_program(), OsStr::new("sudo"));
assert!(
command
.get_args()
.eq(["-n", "ufw", "status"].into_iter().map(OsStr::new))
);
}
}
+19 -4
View File
@@ -218,8 +218,8 @@
</entry>
{% elif host_info.os_vendor == "Linux" -%}
<entry name="anti-malware">
{% if let Some(defender) = &host_info.defender -%}
<list>
{% if let Some(defender) = &host_info.defender %}
<entry>
<ProductInfo>
<Prod name="Microsoft Defender ATP" version="{{ defender.app_version }}" defver="{{ defender.definitions_version }}" prodType="3" engver="{{ defender.engine_version }}" osType="1" vendor="Microsoft Corporation" dateday="{{ day }}" dateyear="{{ year }}" datemon="{{ month }}">
@@ -228,10 +228,17 @@
<last-full-scan-time>n/a</last-full-scan-time>
</ProductInfo>
</entry>
</list>
{% else -%}
<list/>
{% endif -%}
{% if let Some(clamav) = &host_info.clamav %}
<entry>
<ProductInfo>
<Prod vendor="Cisco Systems, Inc." name="ClamAV" version="{{ clamav.version }}"{% if let Some(definitions_version) = &clamav.definitions_version %} defver="{{ definitions_version }}"{% endif %} engver="" datemon="{{ month }}" dateday="{{ day }}" dateyear="{{ year }}" prodType="3" osType="1"/>
<real-time-protection>{% if clamav.real_time_protection %}yes{% else %}no{% endif %}</real-time-protection>
<last-full-scan-time>n/a</last-full-scan-time>
</ProductInfo>
</entry>
{% endif -%}
</list>
</entry>
<entry name="disk-backup">
<list/>
@@ -254,6 +261,14 @@
</entry>
<entry name="firewall">
<list>
{% if let Some(ufw) = &host_info.ufw %}
<entry>
<ProductInfo>
<Prod vendor="Canonical Ltd." name="UFW" version="{{ ufw.version }}"/>
<is-enabled>{% if ufw.is_enabled %}yes{% else %}no{% endif %}</is-enabled>
</ProductInfo>
</entry>
{% endif -%}
<entry>
<ProductInfo>
<Prod name="IPTables" version="1.8.4" vendor="IPTables">
Generated
+3 -3
View File
@@ -63,11 +63,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1766410818,
"narHash": "sha256-ruVneSx6wFy5PMw1ow3BE+znl653TJ6+eeNUj4B/9y8=",
"lastModified": 1787964612,
"narHash": "sha256-0N9nghg3nwzX6b6qc77EzjR9cu/Z+UR66FlfsCqiURs=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3a7affa77a5a539afa1c7859e2c31abdb1aeadf3",
"rev": "e8be7818e19ada32105a8af937a6a473b38167ca",
"type": "github"
},
"original": {
+90 -16
View File
@@ -20,13 +20,10 @@
nixpkgs,
rust-overlay,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
mkPackageSet =
pkgs:
let
pkgs = (import nixpkgs) {
inherit system;
overlays = [ (import rust-overlay) ];
};
inherit (pkgs) lib;
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
@@ -41,39 +38,67 @@
rustc = toolchain;
};
src = pkgs.fetchzip {
unpackReleaseAsset =
{ name, archive }:
pkgs.runCommand name { nativeBuildInputs = [ pkgs.libarchive ]; } ''
mkdir -p "$out"
bsdtar --extract --file ${archive} --directory "$out" --strip-components 1
'';
sourceArchive = pkgs.fetchurl {
url = "https://github.com/yuezk/GlobalProtect-openconnect/releases/download/${releaseTag}/globalprotect-openconnect-${version}.tar.gz";
hash = "sha256-T4jze6/25YTsfuQdcuDfz3kX/ooDB1T0hnWsEBu4xMQ=";
hash = "sha256-VFWbF2BfJ9CtXkjQjkgmBGCZnYgB5ZLctqcqUKuhswg=";
};
src = unpackReleaseAsset {
name = "globalprotect-openconnect-${version}-source";
archive = sourceArchive;
};
cpu = pkgs.stdenv.hostPlatform.parsed.cpu.name;
gpguiHashes = {
x86_64 = "sha256-wPLsH/b/ZSo2pA/kU1HUGiQ98k8xSihyxGyf5o6tvyU=";
aarch64 = "sha256-WFyPhGD9fLAVYGeMSrMcZhSdfM99uVmWPrH68O+4BfE=";
x86_64 = "sha256-uVn3hJkKrjKz3mzRamxFu+0rE7OjLtMlT16d14XPcq4=";
aarch64 = "sha256-g4HKQwFAM4YCP+Afew1AhzC1wPrCS8ICw3GeA7KIeFU=";
};
gpgui = pkgs.fetchzip {
gpguiArchive = pkgs.fetchurl {
url = "https://github.com/yuezk/GlobalProtect-openconnect/releases/download/${releaseTag}/gpgui_${cpu}.bin.tar.xz";
hash = gpguiHashes.${cpu};
};
binaryHashes = {
x86_64 = "sha256-spaKxruu15ro5lir14nAfy8MPXNQhaoCXcG4PDZ9lfM=";
aarch64 = "sha256-iu/zE4B4gjk1I5PQY0m/59ZoJ/k5focT0CxYYlJi7+A=";
gpgui = unpackReleaseAsset {
name = "gpgui-${version}-${cpu}";
archive = gpguiArchive;
};
binaryPackage = pkgs.fetchzip {
binaryHashes = {
x86_64 = "sha256-jgHZC00q+2GnO18/aPGONDCz2CeiF/e1DucefSacv2w=";
aarch64 = "sha256-FDCZN0bmKWKjPiF9wkRaqMUu0PfSVHDUveJVFts25qg=";
};
binaryArchive = pkgs.fetchurl {
url = "https://github.com/yuezk/GlobalProtect-openconnect/releases/download/${releaseTag}/globalprotect-openconnect_${version}_${cpu}.bin.tar.xz";
hash = binaryHashes.${cpu};
};
binaryPackage = unpackReleaseAsset {
name = "globalprotect-openconnect-${version}-${cpu}-binary";
archive = binaryArchive;
};
linuxRuntimeDependencies = with pkgs; [
glib-networking
libayatana-appindicator
xdg-utils
];
rewriteVpncScriptToolPaths = lib.optionalString pkgs.stdenv.isLinux ''
substituteInPlace $out/libexec/gpclient/vpnc-script \
--replace-fail /usr/bin/resolvectl ${pkgs.systemd}/bin/resolvectl \
--replace-fail /usr/bin/busctl ${pkgs.systemd}/bin/busctl
'';
linuxBuildInputs =
with pkgs;
[
@@ -217,6 +242,7 @@
${installNixosPolkitRule}
''
+ ''
${rewriteVpncScriptToolPaths}
${rewriteSourceInstallPaths}
'';
};
@@ -249,6 +275,8 @@
install -Dm755 ${gpgui}/gpgui $out/bin/gpgui
${rewriteVpncScriptToolPaths}
runHook postInstall
'';
};
@@ -443,6 +471,49 @@
'';
};
in
{
inherit fromSource prebuilt;
};
nixosModule =
{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.globalprotect-openconnect;
in
{
options.programs.globalprotect-openconnect = {
enable = lib.mkEnableOption "GlobalProtect-openconnect";
package = lib.mkOption {
type = lib.types.package;
# Use the NixOS module's package set so WebKit and graphics
# dependencies match the rest of the system.
default = (mkPackageSet pkgs).prebuilt;
description = "GlobalProtect-openconnect package to install.";
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
services.ayatana-indicators.enable = lib.mkDefault true;
};
};
in
(flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = (import nixpkgs) {
inherit system;
overlays = [ (import rust-overlay) ];
};
inherit (pkgs) lib;
inherit (mkPackageSet pkgs) fromSource prebuilt;
in
{
# For `nix build`
packages = {
@@ -469,5 +540,8 @@
];
};
}
);
))
// {
nixosModules.default = nixosModule;
};
}
+8 -8
View File
@@ -5,8 +5,8 @@ set -euo pipefail
release_version="${1:-}"
release_tag="${2:-}"
if git diff --quiet -- flake.nix; then
echo "flake.nix hashes are already up to date"
if git diff --quiet -- flake.nix flake.lock; then
echo "flake hashes and lock are already up to date"
exit 0
fi
@@ -21,12 +21,12 @@ fi
branch_suffix="v${version}"
title="chore: update flake hashes for v${version}"
body="Updates the Nix flake fetchzip hashes for v${version} release assets."
body="Updates the Nix flake fetchurl hashes for v${version} release assets and refreshes the Nixpkgs lock."
if [[ "$release_tag" != "v$version" ]]; then
branch_suffix="${branch_suffix}-${release_tag}"
title="chore: update flake hashes for v${version} from ${release_tag}"
body="Updates the Nix flake fetchzip hashes for v${version} using ${release_tag} release assets."
body="Updates the Nix flake fetchurl hashes for v${version} using ${release_tag} release assets and refreshes the Nixpkgs lock."
fi
git config user.name "github-actions[bot]"
@@ -37,7 +37,7 @@ if [[ "$release_tag" == "snapshot" ]]; then
source_branch_slug="$(printf '%s' "$source_branch" | sed -E 's#[/[:space:]]+#-#g; s#[^A-Za-z0-9._-]##g; s#^-+##; s#-+$##')"
branch="chore/flake-${source_branch_slug}"
git switch -C "$branch"
git add flake.nix
git add flake.nix flake.lock
git commit -m "$title"
git push --force origin "$branch"
echo "Updated snapshot flake hashes on branch $branch from $source_branch; skipping PR creation"
@@ -47,12 +47,12 @@ fi
branch="chore/update-flake-hashes-${branch_suffix}"
git switch -C "$branch"
git add flake.nix
git add flake.nix flake.lock
git commit -m "$title"
git push --force origin "$branch"
if gh pr view "$branch" --json number > /tmp/flake-pr.json 2> /dev/null; then
pr_number="$(jq -r '.number' /tmp/flake-pr.json)"
pr_number="$(gh pr list --head "$branch" --state open --json number --jq '.[0].number')"
if [[ -n "$pr_number" ]]; then
gh pr edit "$pr_number" --title "$title" --body "$body"
else
gh pr create --title "$title" --body "$body" --base main --head "$branch"
+2 -3
View File
@@ -11,7 +11,7 @@ FLAKE_FILE="$PROJECT_DIR/flake.nix"
usage() {
echo "Usage: $0 [version] [release-tag]"
echo
echo "Updates flake.nix fetchzip hashes from the published GitHub release assets."
echo "Updates flake.nix fetchurl hashes from the published GitHub release assets."
echo "When version is omitted, the workspace package version from Cargo.toml is used."
echo "When release-tag is omitted, v<version> is used. Use snapshot to test snapshot assets."
}
@@ -22,7 +22,7 @@ if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
fi
if ! command -v nix > /dev/null; then
echo "nix is required to calculate unpacked fetchzip hashes" >&2
echo "nix is required to calculate release asset hashes" >&2
exit 1
fi
@@ -61,7 +61,6 @@ prefetch_hash() {
store prefetch-file \
--hash-type sha256 \
--json \
--unpack \
"$url" \
| jq -r '.hash'; then
return 0