-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sonic-net/SONiC#1367 Why I did it Give ability to: 1. configure limit for active login sessions. 2. configure ssh-server / serial console autologout timeout 3. configure sysrq-capabilities (enable / disable) Work item tracking Microsoft ADO (number only): How I did it Add new service that responsible for serial configuration; Update existing flows for extended ssh-server configurations in hostcfgd; Add YANG model to support new configuration. How to verify it Which release branch to backport (provide reason below if selected) Tested branch (Please provide the tested image version) Description for the changelog Link to config_db schema for YANG module changes [ssh_server](https://github.com/sonic-net/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md#ssh_server) [serial_console](https://github.com/sonic-net/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md#serial_console)
- Loading branch information
1 parent
20ea16f
commit 367495d
Showing
14 changed files
with
220 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Update serial console config | ||
Requires=sonic.target | ||
After=sonic.target | ||
Before=getty-pre.target | ||
StartLimitIntervalSec=0 | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/bin/serial-config.sh | ||
|
||
[Install] | ||
WantedBy=sonic.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
# generate conf file for sysrq capabilities. | ||
sonic-cfggen -d -t /usr/share/sonic/templates/sysrq-sysctl.conf.j2 > /etc/sysctl.d/95-sysrq-sysctl.conf | ||
|
||
SYSRQ_CONF=0 | ||
# update sysrq for current boot. | ||
sysrq_conf=`sonic-db-cli CONFIG_DB HGET "SERIAL_CONSOLE|POLICIES" sysrq_capabilities` | ||
if [ ${sysrq_conf} = "enabled" ]; then | ||
SYSRQ_CONF=1 | ||
fi | ||
sudo echo $SYSRQ_CONF > /proc/sys/kernel/sysrq | ||
|
||
# generate env file for profile.d to set auto-logout timeout for serial consoles. | ||
sonic-cfggen -d -t /usr/share/sonic/templates/tmout-env.sh.j2 > /etc/profile.d/tmout-env.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
############################################################################### | ||
# This file was AUTOMATICALLY GENERATED. DO NOT MODIFY. | ||
# Controlled by serial-config.sh | ||
############################################################################### | ||
{% set sysrq = 0 %} | ||
{% set serial_policies = (SERIAL_CONSOLE | d({})).get('POLICIES', {}) -%} | ||
{% if serial_policies.sysrq_capabilities == 'enabled' %} | ||
{% set sysrq = 1 %} | ||
{% endif %} | ||
kernel.sysrq={{ sysrq }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{# Default timeout (15 min) #} | ||
{% set inactivity_timeout_sec = 900 %} | ||
|
||
{% set serial_pol = (SERIAL_CONSOLE | d({})).get('POLICIES', {}) -%} | ||
{% if serial_pol and serial_pol.inactivity_timeout and serial_pol.inactivity_timeout | int >= 0 %} | ||
{% set inactivity_timeout_sec = serial_pol.inactivity_timeout | int * 60 %} | ||
{% endif %} | ||
|
||
{# apply only for serial tty #} | ||
tty | grep -q tty && \ | ||
export TMOUT={{ inactivity_timeout_sec }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/sonic-yang-models/tests/yang_model_tests/tests/serial_console.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"SERIAL_CONSOLE": { | ||
"desc": "SERIAL_CONSOLE configuration in the Config DB table." | ||
}, | ||
"SERIAL_CONSOLE_INVALID_INACTIVITY_TIMEOUT": { | ||
"desc": "SERIAL_CONSOLE attribute 'inactivity_timeout' set to invalid value (out of allowed range of [0, 35000] minutes).", | ||
"eStr": "does not satisfy the constraint \"0..35000\"" | ||
}, | ||
"SERIAL_CONSOLE_INVALID_SYSRQ" : { | ||
"desc": "SERIAL_CONSOLE attribute 'sysrq' set to invalid value", | ||
"eStr": "Invalid value" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/sonic-yang-models/tests/yang_model_tests/tests_config/serial_console.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"SERIAL_CONSOLE": { | ||
"sonic-serial-console:sonic-serial-console": { | ||
"sonic-serial-console:SERIAL_CONSOLE": { | ||
"POLICIES": { | ||
"inactivity_timeout": 900, | ||
"sysrq_capabilities": "disabled" | ||
} | ||
} | ||
} | ||
}, | ||
|
||
"SERIAL_CONSOLE_INVALID_INACTIVITY_TIMEOUT": { | ||
"sonic-serial-console:sonic-serial-console": { | ||
"sonic-serial-console:SERIAL_CONSOLE": { | ||
"POLICIES": { | ||
"inactivity_timeout": -500 | ||
} | ||
} | ||
} | ||
}, | ||
"SERIAL_CONSOLE_INVALID_SYSRQ" : { | ||
"sonic-serial-console:sonic-serial-console": { | ||
"sonic-serial-console:SERIAL_CONSOLE": { | ||
"POLICIES": { | ||
"sysrq_capabilities": "negative" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/sonic-yang-models/yang-models/sonic-serial-console.yang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//filename: sonic-serial-console.yang | ||
module sonic-serial-console { | ||
yang-version 1.1; | ||
namespace "http://github.com/Azure/sonic-serial-console"; | ||
prefix cli-sessions; | ||
import sonic-types { | ||
prefix stypes; | ||
} | ||
description "SERIAL_CONSOLE YANG Module for SONiC-based OS"; | ||
revision 2023-06-07 { | ||
description "First Revision"; | ||
} | ||
container sonic-serial-console { | ||
container SERIAL_CONSOLE { | ||
description "SERIAL_CONSOLE part of config_db.json"; | ||
container POLICIES { | ||
leaf inactivity_timeout { | ||
description "serial-console inactivity-timeout timer value in minutes"; | ||
type int32 { | ||
range "0..35000"; | ||
} | ||
default 15; | ||
} | ||
|
||
leaf sysrq_capabilities { | ||
type stypes:admin_mode; | ||
description "managing SysRq capabilities"; | ||
default disabled; | ||
} | ||
} | ||
/* end of container POLICIES */ | ||
} | ||
/* end of container SERIAL_CONSOLE */ | ||
} | ||
/* end of top level container */ | ||
} | ||
/* end of module sonic-serial-console */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters