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

[containercfgd] Add containercfgd and syslog rate limit configuration support #12489

Merged
merged 7 commits into from
Dec 8, 2022

Conversation

Junchao-Mellanox
Copy link
Collaborator

HLD: sonic-net/SONiC#1049

Why I did it

Add a containercfgd to handler container side CONFIG DB changes

How I did it

  1. add a daemon containercfgd to run for each containers
  2. add syslog handler to handle syslog rate limit config change

How to verify it

unit test

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205

Description for the changelog

Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

containercfgd.ContainerConfigDaemon.register_handler('LoadMock', mock_handler_cls)
daemon = containercfgd.ContainerConfigDaemon()
daemon.init_data_handler({})
mock_handler_instance.handle_init_data.assert_called_once

Check notice

Code scanning / CodeQL

Statement has no effect

This statement has no effect.
@Junchao-Mellanox
Copy link
Collaborator Author

Build issue pending on PR #12510

@liat-grozovik
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Junchao-Mellanox
Copy link
Collaborator Author

/azpw run Azure.sonic-buildimag

@mssonicbld
Copy link
Collaborator

/AzurePipelines run Azure.sonic-buildimag

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@liushilongbuaa
Copy link
Contributor

/AzurePipelines run Azure.sonic-buildimag

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@liushilongbuaa
Copy link
Contributor

/azprun Azure.sonic-buildimage

@liushilongbuaa
Copy link
Contributor

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Junchao-Mellanox
Copy link
Collaborator Author

/azpw run Azure.sonic-buildimage

@mssonicbld
Copy link
Collaborator

/AzurePipelines run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@zhangyanzhao zhangyanzhao requested a review from mkeda November 7, 2022 03:52
@Junchao-Mellanox
Copy link
Collaborator Author

/azpw run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Junchao-Mellanox
Copy link
Collaborator Author

/azpw run Azure.sonic-buildimage

@mssonicbld
Copy link
Collaborator

/AzurePipelines run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Junchao-Mellanox
Copy link
Collaborator Author

Hi @saiarcot895, could you please kindly help review this?

output = run_command('sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog-container.conf.j2 -a "{{\\"target_ip\\": \\"{}\\", \\"container_name\\": \\"{}\\" }}"'.format(self.target_ip, container_name))
f.write(output)
run_command('cp {} {}'.format(self.TMP_SYSLOG_CONF_PATH, self.SYSLOG_CONF_PATH))
run_command("supervisorctl restart rsyslogd")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these be split into individual entries (such as ["cp", self.TMP_SYSLOG_CONF_PATH, self.SYSLOG_CONF_PATH] and passed directly into subprocess.check_output instead of using shlex.split? That will prevent code injections from outside sources doing something that shouldn't be done.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @saiarcot895 , thanks for the comment. I suppose shlex.split will split cp /tmp/file /tmp/file_copy into ['cp', '/tmp/file', '/tmp/file_copy'], it also prevents code injections. And the benefit is that:

  1. The original command is a complete string which is more readable than a list
  2. shlex.split will do the split for user automatically which prevent user from incorrectly splitting command.

So, I prefer to keep this. What do you say?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's true, because it's split into an array, the first token will always be the command that gets executed. However, if, hypothetically, self.TMP_SYSLOG_CONF_PATH was /tmp/file name, then shlex.split will split cp /tmp/file name /tmp/file_copy into ["cp", "/tmp/file", "name", "/tmp/file_copy"], which is incorrect.

I think considering we know what these arguments should be, just doing the splitting ourselves would be better. (It would also make the JSON argument a couple lines above this a bit easier to read).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@Junchao-Mellanox
Copy link
Collaborator Author

/azpw run Azure.sonic-buildimage

@mssonicbld
Copy link
Collaborator

/AzurePipelines run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@liat-grozovik
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

You have several pipelines (over 10) configured to build pull requests in this repository. Specify which pipelines you would like to run by using /azp run [pipelines] command. You can specify multiple pipelines using a comma separated list.

@saiarcot895 saiarcot895 merged commit 3b3837a into sonic-net:master Dec 8, 2022
@Junchao-Mellanox Junchao-Mellanox deleted the srl-cfgd branch December 20, 2022 03:41
mssonicbld pushed a commit to mssonicbld/sonic-buildimage that referenced this pull request Jan 14, 2023
… support (sonic-net#12489)

* [containercfgd] Add containercfgd and syslog rate limit configuration support

* Fix build issue

* Fix checker issue

* Fix review comment

* Fix review comment

* Update containercfgd.py
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202211: #13361

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants