Skip to content

🐛 fix(terminal): find default tmux socket under arbitrary container UID - #14791

Merged
hivecommons-hive[bot] merged 1 commit into
v5from
fix/ttyd-default-socket-arbitrary-uid
Oct 28, 2026
Merged

hivecommons-hive[bot] merged 1 commit into
v5from
fix/ttyd-default-socket-arbitrary-uid

Conversation

@clubanderson

Copy link
Copy Markdown
Member

Fixes #14789

Problem

On an OpenShift spoke under the restricted SCC (container UID 1000840000), the dashboard terminal showed waiting for agent 'X' to start (tmux session not created yet); polling up to 900s... for every agent, while tmux ls showed every hive-<agent> session alive.

With no per-agent UID map all sessions live on the default tmux server, /tmp/tmux-$(id -u)/default. ttyd-tmux.sh's fallback for that layout computed the socket as /tmp/tmux-$(id -u dev || 1001)/default — dev's passwd uid, not the uid the process runs as. On Compose/Podman they coincide; under an arbitrary OpenShift uid they never do.

Fix (src/deploy/ttyd-tmux.sh)

  • New default_socket_candidates(): deduplicated, likelihood-ordered list — ${TMUX_TMPDIR:-/tmp}/tmux-$(id -u)/default, …/tmux-$(id -u dev || 1001)/default, then any …/tmux-*/default present (unmatched glob discarded by -S, so set -euo pipefail stays happy).
  • find_tmux_socket() walks the candidates and takes the first that is a socket and has the requested session (socket_has_session, which keeps the su-exec path for sockets owned by another uid).
  • list_available_sessions() lists sessions from every default server found, and no longer reports the socket name default as if it were a session.
  • Socket root honours TMUX_TMPDIR (tmux's own convention), which is also what lets the test point the lookup at a scratch dir.
  • Header comment updated: ttyd may run as an arbitrary uid on OpenShift.

entrypoint.sh was checked: its 1001 / id -u dev references are ownership and privilege-drop checks, not tmux socket paths, so nothing to change there.

Tests

New src/deploy/test_ttyd_default_socket_uid.sh (wired into v2-ci.yml, verified by test_deploy_suites_wired.sh). id is stubbed on PATH; real tmux servers are started with tmux -S at the exact path each layout would use; the helper is run for real and attachment is asserted positively via the wheel rebind it leaves on the server:

  • arbitrary uid, no passwd entry for dev → resolves
  • arbitrary uid, id -u dev = 1001 but server on current uid → resolves (the reporting spoke's exact state)
  • dev uid 1001 (Compose/Podman) → still resolves
  • running as another uid, server on dev's socket → resolves
  • server under neither uid → found via glob
  • session nowhere → waits, gives up, hint lists sessions from all default servers, no literal default
  • empty socket root → clean available sessions: none, no set -u trip
test_ttyd_default_socket_uid.sh   23 passed, 0 failed
test_ttyd_url_arg.sh              27 passed, 0 failed
test_terminal_scrollback_status.sh 37 passed, 0 failed
test_deploy_suites_wired.sh       0 orphaned
shellcheck -x                     clean

Workaround currently on the spoke (can be removed after upgrade)

ln -s /tmp/tmux-$(id -u) /tmp/tmux-1001

With no per-agent UID map every hive-<agent> session lives on the default
tmux server of the UID the container runs as. ttyd-tmux.sh's fallback
assumed that was dev's passwd uid (/tmp/tmux-1001/default). Under
OpenShift's restricted SCC the container runs as an arbitrary uid with no
passwd entry, so the helper polled the wrong socket for 900s while every
session was alive.

Walk a deduplicated candidate list instead: the current uid's default
socket, dev's, then any ${TMUX_TMPDIR:-/tmp}/tmux-*/default, and use the
first that is a socket and holds the requested session. The
available-sessions hint lists sessions from every default server found
and no longer reports the socket name 'default' as a session.

Adds test_ttyd_default_socket_uid.sh (id stubbed, real tmux servers at
each layout's path) and wires it into v2-ci.

Fixes #14789

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 28, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign nicholasjackson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 28, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

@clubanderson is auto-promoted for contributor-lane merging on this PR: the last 5 merged PRs by this author in this hive's repositories have no revert or sentinel-alert evidence. CI, reviewer verdict, diff fences, soak, holds and branch protection still apply.

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#14795 🐛 fix: find default tmux sockets under arbitrary container UIDs CONFLICT src/deploy/ttyd-tmux.sh

@hivecommons-hive hivecommons-hive Bot added author/human A person pushed this PR themselves dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 28, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read src/deploy/ttyd-tmux.sh at f566ea9 against the v5 tree. This looks correct to me.

  • default_socket_candidates() (ttyd-tmux.sh:80-98) emits current-uid → id -u dev → glob, deduplicated via the seen list, and the unmatched-glob literal is discarded by [ -S ] so set -u/pipefail are not tripped. Both callers (list_available_sessions, ttyd-tmux.sh:49-72; find_tmux_socket, ttyd-tmux.sh:112-137) consume it through read -r, so a socket path with no session falls through to the next candidate rather than attaching to the wrong server.
  • socket_has_session (ttyd-tmux.sh:98-110) is unchanged and still routes through su-exec when the socket owner differs from the current uid, so the per-agent-UID path keeps working.
  • No other place hard-codes /tmp/tmux-1001: the only remaining id -u dev in src/deploy/entrypoint.sh:380 is the token-ownership check, not a socket path, and I found no Go code in src/pkg / src/cmd computing a default tmux socket path — the fix is complete in the script.
  • The v2-ci.yml change only adds a test step next to the existing test_ttyd_url_arg.sh one; no permissions or triggers change.

One note, not a defect: test_ttyd_default_socket_uid.sh skips the whole suite when su-exec is on PATH (it printed SKIP: su-exec is on PATH / 0 passed, 0 failed on this host). That is fine on the ubuntu runners, but it means the suite is a no-op inside the hive image itself if anyone runs it there.

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me.

Read src/deploy/ttyd-tmux.sh at v5 @ 4fc7d11 against the diff:

  • The tree had five sites that assumed /tmp and dev's passwd UID (ttyd-tmux.sh:39, :44-45, :55, :76, :88-89); the diff replaces all of them, so no stale /tmp/tmux-1001/default lookup remains after this lands.
  • default_socket_candidates orders id -u first, then id -u dev || 1001, then the glob — the Compose/Podman case (both equal) dedupes to one probe, and the OpenShift arbitrary-UID case finds the right socket on the first probe. The -S test discards the unmatched literal glob, so not setting nullglob is fine.
  • find_tmux_socket still requires socket_has_session on each candidate (ttyd-tmux.sh:58-71), so the boot-time "bare default socket, session not yet created" guard this fallback originally protected is preserved for every candidate, not just the first.
  • The .github/workflows/v2-ci.yml hunk only adds a test step after test_ttyd_url_arg.sh; no permission or trigger changes. The new test self-skips when su-exec is on PATH, which matches the helper's real behaviour (ttyd-tmux.sh:66, :251) rather than hiding it.

Nothing blocking from me.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor
f566ea9

ℹ️ Sentinel notice — informational; author is trusted (owner), merge is not blocked

Hive flagged this PR (author @clubanderson, head f566ea9e8869) because it matches behaviors that can override security controls, escalate privileges or damage the codebase. This is a heuristic, not an accusation — a maintainer should confirm the change is intended before it merges.

  • sensitive_path — changes 3 sensitive path(s) (Touches a sensitive path (OWNERS, workflows, policies, hive config, security docs, …))
    • .github/workflows/v2-ci.yml
    • src/deploy/test_ttyd_default_socket_uid.sh
    • src/deploy/ttyd-tmux.sh

Hive did not add the sentinel-alert label because this author is trusted. The finding remains recorded for audit and the dashboard Security tab; set sentinel.trusted_authors_block: true to require the blocking label for trusted authors too.

@github-actions github-actions Bot added the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Oct 28, 2026
@hivecommons-hive hivecommons-hive Bot added stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 28, 2026
@hivecommons-hive
hivecommons-hive Bot merged commit 49afb3d into v5 Oct 28, 2026
85 of 91 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the fix/ttyd-default-socket-arbitrary-uid branch October 28, 2026 01:52
@hivecommons-hive

Copy link
Copy Markdown
Contributor
Evidence bundle `#14791f566ea9` sha256:9d282710e7bf5512013b493b45aa2797195cf022ee3d55d69d0b66497d39bc3f — download from the dashboard or `hivectl review evidence #14791`.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

merged by Hive trusted-author auto-merge: author @clubanderson holds role owner and GitHub permission admin on repo; CI green at f566ea9.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/human A person pushed this PR themselves conflicts-with-open-pr Open PR has a merge conflict with another open PR dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

terminal attach does not find the default tmux socket under an arbitrary container UID

1 participant