Commit Graph

164 Commits

Author SHA1 Message Date
melanie witt 4925356be6 Raise ManagedObjectNotFoundError in MockKeyManager
Currently the MockKeyManager raises KeyError when a key is not found
for a get() or delete() but a real key manager raises
ManagedObjectNotFoundError in the case of not found [1][2].

This updates the MockKeyManager to raise the same exception as a real
key manager so that projects using it in tests will be able to test
their handling of "not found" scenarios properly.

[1] a662b30764/castellan/key_manager/barbican_key_manager.py (L617)
[2] a662b30764/castellan/key_manager/barbican_key_manager.py (L644)

Change-Id: I3184a229f6690854dda1edc12e74bb483b47a057
2024-02-26 08:34:28 +00:00
Takashi Kajinami 291ad9c778 Bump hacking
hacking 3.0.x is too old.

Change-Id: Ic6d33295b33cff8a68fbb8181973480bc17e7711
2024-02-02 01:50:46 +09:00
Zuul 31c77b4542 Merge "Add force parameter functional tests" 2023-02-17 15:12:20 +00:00
Zuul 9efc3e51e9 Merge "Add secret consumers functional tests" 2023-02-17 14:49:39 +00:00
Zuul a2c3d54c82 Merge "Implement force parameter" 2023-02-17 12:51:26 +00:00
Mauricio Harley 7de4f89f02 Add force parameter functional tests
Change-Id: I37036867297ae5e6f95191154c71d25ac9eda796
2023-02-17 13:26:27 +01:00
Zuul 300c60ca97 Merge "Add support for specifying Vault KV path" 2023-02-17 12:23:38 +00:00
Mauricio Harley e65ac5e439 Add secret consumers functional tests
This adds secret consumers functional tests
to use with Barbican.

Change-Id: I23e71e534d94e753c3e94154f39ec04219ab0fa6
2023-02-17 11:11:26 +01:00
Grzegorz Grasza 96027e9cff Implement force parameter
This change adds the force parameter to the secret delete
method. By default, a secret cannot be deleted if it
contains consumers.

This code cannot be merged without a corresponding release and
bump of version for the barbicanclient.

Co-Authored-By: Mauricio Harley <mharley@redhat.com>
Change-Id: I84fd870b1cd19975a5bb832ed6fd6d18ec56eb5a
2023-02-17 10:00:07 +00:00
Grzegorz Grasza bc6d87b969 Add secret consumers
This change adds the ability to add or remove consumers to a
managed object to allow services to indicate which object is
associated with a specific secret.  At this time, only barbican
supports consumers.

This code cannot be merged without a corresponding release and
bump of version for the barbicanclient.

Co-Authored-By: Mauricio Harley <mharley@redhat.com>
Depends-On: https://review.opendev.org/c/openstack/requirements/+/873906
Change-Id: Ic25ac329f87db5992e32ef0b2d7d4020f37b2dee
2023-02-16 13:45:16 +01:00
Grzegorz Grasza fe10397ac0 Initial change to add secret consumers
This adds consumers to the objects. Unit tests are
also covered.

Co-Authored-By: Ade Lee <alee@redhat.com>
Co-Authored-By: Mauricio Harley <mharley@redhat.com>
Change-Id: I598209e30d8f0e4515292b1f8c9a89aa952bac4e
2023-01-27 13:11:05 +01:00
Scott Solkhon 370986e96e Add support for specifying Vault KV path
This commit adds support for a Vault path that is relative to
the root of the Vault KV store. This configuration is optional
and will be a noop for existing deployments.

Change-Id: If34c38c8f0a2f13ea90f564bfe5e933e5e748da4
2023-01-16 20:47:07 +00:00
Ade Lee 316db6cb53 Make tests more consistent
Tests periodically fail right now because the cleanup which is
running in a different thread sometimes removes the managed objects
before we have completed testing with them.  The change to use
concurrency=1 will slow down the tests, but also make them more
consistent.

Also, when things are not cleaned up, you can get false positive
results if multiple objects contain the same content.  This will
fix this problem by making the contents unique.

