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

[canonical-livepatch-onprem] Add Canonical Livepatch on-prem server support #3418

Merged
merged 1 commit into from
Nov 19, 2023
Merged
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
42 changes: 42 additions & 0 deletions sos/report/plugins/canonical_livepatch_onprem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file is part of the sos project: https://github.com/sosreport/sos
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# version 2 of the GNU General Public License.
#
# See the LICENSE file in the source distribution for further information.

from sos.report.plugins import Plugin, UbuntuPlugin


class CanonicaLivepatchOnprem(Plugin, UbuntuPlugin):

short_desc = 'Canonical Livepatch Onprem Service'

plugin_name = 'canonical_livepatch_onprem'
profiles = ('services',)
services = ("livepatch-server",)

def setup(self):
self.add_copy_spec([
"/etc/livepatchd.yaml",
Copy link
Member

Choose a reason for hiding this comment

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

lgtm, just a question: is there an api token or a user/pass we should obfuscate in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are both, actually - user credentials and a token that authenticates against upstream livepatch.. User password is already encoded, but perhaps not a bad idea to obfuscate. Is that something we'd do in the plugin directly, or elsewhere in sos?

Copy link
Member

Choose a reason for hiding this comment

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

You can do it directly in the plugin itself. Here's an example of obfuscation in a yaml file:

https://github.com/sosreport/sos/blob/main/sos/report/plugins/juju.py#L65

Copy link
Contributor Author

@adam-vest adam-vest Nov 16, 2023

Choose a reason for hiding this comment

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

Awesome, thanks for the link! I have some obfuscation code in now that looks like it's having the intended effect 🙂 I'll push once I get the simplification that Arif mentioned sorted out.

])

def postproc(self):
onprem_conf = "/etc/livepatchd.yaml"
protect_keys = [
"username",
"password",
"token",
"connection_string",
]

# Redact simple yaml style "key: value".
keys_regex = r"(^(-|\s)*(%s)\s*:\s*)(.*)" % "|".join(protect_keys)
sub_regex = r"\1*********"
self.do_path_regex_sub(onprem_conf, keys_regex, sub_regex)

# Redact conf
self.do_file_private_sub(onprem_conf)

# vim: set et ts=4 sw=4 :