Skip to content

Commit c2bdac4

Browse files
committed
Implement key rotation for ceph-fs (Quincy)
This patchset implements key rotation for the ceph-fs charm by receiving the new pending key from the ceph-mon charm and manually rotating it via Ceph's authtool. It makes use of the 'ceph-mds-relation-changed' hook for this. Change-Id: Ie0a431235fa6d2c74709f9b6c52ce16557990067
1 parent 9682555 commit c2bdac4

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

charmcraft.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ type: charm
22

33
parts:
44
charm:
5+
charm-entrypoint: "hooks/install"
56
build-packages:
67
- tox
78
- git
89
- python3-dev
10+
- libffi-dev
911
override-build: |
1012
apt-get install ca-certificates -y
1113
tox -e build-reactive
@@ -32,8 +34,8 @@ bases:
3234
channel: "22.04"
3335
architectures: [amd64, s390x, ppc64el, arm64]
3436
- name: ubuntu
35-
channel: "22.10"
37+
channel: "23.04"
3638
architectures: [amd64, s390x, ppc64el, arm64]
3739
- name: ubuntu
38-
channel: "23.04"
40+
channel: "23.10"
3941
architectures: [amd64, s390x, ppc64el, arm64]

requirements.txt

+8-11
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88
# requirements.txt
99
setuptools<50.0.0 # https://github.com/pypa/setuptools/commit/04e3df22df840c6bb244e9b27bc56750c44b7c85
1010

11-
# Build requirements
12-
cffi==1.14.6; python_version < '3.6' # cffi 1.15.0 drops support for py35.
13-
charm-tools==2.8.4
11+
# NOTE: newer versions of cryptography require a Rust compiler to build,
12+
# see
13+
# * https://github.com/openstack-charmers/zaza/issues/421
14+
# * https://mail.python.org/pipermail/cryptography-dev/2021-January/001003.html
15+
#
16+
cryptography<3.4
1417

15-
simplejson
18+
git+https://github.com/juju/charm-tools.git
1619

17-
# Newer versions use keywords that didn't exist in python 3.5 yet (e.g.
18-
# "ModuleNotFoundError")
19-
# NOTE(lourot): This might look like a duplication of test-requirements.txt but
20-
# some tox targets use only test-requirements.txt whereas charm-build uses only
21-
# requirements.txt
22-
importlib-metadata<3.0.0; python_version < '3.6'
23-
importlib-resources<3.0.0; python_version < '3.6'
20+
simplejson

src/reactive/ceph_fs.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016 Canonical Ltd
1+
# Copyright 2024 Canonical Ltd
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -23,6 +23,9 @@
2323
import charms_openstack.bus
2424
import charms_openstack.charm as charm
2525

26+
import os
27+
import subprocess
28+
2629

2730
charms_openstack.bus.discover()
2831

@@ -41,6 +44,9 @@
4144
def config_changed():
4245
ceph_mds = reactive.endpoint_from_flag('ceph-mds.pools.available')
4346
with charm.provide_charm_instance() as cephfs_charm:
47+
host = cephfs_charm.hostname
48+
exists = os.path.exists('/var/lib/ceph/mds/ceph-%s/keyring' % host)
49+
4450
cephfs_charm.configure_ceph_keyring(ceph_mds.mds_key())
4551
cephfs_charm.render_with_interfaces([ceph_mds])
4652
if reactive.is_flag_set('config.changed.source'):
@@ -52,6 +58,22 @@ def config_changed():
5258
reactive.set_flag('config.rendered')
5359
cephfs_charm.assess_status()
5460

61+
# If the keyring file existed before this call, then the new
62+
# provided key implies a rotation.
63+
if exists:
64+
svc = 'ceph-mds@%s.service' % host
65+
try:
66+
# Reset the failure count first, as the service may fail
67+
# to come up due to the way the restart-map is handled.
68+
subprocess.check_call(['sudo', 'systemctl',
69+
'reset-failed', svc])
70+
subprocess.check_call(['sudo', 'systemctl', 'restart', svc])
71+
except subprocess.CalledProcessError as exc:
72+
# The service can be temporarily masked when booting, so
73+
# skip that class of errors.
74+
ch_core.hookenv.log('Failed to restart MDS service: %s' %
75+
str(exc))
76+
5577

5678
@reactive.when('ceph-mds.connected')
5779
def storage_ceph_connected(ceph):

0 commit comments

Comments
 (0)