From 606ff8e77b2dd3cae7b12151a4896795158125fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Douglas=20Mendiz=C3=A1bal?= Date: Thu, 22 Oct 2020 15:05:33 -0500 Subject: [PATCH] Use barbican.conf in barbican-manage This patch updates the hsm subcommand in barbican-manage to read any required values from barbican.conf. Users may continue to specify those values as parameters in the command line, and those values will take precedence over values in barbican.conf. Existing scripts that call barbican-manage should continue to work as expected as the values passed will be used instead of looking into barbican.conf. Change-Id: I4e86e73bbdef0e16d3699cec1cc8f7e17dfb643b (cherry picked from commit 666034475a3fed207c52c70f4041d749d7630ef7) --- barbican/cmd/barbican_manage.py | 198 ++++++++++-------- barbican/plugin/crypto/p11_crypto.py | 5 + barbican/tests/cmd/test_barbican_manage.py | 87 ++++++++ ...f-in-barbican-manage-52035c1cdbfc5a26.yaml | 10 + 4 files changed, 217 insertions(+), 83 deletions(-) create mode 100644 releasenotes/notes/use-barbican-conf-in-barbican-manage-52035c1cdbfc5a26.yaml diff --git a/barbican/cmd/barbican_manage.py b/barbican/cmd/barbican_manage.py index af0ad63cd..ebdba8d35 100644 --- a/barbican/cmd/barbican_manage.py +++ b/barbican/cmd/barbican_manage.py @@ -32,6 +32,7 @@ from barbican.common import config from barbican.model import clean from barbican.model.migration import commands from barbican.model import sync +from barbican.plugin.crypto import p11_crypto from barbican.plugin.crypto import pkcs11 import barbican.version @@ -71,8 +72,8 @@ class DbCommands(object): @args('--soft-delete-expired-secrets', '-e', action='store_true', dest='do_soft_delete_expired_secrets', default=False, help='Soft delete secrets that are expired.') - def clean(self, dburl=None, min_days=None, verbose=None, log_file=None, - do_clean_unassociated_projects=None, + def clean(self, conf, dburl=None, min_days=None, verbose=None, + log_file=None, do_clean_unassociated_projects=None, do_soft_delete_expired_secrets=None): """Clean soft deletions in the database""" if dburl is None: @@ -96,7 +97,7 @@ class DbCommands(object): help='the message for the DB change') @args('--autogenerate', action="store_true", dest='autogen', default=False, help='autogenerate from models') - def revision(self, dburl=None, message=None, autogen=None): + def revision(self, conf, dburl=None, message=None, autogen=None): """Process the 'revision' Alembic command.""" if dburl is None: commands.generate(autogenerate=autogen, message=str(message), @@ -112,7 +113,7 @@ class DbCommands(object): @args('--version', '-v', metavar='', default='head', help='the version to upgrade to, or else ' 'the latest/head if not specified.') - def upgrade(self, dburl=None, version=None): + def upgrade(self, conf, dburl=None, version=None): """Process the 'upgrade' Alembic command.""" if dburl is None: commands.upgrade(to_version=str(version), @@ -126,7 +127,7 @@ class DbCommands(object): help='barbican database URL') @args('--verbose', '-V', action='store_true', dest='verbose', default=False, help='Show full information about the revisions.') - def history(self, dburl=None, verbose=None): + def history(self, conf, dburl=None, verbose=None): if dburl is None: commands.history(verbose, sql_url=CONF.sql_connection) else: @@ -138,7 +139,7 @@ class DbCommands(object): help='barbican database URL') @args('--verbose', '-V', action='store_true', dest='verbose', default=False, help='Show full information about the revisions.') - def current(self, dburl=None, verbose=None): + def current(self, conf, dburl=None, verbose=None): if dburl is None: commands.current(verbose, sql_url=CONF.sql_connection) else: @@ -154,7 +155,8 @@ class DbCommands(object): dest='log_file', help='Set log file location. ' 'Default value for log_file can be found in barbican.conf') - def sync_secret_stores(self, dburl=None, verbose=None, log_file=None): + def sync_secret_stores(self, conf, dburl=None, verbose=None, + log_file=None): """Sync secret_stores table with barbican.conf""" if dburl is None: dburl = CONF.sql_connection @@ -170,61 +172,66 @@ class DbCommands(object): class HSMCommands(object): """Class for managing HSM/pkcs11 plugin""" + _CKK_AES = 'CKK_AES' + description = "Subcommands for managing HSM/PKCS11" check_mkek_description = "Checks if a MKEK label is available" @args('--library-path', metavar='', dest='libpath', - default='/usr/lib/libCryptoki2_64.so', - help='Path to vendor PKCS11 library') - @args('--slot-id', metavar='', dest='slotid', default=1, - help='HSM Slot id (Should correspond to a configured PKCS11 slot, \ - default is 1)') - @args('--passphrase', metavar='', default=None, required=True, - help='Password to login to PKCS11 session') - @args('--label', '-L', metavar='