Commit Graph

80 Commits

Author SHA1 Message Date
selcem 8413b3f9ee Add crl-distribution-point to upload-signed-csr action
New configuration parameter updates URI for CRL Distribution points
inside Vault, to a publicly-accessible location. The purpose is not
to impact all users, so I did not add a global configuration
parameter. Instead, only 'upload_signed_csr' action was updated
with an optional parameter introduced named 'crl-distribution-point'.

Closes-bug: #2048237
Change-Id: I8dbfc0deb9f547100bb63bd6b20737734e97667b
2024-01-18 16:11:32 +03:00
Alex Kavanagh d925ac7566 Fix broken v4 caching due to leader-get asymmetry
leader-get decodes using json, but leader-set just sets the keys. This
wasn't taken into consideration when fetching all the keys to filter for
cached keys when a relation is leaving.  This is resolved in this patch.

Change-Id: I2d44ec0c43c1ecffd9ac77a1162ead4e4a01aabe
2023-08-07 11:37:52 +01:00
Martin Kalcok 1a1953b0ef Implement cert cache for vault units (v4)
This cache is used to store certificates and keys
issued by the leader unit. Non-leader units read
these certificates and keep data in their
"tls-certificates" relations up to date.
This ensures that charm units that receive certs
from vault can read from relation data of any
vault unit and receive correct data.

This patch is mostly the same as
I18aa6c9193379ea454851b6f60a8f331ef88a980
but improved to avoid LP#1896542 by removing
the section where a certificate can be reused
from cache during create_certs.

Co-Authored-By: Rodrigo Barbieri <rodrigo.barbieri@canonical.com>
Co-Authored-By: Alex Kavanagh <alex.kavanagh@canonical.com>

func-test-pr: https://github.com/openstack-charmers/zaza-openstack-tests/pull/1084

Closes-Bug: #1940549
Closes-Bug: #1983269
Closes-Bug: #1845961
Related-Bug: #1896542
Change-Id: I0cca13d2042d61ffc6a7c13eccb0ec8c292020c9
2023-07-26 08:54:22 +00:00
Robert Gildein 9e927889d0 Improve snap channel refresh mechanism
- stop vault.service before refresing it
- added a warning note that changing the channel config option will
  cause the vault to be sealed

Related-Bug: 2007587
Change-Id: I240ebb4bd14932a6bf95f41da3f2cd7776742266
2023-06-22 17:13:30 +02:00
Zuul e86e6dd493 Merge "Revert "Implement cert cache for vault units (v3)"" 2023-04-18 02:04:15 +00:00
Alex Kavanagh 38e00f460d Revert "Implement cert cache for vault units (v3)"
This reverts commit 04a237660b.

Reason for revert:

The bug in [1] caused all the yoga tests to fail in integration testing.  Testing with a version of the charm without this commit allowed tests to complete.  Thus reverting this until a more complete solution can be found to the original bug(s) [2..4]

[1] https://bugs.launchpad.net/charm-keystone/+bug/2015103
[2] LP #1940549
[3] LP #1983269
[4] LP #1845961

Change-Id: I8a794fbb30e921e5322e9023b891d5e17e0e6e8b
2023-04-14 18:03:42 +00:00
Liam Young 457a51377d Add `force` flag to get-csr
As bug/1947265 notes running the get-csr actions can result in the
CA being wiped from the leader DB. This change attempts to make
it more clear to the user that this action be destructive.

* Deprecate the `get-csr` action and replace it with
  `regenerate-intermediate-ca`. They are functionally equivalent but
  the new name makes it clearer that the CA may be destroyed.

* Adds `force` option to the action. The force action must be used
  if a CA already exists.

* The functional test of rerunning the `regenerate-intermediate-ca`
  action is now included in the vault tests so no need to run the
  tests twice now.

Func-Test-PR: https://github.com/openstack-charmers/zaza-openstack-tests/pull/974
Change-Id: Ie01dd7ec0e9134689518b37b5d70c8dd5a556241
Closes-Bug: #1947265
2023-02-23 12:43:12 +00:00
Zuul 15ab73ea72 Merge "Implement cert cache for vault units (v3)" 2023-01-23 11:13:22 +00:00
Andreas Hamacher 1ea06f6819 ssl certificate expiery check added to nagios relation
see https://bugs.launchpad.net/vault-charm/+bug/1998174

Change-Id: Ie56cd9b49f13bd2cd323c440a0e1a7f6d7d499b2
2023-01-18 11:07:39 +11:00
Martin Kalcok 04a237660b Implement cert cache for vault units (v3)
This cache is used to store certificates and keys
issued by the leader unit. Non-leader units read
these certificates and keep data in their
"tls-certificates" relations up to date.
This ensures that charm units that receive certs
from vault can read from relation data of any
vault unit and receive correct data.

This patch is mostly the same as
f55055b878
but improved to avoid LP#1983269 by breaking
down the cert cache into separate key-value pairs
for each remote unit and avoiding a race-condition
caused by get-csr action. Instead of using
leader-settings, this patch is now using
application data bag provided by a new vault-ha
relation implementation.

Co-Authored-By: Rodrigo Barbieri <rodrigo.barbieri@canonical.com>

Change-Id: I18aa6c9193379ea454851b6f60a8f331ef88a980
Closes-Bug: #1940549
Closes-Bug: #1983269
Closes-Bug: #1845961
2023-01-12 11:51:12 -03:00
Samuel Walladge 61fdf9ca77 Add embedded raft cluster storage support
Add support for using the embedded raft storage and ha storage engine,
and related management actions and config.

Closes-Bug: #1883242

func-test-pr: https://github.com/openstack-charmers/zaza-openstack-tests/pull/827

Change-Id: I66a9315844ddb67d43e3e1c002073ed315b3b851
2022-08-10 15:20:11 +09:30
Alex Kavanagh 9bf2a4cb3c Revert "Implement cert cache for vault units (v2)"
This reverts commit f55055b878.

Reason for revert:

This patch breaks when issuing many certificates in large models due to CLI leader-set being overwhelmed: https://bugs.launchpad.net/vault-charm/+bug/1983269

Change-Id: I4854839b5278d1b4db325e44b78b1815b2751728
2022-08-01 18:08:35 +01:00
Samuel Walladge 212d2a7dba Fix use of get_chain
A recent change[1] switched to the newer methods in
hvac 11.2, but unfortunately the semantics between
client.secrets.pki.read_certificate() and client.read() are different,
in that the latter returns None on InvalidPath, whereas the former
allow the exception to bubble up.

This means that for the call sites here, we need to catch InvalidPath,
instead of the TypeError.
The original reason for TypeError was that the function
would end up calling None['key'] if read_certificate failed.

[1]: https://review.opendev.org/c/openstack/charm-vault/+/848205

Change-Id: I46b93457c8a757189802ca2c2cdf31cc9c5a9516
2022-07-28 10:41:32 +09:30
Alex Kavanagh ee3271063d Fix to is_ca_ready() which used read_role() incorrectly
A recent change (1) switched to the newer methods in
hvac 11.2, but unfortunately the semantics between
client.secrets.pki.read_role() and client.read() are different,
in that the latter returns None on InvalidPath, whereas the former
allow the exception to bubble up.

Also updates tests and fixes a mocking issue on service_reload.

[1] https://review.opendev.org/c/openstack/charm-vault/+/848205

Change-Id: Id3d112104b1aa45b242e402709fb855131d5203e
2022-07-14 12:38:18 +01:00
Samuel Walladge 68fecd9ba8 Update hvac library to latest version
Update deprecated method calls where possible,
and use new methods instead of lower level read/write calls.

Change-Id: I991435cdf8d36016e75c46823ec47f3290a42fe4
2022-07-04 09:34:33 +09:30
Martin Kalcok f55055b878 Implement cert cache for vault units (v2)
This cache is used to store certificates and keys
issued by the leader unit. Non-leader units read
these certificates and keep data in their
"tls-certificates" relations up to date.
This ensures that charm units that receive certs
from vault can read from relation data of any
vault unit and receive correct data.

This patch is the same as
1159e547dd
but improved to avoid LP#1970888

Change-Id: Ic4dd009cc18c52e1667391b00ebba9928acc5937
Closes-Bug: #1940549
Closes-Bug: #1970888
2022-05-09 17:35:44 +02:00
gnuoy 1956b5e680 Revert "Implement cert cache for vault units."
This reverts commit 1159e547dd.

Reason for revert: https://bugs.launchpad.net/vault-charm/+bug/1970888

