pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0167-Add-pkinit-status-command.patch

483b06
From 5012843d350b7a39b78e4eb7cab6cff98cae59d5 Mon Sep 17 00:00:00 2001
483b06
From: Martin Babinsky <mbabinsk@redhat.com>
483b06
Date: Fri, 12 May 2017 17:25:30 +0200
483b06
Subject: [PATCH] Add `pkinit-status` command
483b06
483b06
This command is a more streamlined reporting tool for PKINIT feature
483b06
status in the FreeIPA topology. It prints out whether PKINIT is enabled
483b06
or disabled on individual masters in a topology. If a`--server` is
483b06
specified, it reports status for an individual server. If `--status` is
483b06
specified, it searches for all servers that have PKINIT enabled or
483b06
disabled.
483b06
483b06
https://pagure.io/freeipa/issue/6937
483b06
483b06
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
483b06
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
483b06
---
483b06
 API.txt                     |  15 ++++++
483b06
 VERSION.m4                  |   4 +-
483b06
 ipaserver/plugins/pkinit.py | 109 +++++++++++++++++++++++++++++++++++++++++++-
483b06
 3 files changed, 125 insertions(+), 3 deletions(-)
483b06
483b06
diff --git a/API.txt b/API.txt
483b06
index 4e6754afe2deab5c963577f1e1363f1123a31a86..6511ad8d1cb4dc9079628fc058312f31aaec624d 100644
483b06
--- a/API.txt
483b06
+++ b/API.txt
483b06
@@ -3736,6 +3736,20 @@ command: ping/1
483b06
 args: 0,1,1
483b06
 option: Str('version?')
483b06
 output: Output('summary', type=[<type 'unicode'>, <type 'NoneType'>])
483b06
+command: pkinit_status/1
483b06
+args: 1,7,4
483b06
+arg: Str('criteria?')
483b06
+option: Flag('all', autofill=True, cli_name='all', default=False)
483b06
+option: Flag('raw', autofill=True, cli_name='raw', default=False)
483b06
+option: Str('server_server?', autofill=False, cli_name='server')
483b06
+option: Int('sizelimit?', autofill=False)
483b06
+option: StrEnum('status?', autofill=False, cli_name='status', values=[u'enabled', u'disabled'])
483b06
+option: Int('timelimit?', autofill=False)
483b06
+option: Str('version?')
483b06
+output: Output('count', type=[<type 'int'>])
483b06
+output: ListOfEntries('result')
483b06
+output: Output('summary', type=[<type 'unicode'>, <type 'NoneType'>])
483b06
+output: Output('truncated', type=[<type 'bool'>])
483b06
 command: plugins/1
483b06
 args: 0,3,3
483b06
 option: Flag('all', autofill=True, cli_name='all', default=True)
483b06
@@ -6798,6 +6812,7 @@ default: permission_remove_member/1
483b06
 default: permission_show/1
483b06
 default: ping/1
483b06
 default: pkinit/1
483b06
+default: pkinit_status/1
483b06
 default: plugins/1
483b06
 default: privilege/1
483b06
 default: privilege_add/1
483b06
diff --git a/VERSION.m4 b/VERSION.m4
483b06
index e10ee3cad6f5a6e023ea3cb9ec20591b7caae0bd..8aa3ef03f352cd176579c5d5848ed9550f22105d 100644
483b06
--- a/VERSION.m4
483b06
+++ b/VERSION.m4
483b06
@@ -73,8 +73,8 @@ define(IPA_DATA_VERSION, 20100614120000)
483b06
 #                                                      #
483b06
 ########################################################
483b06
 define(IPA_API_VERSION_MAJOR, 2)
483b06
-define(IPA_API_VERSION_MINOR, 226)
483b06
-# Last change: Remove the pkinit-anonymous command
483b06
+define(IPA_API_VERSION_MINOR, 227)
483b06
+# Last change: Add `pkinit-status` command
483b06
 
483b06
 
483b06
 ########################################################
483b06
diff --git a/ipaserver/plugins/pkinit.py b/ipaserver/plugins/pkinit.py
483b06
index e49b31091d676865fa7f023be8edc3cdef9d6d2c..970f955c54bc489765d2565255e8805138a35307 100644
483b06
--- a/ipaserver/plugins/pkinit.py
483b06
+++ b/ipaserver/plugins/pkinit.py
483b06
@@ -3,11 +3,33 @@
483b06
 #
483b06
 
483b06
 from ipalib import Object
