List insecure plugins 12/15712/12
authorAric Gardner <agardner@linuxfoundation.org>
Fri, 17 May 2019 21:34:30 +0000 (17:34 -0400)
committerAric Gardner <agardner@linuxfoundation.org>
Tue, 28 May 2019 14:57:05 +0000 (14:57 +0000)
List active plugins that have a known
vulnerability

Example output:

$ lftools jenkins -s 'build.opnfv.org/ci' plugins sec
pam-auth:1.5    pam-auth:1.5
https://jenkins.io/security/advisory/2019-05-21/#SECURITY-1316
credentials:2.1.18      credentials:2.1.18
https://jenkins.io/security/advisory/2019-05-21/#SECURITY-1322

jenkins_jobs.ini config
$ cat ~/.config/jenkins_jobs/jenkins_jobs.ini | grep build.opnfv.org/ci
[build.opnfv.org/ci]
user=
password=
url=https://build.opnfv.org/ci

ISSUE: RELENG-2046
Signed-off-by: Aric Gardner <agardner@linuxfoundation.org>
Signed-off-by: Jessica Wagantall <jwagantall@linuxfoundation.org>
Change-Id: I807a1e33d10c42c0d48f7fd179858eebc368c1e8

docs/index.rst
docs/jenkins/index.rst [new file with mode: 0644]
docs/jenkins/plugins.rst [new file with mode: 0644]
lftools/cli/jenkins/plugins.py
releasenotes/notes/lftools-jenkins-plugins-b4dbbf23454f659d.yaml [new file with mode: 0644]

index 0ffbd58..8a55e5c 100644 (file)
@@ -20,6 +20,7 @@ Contents:
     release-notes
     installation
     commands/index
+    jenkins/index
 
 Indices and tables
 ==================
diff --git a/docs/jenkins/index.rst b/docs/jenkins/index.rst
new file mode 100644 (file)
index 0000000..306ca5f
--- /dev/null
@@ -0,0 +1,12 @@
+#######
+Jenkins
+#######
+
+lftools is a collection of scripts written directly in python or externally via
+bash. It supports the following Jenkins specific commands.
+
+.. toctree::
+    :maxdepth: 2
+
+    plugins
+
diff --git a/docs/jenkins/plugins.rst b/docs/jenkins/plugins.rst
new file mode 100644 (file)
index 0000000..2075819
--- /dev/null
@@ -0,0 +1,6 @@
+*******
+Plugins
+*******
+
+.. program-output:: lftools jenkins plugins --help
+
index efeb41b..283da21 100644 (file)
@@ -12,6 +12,7 @@
 __author__ = 'Trevor Bramwell'
 
 import click
+import requests
 
 
 def checkmark(truthy):
@@ -21,8 +22,8 @@ def checkmark(truthy):
     return u'\u2717'
 
 
-def print_plugin(plugin, namefield='longName'):
-    """Print the plugin longName and version."""
+def print_plugin(plugin, namefield='shortName'):
+    """Print the plugin shortName and version."""
     print("%s:%s" % (plugin[namefield], plugin['version']))
 
 
@@ -124,6 +125,59 @@ def active(ctx):
             print_plugin(plugin)
 
 
+@click.command()
+@click.pass_context
+def sec(ctx):
+    """List plugins with a known vulnerability.
+
+    Output is in the format:
+
+    Vulnerable Version\t Installed Version\t Link.
+    """
+    r = requests.get('http://updates.jenkins-ci.org/update-center.actual.json')
+    warn = r.json()['warnings']
+
+    # create a dict of relevant info from jenkins update center
+    secdict = {}
+    for w in warn:
+        name = (w['name'])
+        url = (w['url'])
+        for version in w['versions']:
+            lastversion = version.get('lastVersion')
+        nv = {name: lastversion}
+        secdict.update(nv)
+
+    # create a dict of our active plugins
+    activedict = {}
+    plugins = ctx.obj['plugins']
+    for key in plugins.keys():
+        _, plugin_name = key
+        plugin = plugins[plugin_name]
+        if plugin['active']:
+            name = plugin['shortName']
+            version = plugin['version']
+            nv = {name: version}
+            activedict.update(nv)
+
+    # find the delta
+    shared = []
+    for key in set(secdict.keys()) & set(activedict.keys()):
+        shared.append(key)
+        ourversion = (activedict[key])
+        theirversion = (secdict[key])
+        t1 = tuple([ourversion])
+        t2 = tuple([theirversion])
+        if (t1) <= (t2):
+            # Print Vulnerable Version\t Installed Version\t Link
+            for w in warn:
+                name = (w['name'])
+                url = (w['url'])
+                for version in w['versions']:
+                    lastversion = version.get('lastVersion')
+                if name == key and secdict[key] == lastversion:
+                    print("{0}:{1}\t{0}:{2}\t{3}".format(key, secdict[key], activedict[key], url))
+
+
 plugins_init.add_command(list_plugins, name='list')
 plugins_init.add_command(pinned)
 plugins_init.add_command(dynamic)
@@ -131,3 +185,4 @@ plugins_init.add_command(needs_update, name='needs-update')
 plugins_init.add_command(active)
 plugins_init.add_command(enabled)
 plugins_init.add_command(disabled)
+plugins_init.add_command(sec)
diff --git a/releasenotes/notes/lftools-jenkins-plugins-b4dbbf23454f659d.yaml b/releasenotes/notes/lftools-jenkins-plugins-b4dbbf23454f659d.yaml
new file mode 100644 (file)
index 0000000..55cb520
--- /dev/null
@@ -0,0 +1,4 @@
+---
+features:
+  - |
+    List active plugins that have a known vulnerability.