diff options
| author | Zuul <zuul@review.opendev.org> | 2024-08-21 17:18:55 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2024-08-21 17:18:55 +0000 |
| commit | 8f6bc332bfe84275836c9153ebab6902041ca83a (patch) | |
| tree | 2fd7ddee5f11dd0a8fc991ac4881657e72d283f6 | |
| parent | fe1aefd67fb554de81a1ba2d66c33645483fcf79 (diff) | |
| parent | 07d0b12efdbaaf38d41670d67a2ba47ac9ded1e4 (diff) | |
| download | kolla-8f6bc332bfe84275836c9153ebab6902041ca83a.tar.gz kolla-8f6bc332bfe84275836c9153ebab6902041ca83a.zip | |
Merge "Add exclude for permissions in kolla config.json file"
| -rw-r--r-- | doc/source/admin/kolla_api.rst | 6 | ||||
| -rw-r--r-- | docker/base/set_configs.py | 16 | ||||
| -rw-r--r-- | releasenotes/notes/permissions-exclude-e1138abb573956a7.yaml | 5 |
3 files changed, 24 insertions, 3 deletions
diff --git a/doc/source/admin/kolla_api.rst b/doc/source/admin/kolla_api.rst index 74dc58d79..aea5b81b0 100644 --- a/doc/source/admin/kolla_api.rst +++ b/doc/source/admin/kolla_api.rst @@ -65,6 +65,9 @@ The `kolla_set_configs`_ script understands the following attributes: Must be passed in the numeric octal form. * **recurse**: whether to apply the change recursively over the target directory. Boolean, defaults to ``false``. + * **exclude**: array of names of the directories or files to be excluded when + ``recurse`` is set to ``true``. Supports Python regular expressions. + Defaults to empty array. Here is an example configuration file: @@ -85,7 +88,8 @@ Here is an example configuration file: { "path": "/var/log/kolla/trove", "owner": "trove:trove", - "recurse": true + "recurse": true, + "exclude": ["/var/log/^snapshot.*"] } ] } diff --git a/docker/base/set_configs.py b/docker/base/set_configs.py index 4c5078cc4..640e3e2d2 100644 --- a/docker/base/set_configs.py +++ b/docker/base/set_configs.py @@ -19,6 +19,7 @@ import json import logging import os import pwd +import re import shutil import stat import sys @@ -334,6 +335,7 @@ def handle_permissions(config): owner = permission.get('owner') recurse = permission.get('recurse', False) perm = permission.get('perm') + exclude = permission.get('exclude', []) desired_user, desired_group = user_group(owner) uid = pwd.getpwnam(desired_user).pw_uid @@ -373,14 +375,24 @@ def handle_permissions(config): LOG.exception('Failed to set permission of %s to %s', path, perm) + def handle_exclusion(root, path_suffix): + full_path = os.path.join(root, path_suffix) + LOG.debug("Checking for exclusion: %s" % full_path) + if exclude: + for exclude_ in exclude: + if not re.search(exclude_, full_path): + set_perms(full_path, uid, gid, perm) + else: + set_perms(full_path, uid, gid, perm) + for dest in glob.glob(path): set_perms(dest, uid, gid, perm) if recurse and os.path.isdir(dest): for root, dirs, files in os.walk(dest): for dir_ in dirs: - set_perms(os.path.join(root, dir_), uid, gid, perm) + handle_exclusion(root, dir_) for file_ in files: - set_perms(os.path.join(root, file_), uid, gid, perm) + handle_exclusion(root, file_) def execute_config_strategy(config): diff --git a/releasenotes/notes/permissions-exclude-e1138abb573956a7.yaml b/releasenotes/notes/permissions-exclude-e1138abb573956a7.yaml new file mode 100644 index 000000000..46d3c19b0 --- /dev/null +++ b/releasenotes/notes/permissions-exclude-e1138abb573956a7.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Adds option to exclude files and directories when setting permissions + defined in kolla config.json using regular expression. |