483b06
-from ipalib import _
483b06
+from ipalib import _, ngettext
483b06
+from ipalib.crud import Search
483b06
+from ipalib.parameters import Int, Str, StrEnum
483b06
 from ipalib.plugable import Registry
483b06
 
483b06
 register = Registry()
483b06
 
483b06
+__doc__ = _("""
483b06
+Kerberos PKINIT feature status reporting tools.
483b06
+
483b06
+Report IPA masters on which Kerberos PKINIT is enabled or disabled
483b06
+
483b06
+EXAMPLES:
483b06
+ List PKINIT status on all masters:
483b06
+   ipa pkinit-status
483b06
+
483b06
+ Check PKINIT status on `ipa.example.com`:
483b06
+   ipa pkinit-status --server ipa.example.com
483b06
+
483b06
+ List all IPA masters with disabled PKINIT:
483b06
+   ipa pkinit-status --status='disabled'
483b06
+
483b06
+For more info about PKINIT support see:
483b06
+
483b06
+https://www.freeipa.org/page/V4/Kerberos_PKINIT
483b06
+""")
483b06
+
483b06
 
483b06
 @register()
483b06
 class pkinit(Object):
483b06
@@ -17,3 +39,88 @@ class pkinit(Object):
483b06
     object_name = _('pkinit')
483b06
 
483b06
     label = _('PKINIT')
483b06
+
483b06
+    takes_params = (
483b06
+        Str(
483b06
+            'server_server?',
483b06
+            cli_name='server',
483b06
+            label=_('Server name'),
483b06
+            doc=_('IPA server hostname'),
483b06
+        ),
483b06
+        StrEnum(
483b06
+            'status?',
483b06
+            cli_name='status',
483b06
+            label=_('PKINIT status'),
483b06
+            doc=_('Whether PKINIT is enabled or disabled'),
483b06
+            values=(u'enabled', u'disabled'),
483b06
+            flags={'virtual_attribute', 'no_create', 'no_update'}
483b06
+        )
483b06
+    )
483b06
+
483b06
+
483b06
+@register()
483b06
+class pkinit_status(Search):
483b06
+    __doc__ = _('Report PKINIT status on the IPA masters')
483b06
+
483b06
+    msg_summary = ngettext('%(count)s server matched',
483b06
+                           '%(count)s servers matched', 0)
483b06
+
483b06
+    takes_options = Search.takes_options + (
483b06
+        Int(
483b06
+            'timelimit?',
483b06
+            label=_('Time Limit'),
483b06
+            doc=_('Time limit of search in seconds (0 is unlimited)'),
483b06
+            flags=['no_display'],
483b06
+            minvalue=0,
483b06
+            autofill=False,
483b06
+        ),
483b06
+        Int(
483b06
+            'sizelimit?',
483b06
+            label=_('Size Limit'),
483b06
+            doc=_('Maximum number of entries returned (0 is unlimited)'),
483b06
+            flags=['no_display'],
483b06
+            minvalue=0,
483b06
+            autofill=False,
483b06
+        ),
483b06
+    )
483b06
+
483b06
+    def get_pkinit_status(self, server, status):
483b06
+        backend = self.api.Backend.serverroles
483b06
+        ipa_master_config = backend.config_retrieve("IPA master")
483b06
+
483b06
+        if server is not None:
483b06
+            servers = [server]
483b06
+        else:
483b06
+            servers = ipa_master_config['ipa_master_server']
483b06
+
483b06
+        pkinit_servers = ipa_master_config['pkinit_server_server']
483b06
+
483b06
+        for s in servers:
483b06
+            pkinit_status = {
483b06
+                u'server_server': s,
483b06
+                u'status': (
483b06
+                    u'enabled' if s in pkinit_servers else u'disabled'
483b06
+                )
483b06
+            }
483b06
+            if status is not None and pkinit_status[u'status'] != status:
483b06
+                continue
483b06
+
483b06
+            yield pkinit_status
483b06
+
483b06
+    def execute(self, *keys, **options):
483b06
+        if keys:
483b06
+            return dict(
483b06
+                result=[],
483b06
+                count=0,
483b06
+                truncated=False
483b06
+            )
483b06
+
483b06
+        server = options.get('server_server', None)
483b06
+        status = options.get('status', None)
483b06
+
483b06
+        if server is not None:
483b06
+            self.api.Object.server_role.ensure_master_exists(server)
483b06
+
483b06
+        result = sorted(self.get_pkinit_status(server, status))
483b06
+
483b06
+        return dict(result=result, count=len(result), truncated=False)
483b06
-- 
483b06
2.9.4
483b06