Skip to content

Commit 698b554

Browse files
authored
[openssh] Introduce custom openssh-server package for supporting reverse console SSH (#5717)
* Build and install openssh from source * Copy openssh deb package to dest folder * Update make rule * Update sonic debian extension * Append empty line before EOF * Update openssh patch * Add openssh-server to base image dependency * Fix indent type * Fix comments * Use commit id instead of tag id and add comment Signed-off-by: Jing Kan jika@microsoft.com
1 parent f2a258a commit 698b554

7 files changed

+91
-0
lines changed

files/build_templates/sonic_debian_extension.j2

+3
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ sudo chmod 600 $FILESYSTEM_ROOT/etc/monit/conf.d/*
263263
sudo cp $IMAGE_CONFIGS/monit/process_checker $FILESYSTEM_ROOT/usr/bin/
264264
sudo chmod 755 $FILESYSTEM_ROOT/usr/bin/process_checker
265265

266+
# Install custom-built openssh sshd
267+
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/openssh-server_*.deb
268+
266269
# Copy crontabs
267270
sudo cp -f $IMAGE_CONFIGS/cron.d/* $FILESYSTEM_ROOT/etc/cron.d/
268271

rules/openssh.dep

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SPATH := $($(OPENSSH_SERVER)_SRC_PATH)
2+
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/openssh.mk rules/openssh.dep
3+
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
4+
DEP_FILES += $(shell git ls-files $(SPATH))
5+
6+
$(OPENSSH_SERVER)_CACHE_MODE := GIT_CONTENT_SHA
7+
$(OPENSSH_SERVER)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
8+
$(OPENSSH_SERVER)_DEP_FILES := $(DEP_FILES)

rules/openssh.mk

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# openssh package
2+
3+
OPENSSH_VERSION = 7.9p1-10+deb10u2
4+
5+
export OPENSSH_VERSION
6+
7+
OPENSSH_SERVER = openssh-server_$(OPENSSH_VERSION)_$(CONFIGURED_ARCH).deb
8+
$(OPENSSH_SERVER)_SRC_PATH = $(SRC_PATH)/openssh
9+
SONIC_MAKE_DEBS += $(OPENSSH_SERVER)
10+
11+
# The .c, .cpp, .h & .hpp files under src/{$DBG_SRC_ARCHIVE list}
12+
# are archived into debug one image to facilitate debugging.
13+
#
14+
DBG_SRC_ARCHIVE += openssh

slave.mk

+1
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
802802
$(LIBPAM_TACPLUS) \
803803
$(LIBNSS_TACPLUS) \
804804
$(MONIT) \
805+
$(OPENSSH_SERVER) \
805806
$(PYTHON_SWSSCOMMON) \
806807
$(PYTHON3_SWSSCOMMON) \
807808
$(SONIC_UTILITIES_DATA) \

src/openssh/Makefile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.ONESHELL:
2+
SHELL = /bin/bash
3+
.SHELLFLAGS += -e
4+
5+
MAIN_TARGET = openssh-server_$(OPENSSH_VERSION)_$(CONFIGURED_ARCH).deb
6+
DERIVED_TARGETS = openssh-server-dbgsym_$(OPENSSH_VERSION)_$(CONFIGURED_ARCH).deb
7+
8+
$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
9+
# Obtain openssh: https://salsa.debian.org/ssh-team/openssh/-/tree/debian/1%257.9p1-10+deb10u2
10+
rm -rf ./openssh-server
11+
git clone https://salsa.debian.org/ssh-team/openssh.git openssh-server
12+
pushd ./openssh-server
13+
14+
# Check out tag: debian/1%7.9p1-10+deb10u2
15+
git checkout -b openssh-src -f 6d9ca74c48d9911342c6ca5aaac8a25974fa2619
16+
17+
# Apply patch series
18+
stg init
19+
stg import -s ../patch/series
20+
21+
# Build package
22+
sudo apt-get -y build-dep openssh
23+
dpkg-buildpackage -rfakeroot -b -us -uc -j$(SONIC_CONFIG_MAKE_JOBS)
24+
popd
25+
26+
mv $(DERIVED_TARGETS) $* $(DEST)/
27+
28+
$(addprefix $(DEST)/, $(DERIVED_TARGETS)): $(DEST)/% : $(DEST)/$(MAIN_TARGET)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
From 6e8cca780dab4680292192058b90a4a28f35d4ab Mon Sep 17 00:00:00 2001
2+
From: Blueve <blueve@users.noreply.github.com>
3+
Date: Mon, 26 Oct 2020 06:44:59 +0000
4+
Subject: [PATCH 1/1] Put style as line number to ssh session environment
5+
variable
6+
7+
By default, the content between : and @ will be trimmed by sshd before it do
8+
authentication and the trimmed string will be dropped silently. To use this
9+
segment as line number for reverse SSH feature, we need to modify the source
10+
code of OpenSSH and put this segment to a environment variable
11+
SSH_TARGET_CONSOLE_LINE, then we can insert a short script into /etc/bash.bashrc
12+
and run command consutil connect $SSH_TARGET_CONSOLE_LINE to enter the
13+
management session automatically after user login.
14+
---
15+
session.c | 5 +++++
16+
1 file changed, 5 insertions(+)
17+
18+
diff --git a/session.c b/session.c
19+
index 19f38637e..654371447 100644
20+
--- a/session.c
21+
+++ b/session.c
22+
@@ -1209,6 +1209,11 @@ do_setup_env(struct ssh *ssh, Session *s, const char *shell)
23+
child_set_env(&env, &envsize, "SSH_ORIGINAL_COMMAND",
24+
original_command);
25+
26+
+ /* Take advantage of authentication style field */
27+
+ if (s->authctxt->style)
28+
+ child_set_env(&env, &envsize, "SSH_TARGET_CONSOLE_LINE",
29+
+ s->authctxt->style);
30+
+
31+
if (debug_flag) {
32+
/* dump the environment */
33+
fprintf(stderr, "Environment:\n");
34+
--
35+
2.25.1
36+

src/openssh/patch/series

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0001-Put-style-as-line-number-to-ssh-session-environment-.patch

0 commit comments

Comments
 (0)