Skip to content

fix(pia): request port-forwarding tokens from PIA's v2 endpoint - #214

Merged
twistedmelonman merged 2 commits into
mainfrom
claude/fix-pia-token-endpoint
Oct 12, 2026
Merged

twistedmelonman merged 2 commits into
mainfrom
claude/fix-pia-token-endpoint

Conversation

@twistedmelonman

Copy link
Copy Markdown
Member

Summary

On 2026-10-12, after a container recreate at 11:33, pia-port-watchdog sent
its "port forwarding lost" alert. The tunnel was healthy, and the guard kept
the existing peer port, so downloads continued unforwarded. Every token
request failed for over an hour.

The cause was PIA's legacy /gtoken/generateToken endpoint. On most calls it
answered HTTP 500 with "server error: all APIs down; please report bug". The
v2 endpoint /api/client/v2/token, which PIA's own
pia-foss/manual-connections/get_token.sh uses, issued tokens normally.

Changes

  • transmission-post-start.sh asks v2 first, with --form-string
    credentials, and falls back to the legacy endpoint.
  • Each token request retries (--retry 3). curl's retry set includes HTTP 500.
  • A failed request logs the HTTP status and PIA's message, or curl's own
    error. The old code sent stderr to /dev/null and could only log "network
    or auth".
  • pia-pf-probe.sh uses v2 too, so an outage like this one does not make
    every region probe as token_failed.
  • The README gets an incident section and a manual check for both endpoints.
    It also corrects a claim that probe credentials stay out of the process
    table; they do not.
  • Both touched test files had shellcheck info findings from before this
    change. They are fixed, because the commit hook lints whole files.

Verification

  • 7 new BATS tests, with a stubbed curl, for v2 success, fallback, both
    failing, network error, --form-string credentials, and retry. All fail
    against the old code and pass against the new code.
  • Live, from inside the running container: v2 issued a token 3 of 3 times,
    and getSignature accepted a v2 token (status OK, port assigned).
  • shellcheck -S info and shfmt are clean.

Deploy

The running container does not pick this up until the setup script
redeploys transmission-post-start.sh and the container is recreated.

Not done

  • No RETURN trap for the curl stderr temp file. The file leaks only if the
    function is interrupted mid-request.
  • Credentials still reach curl as arguments inside the container. That
    exposure is the same as before this change.

Claude Code Bot added 2 commits October 12, 2026 13:28
After a container recreate on 2026-10-12, every token request failed
for over an hour and the port-forwarding-lost alert fired. The tunnel
was fine; PIA's legacy /gtoken/generateToken endpoint was answering
HTTP 500 "all APIs down; please report bug" on most calls. The v2
endpoint, /api/client/v2/token, which PIA's own manual-connections
get_token.sh uses, issued tokens normally, and getSignature accepts
them (verified live from inside the container).

transmission-post-start.sh now:
- asks v2 first, with form-field credentials, and falls back to the
  legacy endpoint;
- retries each token request, which covers curl's transient set
  including HTTP 500;
- logs the HTTP status and PIA's message, or curl's own error. The
  old code sent stderr to /dev/null and could only log "network or
  auth".

pia-pf-probe.sh switches to v2 too, so an outage like this one does not
make every region probe as token_failed.
curl's --form reads a value starting with @ or < from a file and
treats ;type= as a field modifier, so a PIA password containing those
characters would break the v2 token request. --form-string sends the
value as-is. Verified live: v2 still returns HTTP 200.

Also correct the probe's comment and README paragraph claiming the
credentials stay out of the process table. They appear in the host's
podman exec argv and in curl's argv inside the container.
@twistedmelonman
twistedmelonman force-pushed the claude/fix-pia-token-endpoint branch from 1b3c28a to 8ea6af5 Compare October 12, 2026 20:28
@twistedmelonman
twistedmelonman merged commit ad09608 into main Oct 12, 2026
3 checks passed
@twistedmelonman
twistedmelonman deleted the claude/fix-pia-token-endpoint branch October 12, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant