Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Banner] Add new feature including config, yang and tests #16957

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions files/build_templates/init_cfg.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@
"special_class": "true"
}
},
"BANNER_MESSAGE": {
"global": {
"state": "disabled",
"login": "Debian GNU/Linux 11",
"motd": "You are on\n ____ ___ _ _ _ ____\n / ___| / _ \\| \\ | (_)/ ___|\n \\___ \\| | | | \\| | | |\n ___) | |_| | |\\ | | |___\n |____/ \\___/|_| \\_|_|\\____|\n\n-- Software for Open Networking in the Cloud --\n\nUnauthorized access and/or use are prohibited.\nAll access and/or use are subject to monitoring.\n\nHelp: https://sonic-net.github.io/SONiC/\n\n",
"logout": ""
}
},
"SYSTEM_DEFAULTS" : {
{%- if include_mux == "y" %}
"mux_tunnel_egress_acl": {
Expand Down
7 changes: 7 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in
# Apply environtment configuration files
sudo cp $IMAGE_CONFIGS/environment/environment $FILESYSTEM_ROOT/etc/
sudo cp $IMAGE_CONFIGS/environment/motd $FILESYSTEM_ROOT/etc/
sudo cp $IMAGE_CONFIGS/environment/logout_message $FILESYSTEM_ROOT/etc/

# Create all needed directories
sudo mkdir -p $FILESYSTEM_ROOT/etc/sonic/
Expand Down Expand Up @@ -223,6 +224,7 @@ sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/bash_*.deb || \
# sonic-utilities-data installs bash-completion as a dependency. However, it is disabled by default
# in bash.bashrc, so we copy a version of the file with it enabled here.
sudo cp -f $IMAGE_CONFIGS/bash/bash.bashrc $FILESYSTEM_ROOT/etc/
sudo cp -f $IMAGE_CONFIGS/bash/bash.bash_logout $FILESYSTEM_ROOT/etc/

# Install readline's initialization file
sudo cp -f $IMAGE_CONFIGS/readline/inputrc $FILESYSTEM_ROOT/etc/
Expand Down Expand Up @@ -589,6 +591,11 @@ sudo cp $IMAGE_CONFIGS/hostname/hostname-config.service $FILESYSTEM_ROOT_USR_LIB
echo "hostname-config.service" | sudo tee -a $GENERATED_SERVICE_FILE
sudo cp $IMAGE_CONFIGS/hostname/hostname-config.sh $FILESYSTEM_ROOT/usr/bin/

# Copy banner configuration scripts
sudo cp $IMAGE_CONFIGS/bannerconfig/banner-config.service $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
echo "banner-config.service" | sudo tee -a $GENERATED_SERVICE_FILE
sudo cp $IMAGE_CONFIGS/bannerconfig/banner-config.sh $FILESYSTEM_ROOT/usr/bin/

# Copy miscellaneous scripts
sudo cp $IMAGE_CONFIGS/misc/docker-wait-any $FILESYSTEM_ROOT/usr/bin/

Expand Down
17 changes: 17 additions & 0 deletions files/image_config/bannerconfig/banner-config.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Update banner config based on configdb
Copy link
Collaborator

@qiluo-msft qiluo-msft Jan 14, 2024

Choose a reason for hiding this comment

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

Requires=config-setup.service
After=config-setup.service
Before=systemd-logind.service sshd.service
BindsTo=database.service
BindsTo=sonic.target

[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/usr/bin/banner-config.sh

[Install]
WantedBy=sonic.target


17 changes: 17 additions & 0 deletions files/image_config/bannerconfig/banner-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -e

STATE=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["state"]')
LOGIN=
MOTD=
LOGOUT=

if [[ $STATE == "enabled" ]]; then
LOGIN=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["login"]')
MOTD=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["motd"]')
LOGOUT=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["logout"]')

echo -e "$LOGIN" > /etc/issue.net
echo -e "$LOGIN" > /etc/issue
echo -e "$MOTD" > /etc/motd
echo -e "$LOGOUT" > /etc/logout_message
fi

Choose a reason for hiding this comment

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

If state is disabled, are you planning clear banner files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we do not clean banner messages.

12 changes: 12 additions & 0 deletions files/image_config/bash/bash.bash_logout
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
LOGOUT_MESSAGE_PATH="/etc/logout_message"
LOGOUT_MESSAGE=

if [[ -f "$LOGOUT_MESSAGE_PATH" ]]; then
LOGOUT_MESSAGE=$(cat $LOGOUT_MESSAGE_PATH)
fi

if [[ -n "$LOGOUT_MESSAGE" ]]; then
# Print logout message
echo $LOGOUT_MESSAGE
fi

Empty file.
2 changes: 2 additions & 0 deletions src/sonic-yang-models/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def run(self):
('yang-models', ['./yang-models/sonic-acl.yang',
'./yang-models/sonic-auto_techsupport.yang',
'./yang-models/sonic-bgp-bbr.yang',
'./yang-models/sonic-banner.yang',
'./yang-models/sonic-bgp-common.yang',
'./yang-models/sonic-bgp-device-global.yang',
'./yang-models/sonic-bgp-global.yang',
Expand Down Expand Up @@ -201,6 +202,7 @@ def run(self):
'./yang-models/sonic-bgp-sentinel.yang',
'./yang-models/sonic-smart-switch.yang',]),
('cvlyang-models', ['./cvlyang-models/sonic-acl.yang',
'./cvlyang-models/sonic-banner.yang',
'./cvlyang-models/sonic-bgp-common.yang',
'./cvlyang-models/sonic-bgp-global.yang',
'./cvlyang-models/sonic-bgp-monitor.yang',
Expand Down
8 changes: 8 additions & 0 deletions src/sonic-yang-models/tests/files/sample_config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,14 @@
"dpu1": {
"midplane_interface": "dpu1"
}
},
"BANNER_MESSAGE": {
"global": {
"state": "enabled",
"login": "Some login message",
"motd": "Some message of the day",
"logout": "Some logout message"
}
}
},
"SAMPLE_CONFIG_DB_UNKNOWN": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"BANNER_MESSAGE_TEST_STATE": {
"desc": "Configure Banner feature state."
},
"BANNER_MESSAGE_TEST_LOGIN" : {
"desc": "Banner login messages configuration in BANNER_MESSAGE table."
},
"BANNER_MESSAGE_TEST_MOTD" : {
"desc": "Banner MOTD messages configuration in BANNER_MESSAGE table."
},
"BANNER_MESSAGE_TEST_LOGOUT" : {
"desc": "Banner logout messages configuration in BANNER_MESSAGE table."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"BANNER_MESSAGE_TEST_STATE": {
"sonic-banner:sonic-banner": {
"sonic-banner:BANNER_MESSAGE": {
"global": {
"state": "enabled",
"login": "Some login message",
"motd": "Some message of the day",
"logout": "Some logout message"
}
}
}
},
"BANNER_MESSAGE_TEST_LOGIN": {
"sonic-banner:sonic-banner": {
"sonic-banner:BANNER_MESSAGE": {
"global": {
"state": "enabled",
"login": "Some login message",
"motd": "Some message of the day",
"logout": "Some logout message"
}
}
}
},
"BANNER_MESSAGE_TEST_MOTD": {
"sonic-banner:sonic-banner": {
"sonic-banner:BANNER_MESSAGE": {
"global": {
"state": "enabled",
"login": "Some login message",
"motd": "Some message of the day",
"logout": "Some logout message"
}
}
}
},
"BANNER_MESSAGE_TEST_LOGOUT": {
"sonic-banner:sonic-banner": {
"sonic-banner:BANNER_MESSAGE": {
"global": {
"state": "enabled",
"login": "Some login message",
"motd": "Some message of the day",
"logout": "Some logout message"
}
}
}
}
}
51 changes: 51 additions & 0 deletions src/sonic-yang-models/yang-models/sonic-banner.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module sonic-banner {
yang-version 1.1;
Copy link
Collaborator

@qiluo-msft qiluo-msft Jan 14, 2024

Choose a reason for hiding this comment

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

@ganglyu @wen587 Please review the yang change. #Closed

namespace "http://github.com/sonic-net/sonic-banner";
prefix banner_message;

import sonic-types {
prefix stypes;
}

description "BANNER_MESSAGE YANG Module for SONiC-based OS";
revision 2023-05-18 {
description "First Revision";
}
container sonic-banner {
container BANNER_MESSAGE {
description "BANNER_MESSAGE part of config_db.json";
container global {
leaf state {
type stypes:admin_mode;
description "Banner feature state";
default disabled;
}
leaf login {
type string;
description "Banner message displayed to user before login prompt";
default "Debian GNU/Linux 11";
}
leaf motd {
type string;
description "Banner message displayed to user after login prompt";
default "You are on
____ ___ _ _ _ ____
/ ___| / _ \\| \\ | (_)/ ___|
\\___ \\| | | | \\| | | |
___) | |_| | |\\ | | |___
|____/ \\___/|_| \\_|_|\\____|
-- Software for Open Networking in the Cloud --
Unauthorized access and/or use are prohibited.
All access and/or use are subject to monitoring.
Help: https://sonic-net.github.io/SONiC/
";
}
leaf logout {
type string;
description "Banner message dispalyed to the users on logout";
default "";
}
} /* end of container MESSAGE */
} /* end of container BANNER_MESSAGE */
} /* end of top level container */
}
Loading