Skip to content

Commit

Permalink
Try harder to attach to an existing tmux session
Browse files Browse the repository at this point in the history
If in the course of an ssh/tmux session the tmux package is upgraded
and the ssh connection broken, the next ssh attempt will encounter an
error because of the tmux protocol version mismatch.

The old tmux can be used to reattach by searching for the tmux process
under /proc and using its reference to the old tmux executable. This
change attempts to do that automatically if a first "tmux attach"
attempt fails, but we can see that a previous session still exists.
  • Loading branch information
rmol committed Mar 11, 2019
1 parent 043f63a commit 8502ca9
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ip_info:
### Used by the install_local_deb_pkgs role ###
local_deb_packages:
- "securedrop-keyring-0.1.2+{{ securedrop_app_code_version }}-amd64.deb"
- "securedrop-config-0.1.2+{{ securedrop_app_code_version }}-amd64.deb"
- "securedrop-config-0.1.3+{{ securedrop_app_code_version }}-amd64.deb"
- "securedrop-ossec-agent-3.0.0+{{ securedrop_app_code_version }}-amd64.deb"
- "{{ securedrop_app_code_deb }}.deb"
- "ossec-agent-3.0.0-amd64.deb"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ip_info:
### Used by the install_local_deb_pkgs role ###
local_deb_packages:
- "securedrop-keyring-0.1.2+{{ securedrop_app_code_version }}-amd64.deb"
- "securedrop-config-0.1.2+{{ securedrop_app_code_version }}-amd64.deb"
- "securedrop-config-0.1.3+{{ securedrop_app_code_version }}-amd64.deb"
- "securedrop-ossec-server-3.0.0+{{ securedrop_app_code_version }}-amd64.deb"
- ossec-server-3.0.0-amd64.deb

Expand Down

This file was deleted.

11 changes: 0 additions & 11 deletions install_files/ansible-base/roles/common/tasks/create_users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@
- users
- sudoers

- name: Set SecureDrop bash profile additions.
copy:
src: bashrc_securedrop_additions
dest: /etc/profile.d/securedrop_additions.sh
owner: root
group: root
mode: "0644"
tags:
- users
- environment

# Backwards-compatibility. Previously, the SecureDrop bashrc additions
# for forcing a terminal multiplexer during interactive login sessions were
# added to ~/.bashrc for each admin user account. It's cleaner to add the
Expand Down
2 changes: 1 addition & 1 deletion install_files/securedrop-config/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Priority: optional
Maintainer: SecureDrop Team <[email protected]>
Homepage: https://securedrop.org
Package: securedrop-config
Version: 0.1.2+0.13.0~rc1
Version: 0.1.3+0.13.0~rc1
Architecture: all
Description: Establishes baseline system state for running SecureDrop.
Configures apt repositories.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[[ $- != *i* ]] && return

which tmux >/dev/null 2>&1 || return

function tmux_attach_via_proc() {
pid=$(pgrep --newest tmux)
if test -n "$pid"
then
/proc/$pid/exe attach
fi
return 1
}

if test -z "$TMUX"
then
(tmux attach || tmux_attach_via_proc || tmux new-session)
fi
23 changes: 14 additions & 9 deletions molecule/testinfra/staging/common/test_user_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import hashlib
import os
import re


Expand Down Expand Up @@ -38,16 +40,19 @@ def test_sudoers_tmux_env(host):
the corresponding settings there.
"""

f = host.file('/etc/profile.d/securedrop_additions.sh')
non_interactive_str = re.escape('[[ $- != *i* ]] && return')
tmux_check = re.escape('test -z "$TMUX" && (tmux attach ||'
' tmux new-session)')
host_file = host.file('/etc/profile.d/securedrop_additions.sh')
source_file = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
'../../../../install_files/securedrop-config/etc/profile.d',
'securedrop_additions.sh'
)
)
expected_content = open(source_file).read()
h = hashlib.sha256()
h.update(expected_content)

assert f.contains("^{}$".format(non_interactive_str))
assert f.contains("^if which tmux >\/dev\/null 2>&1; then$")

assert 'test -z "$TMUX" && (tmux attach || tmux new-session)' in f.content
assert f.contains(tmux_check)
assert host_file.sha256sum == h.hexdigest()


def test_tmux_installed(host):
Expand Down

0 comments on commit 8502ca9

Please sign in to comment.