Change-Id: I1770ea46c39f7f20f5d88d5aa65109d8b48740d2
2022-04-29 08:19:02 +00:00
Martin Kalcok 1159e547dd Implement cert cache for vault units.
This cache is used to store certificates and keys
issued by the leader unit. Non-leader units read
these certificates and keep data in their
"tls-certificates" relations up to date.
This ensures that charm units that receive certs
from vault can read from relation data of any
vault unit and receive correct data.

Closes-Bug: #1940549
Change-Id: Iac989b30948fa43fe23851995a8ed00b08126587
2022-04-08 15:05:21 +02:00
Jeff Hillman d8bfff76e4 Add action to generate certificate against the PKI.
Created action to utilize the existing
generate_certificate function for on demand
certificates agains the existing vault PKI.

Closes-Bug: #1948837
Change-Id: Ia1a169623c81d6aede7dc52eabd2de94007fde80
2022-02-23 11:10:42 -06:00
Zuul 485d41dd38 Merge "Use unittest.mock instead of mock" 2021-12-16 10:26:17 +00:00
Hervé Beraud 1de27bc18f Use unittest.mock instead of mock
The mock third party library was needed for mock support in py2
runtimes. Since we now only support py36 and later, we can use the
standard lib unittest.mock module instead.

Note that https://github.com/openstack/charms.openstack is used during tests
and he need `mock`, unfortunatelly it doesn't declare `mock` in its
requirements so it retrieve mock from other charm project (cross dependency).
So we depend on charms.openstack first and when
Ib1ed5b598a52375e29e247db9ab4786df5b6d142 will be merged then CI
will pass without errors.

Depends-On: Ib1ed5b598a52375e29e247db9ab4786df5b6d142
Change-Id: I1d7de2bd4d704ffc331fdeacea725e903890f296
2021-12-15 11:38:28 +00:00
Felipe Reyes 2b115c8d48 Register previous vip set for deletion.
When the vip is changed the ones that are no longer present need to be
registered for deletion from pacemaker's configuration. This change
relies on hookenv.config.changed() to determine what vip(s) are no
longer present in the configuration ask hacluster to remove them.

Closes-Bug: #1952363
Change-Id: I7b77cd4f57e1770faf92860ee7846bf480efdb9e
2021-11-29 20:49:16 -03:00
Zuul 0a03b2b36d Merge "Surround IPv6 addresses with []" 2021-11-23 21:28:54 +00:00
Andy Wu 5151d01ee2 Report 'Missing CA' if certs relation exist but CA not configured
If vault/leader has certificate relationship with other apps but
root CA is either not configured or cleared by action 'disable-pki',
the status should be set to 'Blocked, Missing CA'

Also add unit test for checking 'missing-CA' status

Closes-Bug: #1940451
Change-Id: I2f0093c0ae6949693f2ad1ea4729b690c932b4b1
2021-11-05 13:40:22 +00:00
Simon Deziel 3742fcbc32 Surround IPv6 addresses with []
Fix typo in tests (s/exmaple/example/g) and add IPv4 and
IPv6 tests URLs.

Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Change-Id: I283f88069371d661535f675cc046b04aec2f3f99
2021-11-04 08:54:58 -04:00
Cory Johns 426e68f873 Report when Vault service needs to be restarted for HA
Vault can act as the CA for etcd to allow it to operate in HA mode by
the leader first being unsealed in non-HA mode and providing the root CA
certificate, which allows it to provide a certificate to etcd. However,
at that point, the Vault service needs to be restarted and unsealed
again in order to pick up the HA configuration. Currenty, the status
just reports Vault as ready, potentially with multiple "active" units.
This change detects when the Vault service should be restarted to pick
up the HA configuration and reports it via status.

Change-Id: I40e813b1df4ab3b3301881385a5d713524698821
2021-04-02 14:54:02 -04:00
Cory Johns 0d32b7b320 Fix missing root CA status for non-leader
Follow-on from fix for missing root CA status which didn't properly
account for the non-leader when HA.

Change-Id: I405937ac60541cd008b7bbd01b3c9cdaf2ed88a8
2021-03-29 17:58:29 -04:00
Cory Johns 7f4c95b5b4 Add support for loadbalancer interface
This adds support for the new loadbalancer interface which is intended
to allow for load balancer / ingress endpoint providers, such as the
cloud integrator charms, to provide a load balancer address upon
request. The initial use-case for this is using Vault in Azure, where it
is difficult or impossible to use a VIP or floating IP type approach for
HA Vault; instead, this will allow a relation to the azure-integrator
charm which will provide a native Azure LB which Vault can then
advertise.

