feat(gpclient): add --cookie-only to print gateway cookie without starting tunnel - #647
Open
maksym-shaiev wants to merge 1 commit into
Open
feat(gpclient): add --cookie-only to print gateway cookie without starting tunnel#647maksym-shaiev wants to merge 1 commit into
maksym-shaiev wants to merge 1 commit into
Conversation
…rting tunnel
When --cookie-only is set, connect_gateway() authenticates fully
(including CAS/SAML flow, --cookie-cache reuse) then prints the
gateway cookie to stdout and exits before any VPN tunnel setup:
COOKIE='authcookie=…&portal=…&user=…&computer=…'
HOST='gateway.example.com'
Output format matches openconnect --authenticate for easy shell
consumption and eval safety.
Properties of this mode:
- No tun device is opened, no root is required
- No logout is issued — the gateway cookie stays valid for
subsequent use (e.g. feeding to nm-openconnect or openconnect
--cookie-on-stdin directly)
- Works across all three call sites in connect_gateway(): cached
portal cookie, portal fallback, and gateway prelogin paths
Intended use: external tunnel managers (NetworkManager, systemd
scripts, CI pipelines) that need a verified gateway authcookie but
want to manage the tunnel interface themselves.
Example — feed the cookie to openconnect directly:
eval "$(gpclient connect portal.example.com \
--browser --cookie-cache --cookie-only)"
printf '%s\n' "$COOKIE" | \
sudo openconnect --protocol=gp --cookie-on-stdin portal.example.com
Relates to the existing --cookie-on-stdin flag: that flag consumes
a portal SamlAuthResult (pre-gateway-login); this flag produces a
gateway authcookie (post-gateway-login). They operate at different
levels of the authentication pipeline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(gpclient): add
--cookie-onlyto print gateway cookie without starting tunnelSummary
Adds
--cookie-onlytogpclient connect. When set, the command authenticatesfully (including CAS/SAML,
--cookie-cachereuse) then prints the gatewayauthcookie to stdout and exits — without opening a tun device, without issuing
logout, and without requiring root.
Motivation
There is currently no way to obtain a verified gateway authcookie from
gpclientwithout also starting the VPN tunnel (which requires root). External integrations
that need the cookie but want to manage the tunnel themselves — NetworkManager
plugins, systemd scripts, CI pipelines — have no clean path.
The existing
gpauth | gpclient --cookie-on-stdinpattern produces a portalSamlAuthResult(pre-gateway-login). What external integrations need is agateway authcookie (post-gateway-login, ready for
openconnect --cookie-on-stdin).--cookie-onlyfills that gap.Output format
Matches
openconnect --authenticatefor easy shell consumption andevalsafety:Relation to existing flags
--cookie-on-stdinSamlAuthResult--cookie-onlyTogether they cover both directions of external integration.
Properties
logout.espissued → cookie stays valid for the callerconnect_gateway(): cached portal cookie,portal fallback, and gateway prelogin paths
Usage examples
Feed directly to openconnect:
Unprivileged auth + privileged tunnel (split across users/processes):
Combined with
--cookie-cachefor session reuse (browser only opens whenthe portal session has expired):
gpclient connect portal.example.com \ --browser chrome \ --cookie-cache \ --cookie-onlyChanges
apps/gpclient/src/connect/args.rs— addcookie_only: boolfield with--cookie-onlyclap argument; add 2 testsapps/gpclient/src/connect/gateway.rs— early-return block at top ofconnect_gateway()covering all call sitesTesting
17 tests pass including the two new ones:
cookie_only_flag_parses— verifies--cookie-onlyis accepted by clapcookie_only_is_disabled_by_default— verifies the flag defaults to false