charm-keystone/scripts/fernet_rotate_and_sync.py
Alex Kavanagh c7e34558c4 Make Fernet key distribution more robust
The related bug indicated that the Fernet keys could get out of sync
between the leader and non-leader units.  This patchset assumes that
hooks fail, or that units are off-line when the rotation occurs.  Thus
it tries hard to ensure that the keys are in sync.  It still uses juju
to 'send' the keys from the leader to the subordinate units, so in that
sense, it is not a fix to the related bug, but it does make it more
robust.

Change-Id: Id40a3ccbe565bd742e3fdbd5190deb6b21204a82
Related-Bug: #1849519
2020-11-17 15:24:49 +00:00

50 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright 2018 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import os
import sys
import time
dir_path = os.path.dirname(os.path.realpath(__file__))
hooks_path = os.path.abspath(os.path.join(dir_path, "..", "hooks"))
root_path = os.path.abspath(os.path.join(dir_path, ".."))
for p in [hooks_path, root_path]:
if p not in sys.path:
sys.path.append(p)
# now we can import charm related items
import charmhelpers.core.hookenv
import keystone_utils
def cli_log(msg, level=charmhelpers.core.hookenv.INFO):
"""Helper function to write log message to stdout/stderr for CLI usage."""
if level == charmhelpers.core.hookenv.DEBUG:
return charmhelpers.core.hookenv.log(msg, level=level)
elif level in [charmhelpers.core.hookenv.ERROR,
charmhelpers.core.hookenv.WARNING]:
output = sys.stderr
else:
output = sys.stdout
print('{}: {}'.format(time.ctime(), msg), file=output)
if __name__ == "__main__":
keystone_utils.handle_fernet_keys_cron_call(log_func=cli_log)