Change-Id: Ic2b9e6afe9371dbe135e90fa6df36a8e91921556
2022-09-21 16:27:54 +02:00
Takashi Kajinami d2e8437208 Remove redundant override of logging_context_format_string
The target value is exactly same as the default defined in oslo.log,
thus this override is just redundant.

Change-Id: I91fcc035526d655f0b885f5b6a176dc18577a3a3
2022-04-16 00:42:55 +09:00
Joel Capitao a160e5c8dc Replace the deprecated argument tenant
The deprecated argument tenant from RequestContext
has been removed since [1], so we switch to 'project_id'.

[1] https://review.opendev.org/c/openstack/oslo.context/+/815938

Change-Id: I4e3e4c50ba5d829ed739e278b5286f2bf4808870
2022-03-15 08:36:02 +01:00
LiZekun 86712360f3 remove unicode from code
Change-Id: I086d90b6f46e31582d412b8725e48cba5c21d6bc
2022-01-05 10:44:00 +08:00
Lingxian Kong 4b6f73a671 Support setting Vault kv version config
Change-Id: If1e244c808eeb5303b6b29d723cd60cdb66e6e86
2021-10-13 10:20:20 +13:00
Pavlo Shchelokovskyy ecf625b65c Add support for Vault Namespaces
Vault Namespaces [0] is a feature available in Vault Enterprise that
can be considered as a more advanced isolation feature on top of current
KV Mountpoint option in Castellan Vault plugin.

Passing a namespace in all request headers (including Auth) allows to organize
Vault-in-Vault style of isolation, with clients using the same simple URI path
but accessing separate sets of entities in Vault.

[0] https://www.vaultproject.io/docs/enterprise/namespaces

Change-Id: I627c20002bb2a0a1b346b57e824f87f856eca4c9
2021-10-07 12:12:51 +00:00
Mark Goddard 162039467a barbican key manager: Add support for service user
This change adds support to the Barbican key manager for configuring a
service user. This can be used to provide additional security through
the combination of a user token and a service token, with appropriate
modifications to Barbican API policy.

Use of a service user is enabled via the [barbican]
send_service_user_token option, which defaults to False. When set to
True, the service user is configured via keystoneauth options in the
barbican_service_user group.

Change-Id: I143cb57c8534a8dc0a91e6e42917dd0c134170c0
2021-06-21 12:48:03 +00:00
Zuul f8b79a2b66 Merge "Simplify the reference to barbican parameters" 2021-03-30 18:54:00 +00:00
Zuul 984ebb2bf8 Merge "Allow specifying region of barbican endpoint" 2021-03-30 17:21:40 +00:00
Takashi Kajinami bfcf4b2f69 Simplify the reference to barbican parameters
... so that we can easily identify the logics which are referring to
configuration parameters.

Change-Id: I93427a64b83f474c7c2dd45c8c200e7a3c9bc6f9
2021-02-03 23:31:56 +09:00
Takashi Kajinami 8c48341169 Allow specifying region of barbican endpoint
This change introduces a new option to define the region to which
the Barbican endpoint belongs. This is required if the deployment has
multiple regions and a single Keystone instance stores multiple
Barbican endpoints for different regions.
This change also ensures that the same interface and region are used
in endpoint detection and api version detection.

Change-Id: If2c0055d45922937e259a8f22f5879c9faa41e35
2021-02-03 12:11:09 +00:00
Mark Goddard 35f1a20d51 Fix assertion typo in barbican key manager unit test
Change-Id: Ibd761519cb6ef2ee27aebe2b02c80c8c5c0b7ca4
2021-01-21 17:45:43 +00:00
Sam Morrison 4a4544b8ec Don't expect barbican service name to be barbican.
It is standard practice to search for services in the catalog by
service type and interface only. Service name should be left
to deployers to choose and this could be something other than barbican.

