This guide describes how to develop a custom secret store plugin for use by Barbican.
Barbican supports two storage modes for secrets: a secret store mode (detailed on this page), and a cryptographic mode. The secret store mode offloads both encryption/decryption and encrypted secret storage to the plugin implementation. Barbican includes plugin interfaces to a Red Hat Dogtag service and to a Key Management Interoperability Protocol (KMIP) compliant security appliance.
Since the secret store mode defers the storage of encrypted secrets to plugins, Barbican core does not need to store encrypted secrets into its data store, unlike the cryptographic mode. To accommodate the discrepancy between the two secret storage modes, a secret store to cryptographic plugin adapter has been included in Barbican core, as detailed in The Cryptographic Plugin Adapter section below.
The barbican.plugin.interface.secret_store module contains the classes needed to implement a custom plugin. These classes include the SecretStoreBase abstract base class which custom plugins should inherit from, as well as several Data Transfer Object (DTO) classes used to transfer data between Barbican and the plugin.
The DTO classes are used to wrap data that is passed from Barbican to the plugin as well as data that is returned from the plugin back to Barbican. They provide a level of isolation between the plugins and Barbican’s internal data models.
This object is a secret data transfer object (DTO).
This object encapsulates a key and attributes about the key. The attributes include a KeySpec that contains the algorithm and bit length. The attributes also include information on the encoding of the key.
This DTO encapsulates metadata(s) for asymmetric key components.
These components are private_key_meta, public_key_meta and passphrase_meta.
The secret parameter classes encapsulate information about secrets to be stored within Barbican and/or its plugins.
Constant to define the symmetric key type.
Used by getSecret to retrieve a symmetric key.
Constant for the Diffie Hellman algorithm.
This object specifies the algorithm and bit length for a key.
Barbican secret store plugins should implement the abstract base class SecretStoreBase. Concrete implementations of this class should be exposed to Barbican using stevedore mechanisms explained in the configuration portion of this guide.
Deletes a secret from the secret store.
Deletes a secret from a secret store. It can no longer be referenced after this call.
Parameters: | secret_metadata – secret_metadata |
---|
Generate a new asymmetric key pair and store it.
Generates a new asymmetric key pair and stores it in the secret store. An object of type AsymmetricKeyMetadataDTO will be returned containing attributes of metadata for newly created key pairs. The metadata is stored by Barbican and passed into other methods to aid the plugins. This can be useful for plugins that generate a unique ID in the external data store and use it to retrieve the key pairs in the future.
Parameters: | key_spec – KeySpec that contains details on the type of key to generate |
---|---|
Returns: | An object of type AsymmetricKeyMetadataDTO containing metadata about the key pair. |
Returns a boolean indicating if the secret type is supported.
This checks if the algorithm and bit length are supported by the generate methods. This is useful to call before calling generate_symmetric_key or generate_asymetric_key to see if the key type is supported before trying to generate it.
Parameters: | key_spec – KeySpec that contains details on the algorithm and bit length |
---|---|
Returns: | boolean indicating if the algorithm is supported |
Generate a new symmetric key and store it.
Generates a new symmetric key and stores it in the secret store. A dictionary is returned that contains metadata about the newly created symmetric key. The dictionary of metadata is stored by Barbican and passed into other methods to aid the plugins. This can be useful for plugins that generate a unique ID in the external data store and use it to retrieve the key in the future. The returned dictionary may be empty if the SecretStore does not require it.
Parameters: | key_spec – KeySpec that contains details on the type of key to generate |
---|---|
Returns: | an optional dictionary containing metadata about the key |
Gets user friendly plugin name.
This plugin name is expected to be read from config file. There will be a default defined for plugin name which can be customized in specific deployment if needed.
This name needs to be unique across a deployment.
Retrieves a secret from the secret store.
Retrieves a secret from the secret store and returns a SecretDTO that contains the secret.
The secret_metadata parameter is the metadata returned from one of the generate or store methods. This data is used by the plugins to retrieve the key.
The secret_type parameter may be useful for secret stores to know the expected format of the secret. For instance if the type is SecretDTO.PRIVATE then a PKCS8 structure is returned. This way secret stores do not need to manage the secret type on their own.
Parameters: |
|
---|---|
Returns: | SecretDTO that contains secret |
Gets a transport key.
Returns the current valid transport key associated with this plugin. The transport key is expected to be a base64 encoded x509 certificate containing a public key. Admins are responsible for deleting old keys from the database using the DELETE method on the TransportKey resource.
By default, returns None. Plugins that support transport key wrapping should override this method.
Determines if the provided transport key is the current valid key
Returns true if the transport key is the current valid transport key. If the key is not valid, then barbican core will request a new transport key from the plugin.
Returns False by default. Plugins that support transport key wrapping should override this method.
Stores a key.
The SecretDTO contains the bytes of the secret and properties of the secret. The SecretStore retrieves the secret bytes, stores them, and returns a dictionary of metadata about the secret. This can be useful for plugins that generate a unique ID in the external data store and use it to retrieve the secret in the future. The returned dictionary may be empty if the SecretStore does not require it.
Parameters: | secret_dto – SecretDTO for secret |
---|---|
Returns: | an optional dictionary containing metadata about the secret |
Returns a boolean indicating if the secret can be stored.
Checks if the secret store can store the secret, give the attributes of the secret in the KeySpec. For example, some plugins may need to know the attributes in order to store the secret, but other plugins may be able to store the secret as a blob if no attributes are given.
Parameters: | key_spec – KeySpec for the secret |
---|---|
Returns: | a boolean indicating if the secret can be stored |
The sequence that Barbican invokes methods on SecretStoreBase depends on the requested action as detailed next. Note that these actions are invoked via the barbican.plugin.resources module, which in turn is invoked via Barbican’s API and Worker processes.
For secret storage actions, Barbican core calls the following methods:
For secret retrievals, Barbican core will select the same plugin as was used to store the secret, and then invoke its get_secret() method to return the unencrypted secret.
For symmetric key generation, Barbican core calls the following methods:
For asymmetric key generation, Barbican core calls the following methods:
Barbican core includes a specialized secret store plugin used to adapt to cryptographic plugins, called StoreCryptoAdapterPlugin. This plugin functions as a secret store plugin, but it directs secret related operations to cryptographic plugins for encryption/decryption/generation operations. Because cryptographic plugins do not store encrypted secrets, this adapter plugin provides this storage capability via Barbican’s data store.
This adapter plugin also uses stevedore to access and utilize cryptographic plugins that can support secret operations.