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 HLD #1361

Merged
merged 1 commit into from
Dec 3, 2023
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
278 changes: 278 additions & 0 deletions doc/banner/banner_hld.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
# Banner messages HLD #

## Table of contents
- [Revision](#revision)
- [About this manual](#about-this-manual)
- [Scope](#scope)
- [1 Introduction](#1-introduction)
- [1.1 Feature overview](#11-feature-overview)
- [1.2 Requirements](#12-requirements)
- [2 Design](#2-design)
- [2.1 Overview](#21-overview)
- [2.2 Flows](#25-flows)
- [2.3 CLI](#26-cli)
- [2.3.1 Config command group](#231-config-command-group)
- [2.3.2 Show command](#232-show-command)
- [2.4 YANG model](#24-yang-model)
- [3 Test plan](#3-test-plan)
- [3.1 Unit tests via VS](#31-unit-tests-via-vs)


# Revision
| Rev | Date | Author | Description |
|:---:|:----------:|:-------------------:|:----------------|
| 0.1 | 01/02/2023 | Sviatoslav Boichuk | Initial version |


# About this manual
This document provides a high-level information for the SONiC Banner feature and Banner CLI. It describes high-level behavior, internal definition, design of the commands, syntax, and output definition.

# Scope
The scope of this document is to cover definition, design and implementation of SONiC Banner feature and Banner CLI.
The document covers the next CLI:
1. Commands to configure banner messages
2. Command to display banner settings

<!-- omit in toc -->
## Abbreviations
| Term | Meaning |
|:------|:------------------------------------------|
| SONiC | Software for Open Networking in the Cloud |
| MOTD | Message of the day |
| DB | Database |
| CLI | Сommand-line Interface |
| YANG | Yet Another Next Generation |

<!-- omit in toc -->
## List of figures
- [Figure 1: Banner system chart diagram](#figure-1-banner-system-chart-diagram)
- [Figure 2: Banner init flow](#figure-2-banner-init-flow)
- [Figure 3: Banner config flow](#figure-3-banner-config-flow)
- [Figure 4: Banner show configuration](#figure-4-banner-show-configuration)

# 1 Introduction

## 1.1 Feature overview
The SONiC maintains several messages for communication with users. These messages are associated with login and logout processes.

There are few banners message types:
| Type | Description |
| :-----------: | :-----------------------------------------------------------------------------: |
| login | Display a banner to the users connected locally or remotely before login prompt |
| motd | Display a banner to the users after login prompt |
| logout | Display a logout banner to the users connected locally or remotely |
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Please explain the purpose or use case of logout banner requirement.
  2. Mention the Linux banner files (/etc/banner, /etc/motd, etc) where the banners are maintained for completeness

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Purpose to have logout message is - full interface (login-motd-logout)
  2. Updated HLD and mentioned Linux files

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, still not convinced about the use case for logout banner. Linux does not support logout banner natively, seems to be something new being brought as SONiC specific. I would recommend to add logout banner, if valid use case is available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logout message supported by bash (bash.bash_logout file). The logout message will be written from ConfDB to new file: /etc/logout_message. And "bash.bash_logout" will be modified to read logout message from "/etc/logout_message" and display it (via 'echo'). Some vendors, for example Mellanox (https://docs.nvidia.com/networking/display/onyxv3102002/ui+commands#src-80577389_UICommands-Banner) support logout banner, so it might be useful for users.



## 1.2 Requirements

**This feature will support the following functionality:**
1. Show Banner configuration
2. Configure Banner
1. Feature state
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is enable / disable of banner feature is supported? If so, unable to locate the respective commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated HLD with feature state enable/disable command (please see section 2.3.1 Config command group)

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be great if below details are added into HLD

  1. The behavior when feature state is disabled ==> Is it intended to revert back to default SONiC banner? If not, what is the procedure to revert back to default banner?
  2. The behavior of when feature state is enabled ==> Is user configured banner will be applied into system only when state is enabled?
  3. The behavior of banner configuration when feature state is disabled
  4. The provisions to revert back to default banners independently, looks like currently the feature state disabled option is meant for that (if the assumption is correct). Both banners will be reverted to default. I would suggest to add default option in both command syntax (config login banner default, config motd banner default) and remove the feature enable / disable option. This will provide flexibility to user to manage the banners independently and consistent with other configuration commands to set default values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated Flows section in HLD with explanation regarding feature state.
Regarding reverting back to default SONiC banners. AFAIK SONiC OS doesn't have an infra to restore configuration to default values, and whatever configuration you changed - to revert it back to "default" you need to configured "default" value again manually. The same is for this feature.

2. Login message
3. Logout message
4. MOTD

# 2 Design

## 2.1 Overview
Here is the representation of SONiC platform using Banner feature:

![Banner system chart diagram](images/banner_system_chart_diagram.png "Figure 1: Banner system chart diagram")
<!-- omit in toc -->
###### Figure 1: Banner system chart diagram

This feature require access to SONiC DB. All messages (MOTD, login and logout) saved into the SONiC config database. Hostcfgd will listen for the configuration changes in corresponding tables and restart banner-config service. Banner config service - it is simple SystemD service which runs before we get SSH connection. It reads configured messages from database and apply it to Linux.

**The Linux files will be used:**
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering why should user not directly update the linux files. What is the value added by this HLD?

Is there a really scenarios that we need to config banner per device? If no, maybe a single command line to update these "Linux files" will be good enough. No dependency on database, hostcfgd, no need to have another service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The banner messages are user configuration.
We would like to provide to user simple CLI commands to configure messages.
Saved banners to Config DB will be restored after upgrade, so user don't need to set them again.

1. /etc/issue.net and /etc/issue - Login message
Copy link
Collaborator

Choose a reason for hiding this comment

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

I hope that Debian uses /etc/login.warn file as default login banner file & Linux flavors use /etc/issue and /etc/issue.net files. Please correct me, if wrong. If so, any reason why it is not being updated & introducing new 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.

Don't see /etc/login.warn file is used by SONiC. The messages is configured to /etc/motd, /etc/issue.net files.
The Banner feature is going use the same files. We introduce only 1 new file: /etc/logout_message for logout banner.
This file will be used in "bash.bash_logout" script to read and display configured logout message.

2. /etc/motd - Message of the day
3. /etc/logout_message - Logout message

## 2.2 Flows
<!-- omit in toc -->
### 2.2.1 Banner init flow
![Banner init flow](images/banner_init_diagram.png "Figure 2: Banner init flow")
<!-- omit in toc -->
###### Figure 2: Banner init flow

<!-- omit in toc -->
### 2.5.2 Banner config flow
![Banner config flow](images/banner_config_diagram.png "Figure 3: Banner config flow")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would recommend to update the banner files directly from hostcfgd service. This will avoid introducing another service (banner-config) which is intended to fetch the data from redis & update the banner files.
Is there any advantage of introducing new host service?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The hostcfgd (after reboot) start later then network service - means banner might not be updated when user login to the system.
It is main goal to use the systemd service as single point where the banners will be updated and it will start before network service.

<!-- omit in toc -->
###### Figure 3: Banner config flow

<!-- omit in toc -->
### 2.5.2 Banner show configuration
![Banner show configuration](images/banner_show_diagram.png "Figure 4: Banner show configuration")
<!-- omit in toc -->
###### Figure 4: Banner show configuration

The default Banner feature state is disabled. It means - the current (default) SONiC OS banner messages won't be changed.
With disabled feature state - user can use provided CLI to configre banner messages. The changes will be applied to Config DB table.
Only with enabled feature state, configured banner messages from Config DB will be applied to Linux.

## 2.3 CLI

<!-- omit in toc -->
### 2.3.1 Command structure

**User interface**:
```
config
\-- banner
|-- state <enabled|disabled>
|-- login <message>
|-- logout <message>
|-- motd <message>

show
\-- banner
```

**Options:**

General:
1. `<message>` - Message to be configured: `string`

## Multiline string support
Banner feature support multiline string message.
Example: config banner login "Hello!\nWellcome to SONiC CLI!"
Banner output: "
Hello!
Wellcome to SONiC CLI!
"


#### 2.3.1 Config command group
**The following command set banner feature state:**
```bash
config banner state <enabled|disabled>
```

**The following command set loin banner message:**
```bash
config banner login <message>
```

**The following command set logout banner message:**
```bash
config banner logout <message>
```

**The following command set mesage of the day (MOTD):**
```bash
config banner motd <message>
```

#### 2.3.2 Show command
**The following command display banner configuration:**
```bash
root@sonic:/home/admin# show banner
state login motd logout
------- ------- ------------------------------------------------ --------
enabled Login You are on
Message ____ ___ _ _ _ ____
/ ___| / _ \| \ | (_)/ ___|
\___ \| | | | \| | | |
___) | |_| | |\ | | |___
|____/ \___/|_| \_|_|\____|

-- 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/
```

## 2.4 YANG model
New YANG model `sonic-banner.yang` will be added to provide support for configuring Banner messages.

**Skeleton code:**
```
module sonic-banner {

yang-version 1.1;

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

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 MESSAGE {
leaf state {
type string {
pattern "enabled|disabled";
}
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 */
}
/* end of module sonic-banner */
```

# 3 Test plan

## 3.1 Unit tests

1. Configure login banner message
1. Logout form system. Login again - expected to see configured message
before login prompt.
2. Do not save configuration and reboot device, login to the system - expected to see default message before login prompt.
3. Save configuration and reboot device - expected to see configured message before login prompt.
2. Configure message of the day
1. Logout form system. Login again - expected to see configured message
after login prompt.
2. Do not save configuration and reboot device,login to the system - expected to see default message after login prompt.
3. Save configuration and reboot device - expected to see configured message after login prompt.
3. Configure logout banner message
1. Logout form system - expected to see configured logout message.
2. Do not save configuration and reboot device. Logout from system after reboot - expected to see default message before login prompt.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I hope that expected result shall be the default logout banner message after login + logout sequence

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

3. Save configuration and reboot device. Logout from system after reboot expected to see configured message before login prompt.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I hope that expected result shall be the configured logout banner message after login + logout sequence

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

Binary file added doc/banner/images/banner_config_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/banner/images/banner_init_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/banner/images/banner_show_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/banner/images/banner_system_chart_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.