Change-Id: I9dddba1e52bbf1ee1d8227fdb45e625fdbf0a21b
2020-12-01 13:54:37 +11:00
Ivan Kolodyazhny e63d813a70 Use 'barbican_endpoint_type'config option to get endpoint from catalog
_get_barbican_endpoint now uses barbican_endpoint_type config option to
retrieve a correct endpoint from catalog.

This config option is set to 'public' by default and it's a default
value for ServiceCatalog.endpoint_data_for method. It means that the
default behaviour will be the same as before this patch.

Change-Id: Idf4061fe3e35e3c47a993a56b23c0257c92e5cc3
2020-07-31 21:48:42 +00:00
Moisés Guimarães de Medeiros 883e9603fa Add to_dict and from_dict conversions to managed objects
This patch centralizes the managed objects conversion in order to be
used across multiple key_manager backends.

Change-Id: Ia2e15d46eb2e504b815a7f51173aecaf82978402
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2020-07-13 13:44:22 +02:00
Moisés Guimarães de Medeiros 68c1eb50a0 Replaces _get_api_version with config option
This patch fixes the issue when guessing the KV API version fails.
From now on, a configuration option should be used to set vault's API
version.

Change-Id: I962b29519c189dddf9723689e6aaeed2cac3ff2c
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2020-06-22 17:00:15 +02:00
Ivan Kolodyazhny 59f9380c32 Add handler for Bad Request error during Vault authentication
Vault returns Bad Request error if invalid secret ID is provided. It's
better to have such errors handled instad of generic "KeyError: 'auth'"
execption.

Change-Id: Ibc068af70de4022f544d394ec4b014443a9c16b5
2020-06-12 12:51:57 +00:00
Zuul 9a9bf2e48c Merge "Use unittest.mock instead of third party mock" 2020-05-25 14:23:04 +00:00
ramboman 89f311dfbd add "verify_ssl_path" config for barbican key manager
Now we cann't use the verify_ssl if we set True, so we
add the "verify_ssl_path" config to solve it.

Closes-Bug: #1876102
Change-Id: I83bafe5b7e0c4cca67f773858007fb59d98a93a5
2020-05-06 21:31:27 +08:00
Sean McGinnis 27cf110749
Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: Ib3028d55552ef51d93aaf38653bca888166e6d27
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-18 11:52:10 -05:00
Zuul 2ae27479f8 Merge "Update hacking for Python3" 2020-04-14 13:21:01 +00:00
Douglas Mendizábal f8bcee0d90 Fix stale references to renamed constant
Change-Id: I5d2bda5e653ee5d7c17cb7697247802916bdc5f7
2020-04-09 14:16:23 -05:00
Andreas Jaeger a1718bb95a Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Fix problems found by updated hacking version.

Change-Id: I4f24c0fa5178f15912db899fcf26ca11480eab21
2020-03-31 13:08:37 +00:00
Moisés Guimarães de Medeiros 8e88919f02 Removes context "validation".
The Vault backend doesn't really care about context. Even an empty
string would suffice these checks.

Change-Id: I1c0d00675a479cf05d92cec7b69fd720a88023d3
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2020-03-09 16:06:55 +01:00
Moisés Guimarães de Medeiros fd01ccc0f5 Moving common objects under KeyManager.
Both Barbican and Vault backends have this replicated code. Let's
centralize it to reduce code duplication.

Change-Id: I365a6d3031695ee369664c00a61816c77792f2e2
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2020-03-09 16:06:55 +01:00
Moisés Guimarães de Medeiros 3ccf918c98 Drop use of six
nit: Certificate inherits from ManagedObject which already has
ABCMeta as metaclass.

Change-Id: I17b12980b88e306fbdc99a3e92b1fa22d8e96471
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2020-03-09 11:14:16 +01:00
Moisés Guimarães de Medeiros 943150ee51 Implements KeyManager's option discovery.
The KeyManager itself should be responsible for advertising the
correct set of options for discovery, not relying on the global
option listing method to know which variable holds the options
and how are they grouped.

