Skip to content

Commit

Permalink
try system test
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterTea committed Feb 3, 2024
1 parent da05312 commit 0c0b4f0
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 11 deletions.
35 changes: 29 additions & 6 deletions .github/workflows/linux_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,29 @@ jobs:
run: |
mkdir -p ~/.ssh/
echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive ACCEPT_EULA=Y apt-get install -y curl zip unzip tar libssl-dev libcurl4-openssl-dev libunwind-dev git cmake ninja-build gdb protobuf-compiler libsodium-dev libgflags-dev libprotobuf-dev libutempter-dev g++
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
apt-get update
DEBIAN_FRONTEND=noninteractive ACCEPT_EULA=Y apt-get install -y rsyslog curl zip unzip tar libssl-dev libcurl4-openssl-dev libunwind-dev git cmake ninja-build gdb protobuf-compiler libsodium-dev libgflags-dev libprotobuf-dev libutempter-dev g++ net-tools lsof
echo "KEYGEN"
netstat -nlp | grep :22
sed -i '/imklog/s/^/#/' /etc/rsyslog.conf
echo "LogLevel DEBUG3" >> /etc/ssh/sshd_config
#echo "Port 2222" >> /etc/ssh/sshd_config
service rsyslog restart
service ssh restart
cat /var/log/auth.log
cat /etc/ssh/sshd_config
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P "" -N ""
echo "KEYGEN"
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
echo "KEYGEN"
cat ~/.ssh/id_rsa.pub >> ~/.ssh/known_hosts
echo "KEYGEN"
chown $USER:$USER ~/{.,.ssh/,.ssh/authorized_keys,.ssh/known_hosts}
chmod 600 ~/.ssh/authorized_keys
chmod go-w ~/
echo "KEYGEN"
ssh -vvvvvvv -o "StrictHostKeyChecking no" -o 'PreferredAuthentications=publickey' -p 2222 localhost "echo foobar" # Fails if we can't ssh into localhost without a password
if [[ -z "${ACT}" ]]; then auth_header="$(git config --local --get http.https://github.com/.extraheader)"; fi
git submodule sync --recursive
git submodule update --init --force --recursive
Expand Down Expand Up @@ -95,6 +115,9 @@ jobs:
make -j`nproc`
TSAN_OPTIONS="suppressions=../test/test_tsan.suppression" ./et-test
popd
./test/system_tests/connect_with_jumphost.sh
rm -Rf build
msan_linux:
Expand All @@ -109,7 +132,7 @@ jobs:
echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive ACCEPT_EULA=Y apt-get install -y curl zip unzip tar libssl-dev libcurl4-openssl-dev libunwind-dev git cmake ninja-build gdb protobuf-compiler libsodium-dev libgflags-dev libprotobuf-dev libutempter-dev g++
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
if [[ -z "${ACT}" ]]; then auth_header="$(git config --local --get http.https://github.com/.extraheader)"; fi
git submodule sync --recursive
git submodule update --init --force --recursive
Expand Down Expand Up @@ -154,7 +177,7 @@ jobs:
echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive ACCEPT_EULA=Y apt-get install -y curl zip unzip tar libssl-dev libcurl4-openssl-dev libunwind-dev git cmake ninja-build gdb protobuf-compiler libsodium-dev libgflags-dev libprotobuf-dev libutempter-dev g++
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
if [[ -z "${ACT}" ]]; then auth_header="$(git config --local --get http.https://github.com/.extraheader)"; fi
git submodule sync --recursive
git submodule update --init --force --recursive
Expand Down Expand Up @@ -199,7 +222,7 @@ jobs:
echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive ACCEPT_EULA=Y apt-get install -y curl zip unzip tar libssl-dev libcurl4-openssl-dev libunwind-dev git cmake ninja-build gdb protobuf-compiler libsodium-dev libgflags-dev libprotobuf-dev libutempter-dev g++ lcov
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
if [[ -z "${ACT}" ]]; then auth_header="$(git config --local --get http.https://github.com/.extraheader)"; fi
git submodule sync --recursive
git submodule update --init --force --recursive
Expand Down
12 changes: 9 additions & 3 deletions src/terminal/SshSetupHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ string genCommand(const string& passkey, const string& id,

string SshSetupHandler::SetupSsh(const string& user, const string& host,
const string& host_alias, int port,
const string& jumphost, int jport, bool kill,
const string& jumphost, const string& jServerFifo, bool kill,
int vlevel, const string& cmd_prefix,
const string& serverFifo,
const std::vector<std::string>& ssh_options) {
Expand Down Expand Up @@ -72,6 +72,9 @@ string SshSetupHandler::SetupSsh(const string& user, const string& host,

ssh_args.push_back(SSH_SCRIPT_DST);

std::string ssh_concat;
for (const auto &piece : ssh_args) ssh_concat += piece + " ";
VLOG(1) << "Trying ssh with args: " << ssh_concat << endl;
auto sshBuffer = SubprocessToStringInteractive("ssh", ssh_args);

try {
Expand Down Expand Up @@ -107,8 +110,11 @@ string SshSetupHandler::SetupSsh(const string& user, const string& host,
if (!jumphost.empty()) {
/* If jumphost is set, we need to pass dst host and port to jumphost
* and connect to jumphost here */
string cmdoptions{"--verbose=" + std::to_string(vlevel)};
string jump_cmdoptions = cmdoptions + " --jump --dsthost=" + host +
string jump_cmdoptions{"--verbose=" + std::to_string(vlevel)};
if (!jServerFifo.empty()) {
jump_cmdoptions += " --serverfifo=" + jServerFifo;
}
jump_cmdoptions = jump_cmdoptions + " --jump --dsthost=" + host +
" --dstport=" + to_string(port);
string SSH_SCRIPT_JUMP = genCommand(passkey, id, clientTerm, user, kill,
cmd_prefix, jump_cmdoptions);
Expand Down
3 changes: 2 additions & 1 deletion src/terminal/SshSetupHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class SshSetupHandler {
public:
static string SetupSsh(const string &user, const string &host,
const string &host_alias, int port,
const string &jumphost, int jport, bool kill,
const string &jumphost,
const string& jServerFifo, bool kill,
int vlevel, const string &etterminal_path,
const string &serverFifo,
const std::vector<std::string> &ssh_options);
Expand Down
9 changes: 8 additions & 1 deletion src/terminal/TerminalClientMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ int main(int argc, char** argv) {
cxxopts::value<std::string>()) //
("jport", "Jumphost machine port",
cxxopts::value<int>()->default_value("2022")) //
("jserverfifo", "If set, communicate to jumphost on the matching fifo name",
cxxopts::value<string>()->default_value("")) //
("x,kill-other-sessions",
"kill all old sessions belonging to the user") //
("macserver",
Expand Down Expand Up @@ -294,6 +296,11 @@ int main(int argc, char** argv) {
}

int jport = result["jport"].as<int>();
string jServerFifo = "";
if (result["jserverfifo"].as<string>() != "") {
jServerFifo = result["jserverfifo"].as<string>();
}

string serverFifo = "";
if (result["serverfifo"].as<string>() != "") {
serverFifo = result["serverfifo"].as<string>();
Expand All @@ -310,7 +317,7 @@ int main(int argc, char** argv) {
etterminal_path = result["terminal-path"].as<string>();
}
string idpasskeypair = SshSetupHandler::SetupSsh(
username, destinationHost, host_alias, destinationPort, jumphost, jport,
username, destinationHost, host_alias, destinationPort, jumphost, jServerFifo,
result.count("x") > 0, result["verbose"].as<int>(), etterminal_path,
serverFifo, ssh_options);

Expand Down
27 changes: 27 additions & 0 deletions test/system_tests/connect_with_jumphost.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
set -x
set -e

ssh -o 'PreferredAuthentications=publickey' localhost "echo" || exit 1 # Fails if we can't ssh into localhost without a password

# Bypass host check
ssh -o "StrictHostKeyChecking no" localhost echo "Bypassing host check 1"
ssh -o "StrictHostKeyChecking no" 127.0.0.1 echo "Bypassing host check 2"

mkdir -p /tmp/et_test_logs/connect_with_jumphost/1
build/etserver --port 9900 --serverfifo=/tmp/etserver.idpasskey.fifo1 -l /tmp/et_test_logs/connect_with_jumphost/1 &
first_server_pid=$!

mkdir -p /tmp/et_test_logs/connect_with_jumphost/2
build/etserver --port 9901 --serverfifo=/tmp/etserver.idpasskey.fifo2 -l /tmp/et_test_logs/connect_with_jumphost/2 &
second_server_pid=$!
sleep 3

# Make sure servers are working
build/et -c "echo 'Hello World 1!'" --serverfifo=/tmp/etserver.idpasskey.fifo1 --logtostdout localhost:9900
build/et -c "echo 'Hello World 2!'" --serverfifo=/tmp/etserver.idpasskey.fifo2 --logtostdout localhost:9901

build/et -c "echo 'Hello World 3!'" --serverfifo=/tmp/etserver.idpasskey.fifo2 --logtostdout --jumphost localhost --jport 9900 --jserverfifo=/tmp/etserver.idpasskey.fifo1 127.0.0.1:9901 # We can't use 'localhost' for both the jumphost and the destination because ssh doesn't support keeping them the same.

kill -9 $first_server_pid
kill -9 $second_server_pid

0 comments on commit 0c0b4f0

Please sign in to comment.