Change-Id: I5e0738429d47625c23bfe71c86df6266a3ea364b
2021-03-23 14:49:55 -04:00
Cory Johns 8923bc9f86 Report missing CA if cert requests are pending
This sets the charm status to blocked to make it obvious when the CA
cert is missing and there are pending cert requests being blocked.

This also moves the optional interfaces checks down to ensure that they
don't mask the more important status messages.  (E.g., if Vault is
providing certs for Etcd, it's more important to know that Vault is
sealed or missing the CA than to know that Etcd doesn't have its cert
yet.)

This also adds some error checking to gracefully handle the case where
Vault becomes sealed after it was successfully started rather than
having it go into a hook error.

Change-Id: I18a5dbeabc562e14d164f82c041fed207032f52b
Closes-Bug: 1840696
2021-03-18 14:45:24 -04:00
David Ames af60645555 Handle when allowed_units is None
If for any reason the mysql relation is not ready, the
mysql.allowed_units call would return None. Leading to the error:
"argument of type 'NoneType' is not iterable".

Handle when mysql.allowed_units returns None.

Closes-Bug: #1894123
Change-Id: Ia764f6d95adb87726813d40fab0e1642d35bb27f
2020-12-08 11:37:42 -08:00
Hemanth Nakkina ca32e36ad0 Update status message if new version of vault is installed
As part of snap auto-updates, new versions of vault get installed when
available. But manual intervention is required to restart the vault
service. This patch updates the status message to inform the same to
the user.

Closes-Bug: #1895577

Change-Id: I995069bc151c1db5061c52b9d89d014be6b6a556
2020-09-29 17:11:59 +05:30
David Ames 3e48efe85b Do not check app role auth until ready
The client_approle_authorized was checking for app role authorization
too early before the charm had been authorized by the authorize-charm
action.

Before checking on app role authorization verify the leader setting,
"local-charm-access-id",  set by the authorize-charm action.

Closes-Bug: #1889654
Change-Id: I53f2c357c06a5ac9846718654d35c9baa576cafd
2020-08-03 14:44:56 -07:00
Zuul 56ad2e6c5e Merge "Enable MySQL DB TLS Communication" 2020-07-03 05:57:01 +00:00
Zuul ce8070a73f Merge "Allow for temporary loss of the DB" 2020-07-03 05:56:36 +00:00
David Ames b989a4130a Enable MySQL DB TLS Communication
Change-Id: I626493c099b15b3ee7a3bef8d76e408193f60cba
2020-07-02 13:58:56 -07:00
David Ames 25ac2cb0de Allow for temporary loss of the DB
MySQL topology changes, pause/resumes or even rolling restarts
can put the vault charm into an error state unnecessarily.

* Make the vault charm more robust to temporary MySQL unavailability.
* Make the workload status indicate to the end user when this occurs.

Closes-Bug: #1886083
Change-Id: I57ce8b7d3f778fb87ab01170db1b3770ad84badf
2020-07-02 13:12:06 -07:00
Jeff Hillman 7916e44f1c Add CN and L options to get-csr action
Add the common_name and locality option(s) for when creating
new Certificate Signing Requests.

Closes-Bug: 1882599

Change-Id: I1900b942ed6a409252b35c539c70226c32ed53e3
2020-06-10 16:50:26 -05:00
David Ames 3f94a10cbf If VIP is set, wait until ha.available
The charm was sending an individual unit's address even when the VIP
configuration value was set. If VIP is set and we have not yet reached
the ha.available state, wait on publishing the vault url.

Change-Id: I3de05b5e771dc4b7c43996d99ccc4b5d8668737d
Closes-Bug: #1878035
2020-05-18 12:04:36 -07:00
Sahid Orentino Ferdjaoui 191c9bc5f3 handler: check for service running
Change-Id: I8bcde949a9cfec0094d7fde7af5ed2c956106ea9
Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@canonical.com>
2019-11-28 16:44:17 +00:00
Sahid Orentino Ferdjaoui b0ba16efd1 handler: avoid to tune backend pki when service is pause/sealed
Change-Id: I0e59655446c3d76ba290d8a9e53c897890b99929
Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@canonical.com>
2019-11-28 15:23:51 +00:00
Sahid Orentino Ferdjaoui c982239239 handler: fix publish_ca_info when unit is paused
If the service is paused we should pass on executing this function.

