Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: T3 Connect: The environment credential is invalid. #5332

Closedpaulomanrique(GitHub profile, opens in a new tab) opened this issue 6 comments

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/desktop

Steps to reproduce

Trying to connect to another remote environment

Expected behavior

T3 would connect and have access to such environment

Actual behavior

I have 3 machines in my network, all of them connect to T3 Connect and all of them can connect to each other, except my Macbook can't connect to the Windows instance. The error is: The environment credential is invalid.

Impact

Blocks work completely

Version or commit

0.0.32

Environment

27.0 Beta (26A5388g), Windows 11

Logs or stack traces

Trace ID: 397a5a9c7c80045bcc7f3cd117837401

Screenshots, recordings, or supporting files

image.png image.png

Workaround

No response

  1. paulomanrique(GitHub profile, opens in a new tab) added labelsneeds-triage

  2. I am also facing the same error. For me I am not using t3 connect instead I am getting this error when using t3 serve. The generated code works correctly for the first device. Any attempt to add the same remote environment on any other device results in this error.

  3. kylescudder(GitHub profile, opens in a new tab)commented

    Update: I resolved my reproduction. This was not caused by a corrupt persisted environment credential.

    After adding credential-safe diagnostics around DPoP verification, the server reported the actual rejection reason:

    DPoP proof verification failed
    reason: DPoP proof is outside the allowed time window.
    requestProtocol: https:
    requestHost: prod-aa75a8b4828aa058.t3coderelay.com
    requestPath: /oauth/token
    forwardedProtocol: https
    cloudflareVisitor: {"scheme":"https"}

    The VPS clock was not synchronized:

    System clock synchronized: no
    NTP service: active
    Packet count: 0

    NTP requests were timing out because UDP response traffic was blocked by the provider firewall. Once I allowed incoming UDP traffic from source port 123 and restarted systemd-timesyncd, it synchronized and corrected approximately 11 seconds of clock drift:

    System clock synchronized: yes
    Offset: +10.959798s
    Packet count: 1

    The existing T3 Connect environment then connected successfully from the mobile app without relinking or regenerating its credential.

    There was a separate network issue where Cloudflare Tunnel could not establish QUIC because UDP was blocked. Running the tunnel over HTTP/2 with TUNNEL_TRANSPORT_PROTOCOL=http2 handled that; it was not the cause of the invalid_credential response.

    So, for my reproduction:

    • The environment credential was valid.
    • The public HTTPS request URL was reconstructed correctly.
    • The 401 invalid_credential response was caused by clock skew during DPoP verification.
    • Restoring working NTP synchronization fixed the connection.

    Other reports on this issue may still have different causes, but regenerating the environment credential was not required in my case.

  4. I just ran into the same issue. In my case, the Windows environment host’s clock was about 11 seconds behind.

    After diagnosing it with T3 (ha!), clicking Sync now under Windows Settings → Time & language → Date & time fixed the connection immediately. I did not need to relink the environment or regenerate its credentials.

    This matches the clock-skew diagnosis above. I’d suggest that when authentication fails specifically because the DPoP proof falls outside the permitted time window, the app show a more actionable message:

    The environment host’s clock appears out of sync. Sync its date and time, then retry.

    Other invalid-credential failures can remain generic.

  5. paulomanrique(GitHub profile, opens in a new tab)commented

    One thing I noticed, is that if you try add the 4th device in the tunnel, you also get this error message instead of something reporting you ran out of devices, subscribe and whatever.

  6. agm-114(GitHub profile, opens in a new tab)commented

    I get the same error on Android mobile trying to connect to my desktop. Over time more and more "T3 Connect connect" connections are made.

    Image Image
  7. juliusmarminge closed this

  8. evolveperformance(GitHub profile, opens in a new tab)commented

    Root cause for the clock-skew reproductions in this thread (from the closed #17186, preserved here as requested):

    verifyDpopProof in packages/shared/src/dpop.ts accepts a proof whose iat is up to 300 seconds in the past but only 5 seconds in the future. The environment server and the relay both use it. So when the verifying machine's clock runs more than 5 seconds behind the client's, every proof is rejected with time_window, and the client shows "The environment credential is invalid."

    Reproduction:

    1. Set the environment host's clock about 10 seconds behind real time (for example, turn off automatic time on Windows and move it back).
    2. Connect to that environment from another device with a synced clock, over T3 Connect or t3 serve.
    3. Every request fails with "The environment credential is invalid." The server logs DPoP proof is outside the allowed time window.
    4. Sync the host clock (Windows: Settings > Time & language > Date & time > Sync now). The connection works again right away, with no relink.

    Matching reports: the Windows host about 11 seconds behind and the VPS about 11 seconds off in this issue, #9676 (Android with automatic time off), and the VirtualBox guest drifting 13 to 43 seconds behind, reported on #17186.

    A smaller fix that only makes the tolerance symmetric (300 seconds either way) and extends the relay replay marker to match is in #19640.

Sign in to join this conversation.