Skip to content

Commit 07d0b12

Browse files
Add exclude for permissions in kolla config.json file
When using recursive mode to set permissions for a directory as defined in kolla config.json, all the subdirectories and files will receive the same permissions. This change adds the option to exclude specific files or directories - either a name or a regular expression can be used. Closes-Bug: #1931294 Closes-Bug: #1972168 Co-Authored-By: Jakub Darmach <[email protected]> Change-Id: If2f39736e2af34cd91d0976051ff66f06e96ab42
1 parent 5dede10 commit 07d0b12

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

doc/source/admin/kolla_api.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ The `kolla_set_configs`_ script understands the following attributes:
6565
Must be passed in the numeric octal form.
6666
* **recurse**: whether to apply the change recursively over the target
6767
directory. Boolean, defaults to ``false``.
68+
* **exclude**: array of names of the directories or files to be excluded when
69+
``recurse`` is set to ``true``. Supports Python regular expressions.
70+
Defaults to empty array.
6871

6972
Here is an example configuration file:
7073

@@ -85,7 +88,8 @@ Here is an example configuration file:
8588
{
8689
"path": "/var/log/kolla/trove",
8790
"owner": "trove:trove",
88-
"recurse": true
91+
"recurse": true,
92+
"exclude": ["/var/log/^snapshot.*"]
8993
}
9094
]
9195
}

docker/base/set_configs.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import logging
2020
import os
2121
import pwd
22+
import re
2223
import shutil
2324
import sys
2425

@@ -345,6 +346,7 @@ def handle_permissions(config):
345346
owner = permission.get('owner')
346347
recurse = permission.get('recurse', False)
347348
perm = permission.get('perm')
349+
exclude = permission.get('exclude', [])
348350

349351
desired_user, desired_group = user_group(owner)
350352
uid = pwd.getpwnam(desired_user).pw_uid
@@ -375,14 +377,24 @@ def set_perms(path, uid, gid, perm):
375377
LOG.exception('Failed to set permission of %s to %s',
376378
path, perm)
377379

380+
def handle_exclusion(root, path_suffix):
381+
full_path = os.path.join(root, path_suffix)
382+
LOG.debug("Checking for exclusion: %s" % full_path)
383+
if exclude:
384+
for exclude_ in exclude:
385+
if not re.search(exclude_, full_path):
386+
set_perms(full_path, uid, gid, perm)
387+
else:
388+
set_perms(full_path, uid, gid, perm)
389+
378390
for dest in glob.glob(path):
379391
set_perms(dest, uid, gid, perm)
380392
if recurse and os.path.isdir(dest):
381393
for root, dirs, files in os.walk(dest):
382394
for dir_ in dirs:
383-
set_perms(os.path.join(root, dir_), uid, gid, perm)
395+
handle_exclusion(root, dir_)
384396
for file_ in files:
385-
set_perms(os.path.join(root, file_), uid, gid, perm)
397+
handle_exclusion(root, file_)
386398

387399

388400
def execute_config_strategy(config):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Adds option to exclude files and directories when setting permissions
5+
defined in kolla config.json using regular expression.

0 commit comments

Comments
 (0)