From 9e4f45997ebee452c58d7d3066dcfc175d65ef82 Mon Sep 17 00:00:00 2001 From: Maksym Shaiev Date: Mon, 7 Sep 2026 17:53:32 +0300 Subject: [PATCH 1/2] feat(gpclient): add --cookie-only to print gateway cookie without starting tunnel (#647) Co-authored-by: Maksym Shaiev --- apps/gpclient/src/connect/args.rs | 28 ++++++++++++++++++++++++++++ apps/gpclient/src/connect/gateway.rs | 10 ++++++++++ 2 files changed, 38 insertions(+) diff --git a/apps/gpclient/src/connect/args.rs b/apps/gpclient/src/connect/args.rs index 2ca0d60..3f9bc48 100644 --- a/apps/gpclient/src/connect/args.rs +++ b/apps/gpclient/src/connect/args.rs @@ -146,6 +146,14 @@ pub(crate) struct ConnectArgs { num_args=0..=1 )] pub(super) browser: Option, + + #[arg( + long, + help = "Authenticate and print the gateway cookie to stdout, then exit without starting the \ + VPN tunnel. Outputs two lines: COOKIE='' and HOST=''. Combine with \ + --cookie-cache to avoid re-authenticating when the portal session is still valid." + )] + pub(super) cookie_only: bool, } pub(super) fn build_os_profile(args: &ConnectArgs) -> OsProfile { @@ -398,4 +406,24 @@ mod tests { }; assert_eq!(err.kind(), ErrorKind::ArgumentConflict); } + + #[test] + fn cookie_only_flag_parses() { + use clap::Parser; + + let cli = ConnectArgsTestCli::try_parse_from(["test", "portal.example.com", "--cookie-only"]) + .expect("--cookie-only should parse"); + + assert!(cli.args.cookie_only); + } + + #[test] + fn cookie_only_is_disabled_by_default() { + use clap::Parser; + + let cli = ConnectArgsTestCli::try_parse_from(["test", "portal.example.com"]) + .expect("connect args should parse"); + + assert!(!cli.args.cookie_only); + } } diff --git a/apps/gpclient/src/connect/gateway.rs b/apps/gpclient/src/connect/gateway.rs index 8963be1..fc4c327 100644 --- a/apps/gpclient/src/connect/gateway.rs +++ b/apps/gpclient/src/connect/gateway.rs @@ -341,6 +341,16 @@ impl ConnectHandler<'_> { allow_extend_session: bool, extension_auth: SessionExtensionAuth, ) -> Result<(), GatewayConnectError> { + // --cookie-only: print the gateway cookie and exit without opening a tunnel. + // No tun device is allocated, no root is required, and no logout is issued + // against the gateway — the cookie remains valid for subsequent use. + // Output format matches openconnect --authenticate for easy shell consumption. + if self.args.cookie_only { + println!("COOKIE='{}'", cookie); + println!("HOST='{}'", gateway); + return Ok(()); + } + let mtu = self.args.mtu.unwrap_or(0); let (hip, csd_wrapper) = self.determine_hip_script(); let hip_user = self.determine_hip_user(); From 0425ee6ddb8e0cadd8491532dbef466864748dc8 Mon Sep 17 00:00:00 2001 From: koval-jan <2558940+koval-jan@users.noreply.github.com> Date: Fri, 18 Sep 2026 02:29:34 +0200 Subject: [PATCH 2/2] fix(cli): exempt hip subcommand from singleton lock check (#658) --- apps/gpclient/src/cli.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/gpclient/src/cli.rs b/apps/gpclient/src/cli.rs index 1a31619..5467439 100644 --- a/apps/gpclient/src/cli.rs +++ b/apps/gpclient/src/cli.rs @@ -135,7 +135,10 @@ impl Cli { async fn run(&self) -> anyhow::Result<()> { // check if an instance is running - if !matches!(self.command, CliCommand::Disconnect(_)) && self.is_running().await { + if !matches!( + self.command, + CliCommand::Disconnect(_) | CliCommand::Hip(_) + ) && self.is_running().await { bail!("Another instance of the client is already running"); }