Change-Id: Iab86101a6b9bf2647ea852c01bb47bee47661c4f
Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@canonical.com>
2019-11-28 15:23:50 +00:00
Zuul 45890b14d0 Merge "Make cert and ca cert ttl configurable" 2019-11-19 23:34:59 +00:00
Seyeong Kim 5f233696a4 Make cert and ca cert ttl configurable
Currently the default ttl for a cert is not configurable
and defaults to one month. This patch makes the ttl
configurable and updates the default for new and
re-generated certs to 1 year and 10 years for the CA
cert.

Closes-Bug: #1841138

Change-Id: Iaa6709c74d64c4191b44b92d4cfb3a3dbbb3fdc8
2019-11-19 13:24:19 -03:00
Sahid Orentino Ferdjaoui fb166e451e handler: correctly handle vault sealed exception
In situation where the vault service is restarted the service should
be unsealed. It apears that some parts of the code do not handle the
exception correctly which results the unit to be in an error state.

In the code to handle that we check whether the service is well
unsealed. If that not the case juju will report the service as blocked
asking user to unseal it.

Change-Id: I1b4d83eb4c944a98a06cc457f51d0fb9d0b9a6ce
Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@canonical.com>
2019-11-12 11:16:39 +00:00
Edward Hope-Morley c7e2c531ec Add support for multiple client spaces
Some users may not want to expose all vault clients
to the same networks. In particular they might want
to have some on the default access network and some
on an external network. This patch adds support for
new 'external' binding which clients can use to
talk to the vault api.

Change-Id: I0d393c71dcb127b14b8ffcacbd03bbf68f81a53b
Closes-Bug: #1826892
2019-07-18 11:13:14 +01:00
Nicolas Pochet 8b99dc2829
Add hostname as a new config option
Without this option, the charm announces its API URL with the VIP
address. It is problematic when using FQDN in the SAN section of the
certificates and not IP addresses.

Change-Id: Id40f7f3d70c1e9b055bd0ed65c1c9a90c95f84c1
Closes-Bug: 1826225
2019-05-03 08:23:59 +02:00
James Page e4411326d8 Move interface assessement earlier in assess status
Ensure that interface state is assessed early in the assess_status
function so that missing or incomplete interfaces are detected
correctly, rather than the units just reporting a blocked status.

Change-Id: I9989c708a6385c728fa1fa9cff955efd70854774
Closes-Bug: 1811617
2019-02-22 09:31:51 +00:00
Cory Johns 102b222fce Improve Vault startup handling
The `@when_file_changed` decorator is not considered reliable.
Additionally, the way it was being used led to a race condition where
the Vault service might never get started. This also detects and reports
in a better way if Vault fails to start.

Change-Id: If6153377cd516ed8121e09da627905036128a6ec
2019-02-16 19:21:14 -05:00
James Page 6f043bb7ca Correct key name for PKI backend TTL
Switch max-lease-ttl -> max_lease_ttl inline with Vault API
docs to ensure that certs can be issued for more than 30 days.

Existing deployments with PKI enabled will be re-tuned to
set max_lease_ttl to 10 years, correcting any existing PKI
enablement.

Certificates must be re-issued to use the TTL as provided
during upload of the signed CSR for an Intermediate certificate.

For deploys using the internally signed Root CA, the root
CA must be re-generated using the 'disable-pki' and
'generate-root-ca' actions.

Change-Id: I6a771090e320404c605d2170c7915c3c22a3ea2c
Closes-Bug: 1788945
2019-01-18 09:37:56 +02:00
James Page b5afdc3817 vault-kv: Add functional test and use KV v1
Add ceph-mon and ceph-osd charms to smoke testing bundle
to ensure coverage of vault-kv relation and associated
secrets storage functionality.

Revert default KV backend to v1; v2 has a slightly different
API so revert default KV backend version to v1.

This resolve and issue with vaultlocker access to stored
keys.

Also pin hvac version to < 0.7.0.

Change-Id: I8ed197aba3f9a42399fd4304b21e2a36e3dd6dca
2018-11-13 17:16:54 +00:00