Change-Id: I1764c383206df835b7d654f2f776663bd6d4d25b
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2020-02-21 16:33:17 +01:00
Eric Harney fcb39e5d9d Fix "is" usage with literals
This throws warnings on Python 3.8.

Change-Id: I82625d6d202b33daaa2e7f02fbfb8dc5ab59079c
2019-11-12 12:07:12 -05:00
Vladislav Kuzmin 5d93676338 Reuse existing token from RequestContext
When castellan trying to recreate trust-scoped token
from RequestContext keystone throw exception
because it's not allowed.
Starting from this commit castellan trying to
reuse existing token constructed from RequestContext
if get_auth_plugin() is available.

Change-Id: I10a12b9a2a7f796eca37dd20a280d3a4015a6903
Closes-Bug: #1827047
Depends-On: https://review.opendev.org/#/c/664558/
2019-06-13 15:44:44 +04:00
Moisés Guimarães de Medeiros 9ecd30081a Fix length usage in VaultKeyManager.create_key.
Previous code was considering length as bytes, but the API contract
considers the length param to be bits so that the considering `km`
as a VaultKeyManager, the call `km.create_key(ctx, 'AES', 256)` should
generate a 256 bit AES key and not a 2048 bit AES key instead.

Closes-Bug: #1817248
Change-Id: I5815cb74394e18b6058f4c5cf69b656d7cc2c43b
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2019-02-22 15:46:35 +01:00
Zuul 62a078c261 Merge "vault: support configuration of KV mountpoint" 2019-01-24 12:07:05 +00:00
Zuul 3b2d2e3b13 Merge "vault: add AppRole support" 2019-01-23 22:16:17 +00:00
Moises Guimaraes de Medeiros 6e03a68c14 Add Castellan Oslo Config Driver.
This driver is an oslo.config backend driver implemented with
Castellan. It extends oslo.config's capabilities by enabling it
to retrieve configuration values from a secret manager behind
Castellan.

Change-Id: Id7cf99bea5788e0a6309461a75eaa8d08d29641b
Signed-off-by: Moises Guimaraes de Medeiros <moguimar@redhat.com>
2019-01-09 23:17:17 +01:00
James Page afb539f748 vault: support configuration of KV mountpoint
Support end user configuration of KV store in Vault to use for
key storage allowing more flexibility in Vault configuration.

Change-Id: I625a819c2b9b542677258de709a9c520fb86858b
Closes-Bug: 1797148
2018-10-12 10:05:50 +01:00
James Page bc7f7a4c36 vault: add AppRole support
Add support for use of AppRole's for authentication to Vault; this
feature provides a more application centric approach to managing
long term access to Vault.

The functional tests exercise this integration with a restricted
policy which only allows access to the default 'secret' backend.

Change-Id: I59dfe31adb72712c53d49f66d9ac894e43e8bbad
Closes-Bug: 1796851
2018-10-12 10:03:21 +01:00
Moises Guimaraes de Medeiros 6510f8639a Add method to wrap HashiCorp Vault HTTP API calls.
The new method handles the HTTP request for the Vault HTTP API
and does the error checking in a single place. The same code
was already in four different places in the same file.

Change-Id: I4b688d8cf994fb26f88570840523fcc0ac24faba
Signed-off-by: Moises Guimaraes de Medeiros <moguimar@redhat.com>
2018-08-28 08:33:01 +02:00
Moises Guimaraes de Medeiros 2d5be1ade4 Fix Vault K/V API compatibility.
Starting from version 0.10.0, HashiCorp Vault has a different
API for the Key/Value Secrets Engine. This fix implements both
the new API support and the fallback for the legacy one.

Fixes https://bugs.launchpad.net/castellan/+bug/1788375

Change-Id: I7fed7b5091440dae15551d83f0ee0895651e47bf
Signed-off-by: Moises Guimaraes de Medeiros <moguimar@redhat.com>
2018-08-22 16:04:11 +02:00
Ade Lee 55026461d2 Add code to generate private keys
Change-Id: I05d0cb71406769ebf8ccbd63644ae27a4da6d405
2018-07-04 13:31:32 -04:00