Skip to content

Commit

Permalink
feat: User-specified mount point owner and permissions
Browse files Browse the repository at this point in the history
Added new volume options related to mount point directory:
mount_user - directory owner (string)
mount_group - directory group (string)
mount_permissions - directory permissions (string; same format as chmod)

Resolves: rhbz#2181661
  • Loading branch information
japokorn committed May 16, 2023
1 parent 1b4b4c5 commit a638c00
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
8 changes: 7 additions & 1 deletion library/blivet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,10 @@ def handle_new_mount(volume, fstab):
'opts': volume['mount_options'],
'dump': volume['mount_check'],
'passno': volume['mount_passno'],
'state': 'mounted' if volume['fs_type'] != "swap" else "present"})
'state': 'mounted' if volume['fs_type'] != "swap" else "present",
'owner': volume['mount_user'],
'group': volume['mount_group'],
'permissions': volume['mount_permissions']})

return mount_info

Expand Down Expand Up @@ -1729,6 +1732,9 @@ def run_module():
fs_type=dict(type='str'),
mount_options=dict(type='str'),
mount_point=dict(type='str'),
mount_user=dict(type='str'),
mount_group=dict(type='str'),
mount_permissions=dict(type='str'),
name=dict(type='str'),
raid_level=dict(type='str'),
size=dict(type='str'),
Expand Down
27 changes: 27 additions & 0 deletions tasks/main-blivet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,33 @@
daemon_reload: true
when: blivet_output['mounts']

- name: Set directory owner
command: "chown {{ mount_info['owner'] }} {{ mount_info['path'] }}"
when: mount_info['owner']
loop: "{{ blivet_output.mounts | selectattr('state', 'defined') |
rejectattr('state', 'match', '^absent$') | list }}"
loop_control:
loop_var: mount_info
changed_when: false

- name: Set directory group
command: "chown :{{ mount_info['group'] }} {{ mount_info['path'] }}"
when: mount_info['group']
loop: "{{ blivet_output.mounts | selectattr('state', 'defined') |
rejectattr('state', 'match', '^absent$') | list }}"
loop_control:
loop_var: mount_info
changed_when: false

- name: Set directory permissions
command: "chmod {{ mount_info['permissions'] }} {{ mount_info['path'] }}"
when: mount_info['permissions']
loop: "{{ blivet_output.mounts | selectattr('state', 'defined') |
rejectattr('state', 'match', '^absent$') | list }}"
loop_control:
loop_var: mount_info
changed_when: false

#
# Manage /etc/crypttab
#
Expand Down
40 changes: 39 additions & 1 deletion tests/test-verify-volume-mount.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@
_storage_test_volume_present and
storage_test_volume.fs_type == 'swap' else 0 }}"

- name: Get information about the mountpoint directory owner
command: "stat -c '%U' {{ storage_test_volume.mount_point }}"
register: storage_test_found_mount_user
changed_when: false
when: _storage_test_volume_present and storage_test_volume.mount_point and storage_test_volume.mount_user

Check failure on line 37 in tests/test-verify-volume-mount.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (107 > 80 characters)

- name: Get information about the mountpoint directory group
command: "stat -c '%U' {{ storage_test_volume.mount_point }}"
register: storage_test_found_mount_group
changed_when: false
when: _storage_test_volume_present and storage_test_volume.mount_point and storage_test_volume.mount_group

Check failure on line 43 in tests/test-verify-volume-mount.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (108 > 80 characters)

- name: Get information about the mountpoint directory permissions
command: "stat -c '%a' {{ storage_test_volume.mount_point }}"
register: storage_test_found_mount_permissions
changed_when: false
when: _storage_test_volume_present and storage_test_volume.mount_point and storage_test_volume.mount_permissions

Check failure on line 49 in tests/test-verify-volume-mount.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (114 > 80 characters)

#
# Verify mount presence.
#
Expand All @@ -43,7 +61,7 @@
when: _storage_test_volume_present and storage_test_volume.mount_point

#
# Verify mount directory.
# Verify mount directory (state, owner, group, permissions).
#
- name: Verify the current mount state by mount point
assert:
Expand All @@ -53,6 +71,24 @@
Found unexpected mount state for volume
'{{ storage_test_volume.name }}' mount point
- name: Verify mount directory user
assert:
that: "{{ storage_test_volume.mount_user == storage_test_found_mount_user.stdout }}"

Check failure on line 76 in tests/test-verify-volume-mount.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (88 > 80 characters)
msg: "Mount directory {{ storage_test_volume.mount_point }} of volume {{ storage_test_volume.name }}) has unexcepted owner (expected: {{ storage_test_volume.mount_user }}, found: {{ storage_test_found_mount_user.stdout }})"

Check failure on line 77 in tests/test-verify-volume-mount.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (227 > 80 characters)
when: _storage_test_volume_present and storage_test_volume.mount_point and storage_test_volume.mount_user

Check failure on line 78 in tests/test-verify-volume-mount.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (107 > 80 characters)

- name: Verify mount directory group
assert:
that: "{{ storage_test_volume.mount_group == storage_test_found_mount_group.stdout }}"

Check failure on line 82 in tests/test-verify-volume-mount.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (90 > 80 characters)
msg: "Mount directory {{ storage_test_volume.mount_point }} of volume {{ storage_test_volume.name }}) has unexcepted group (expected: {{ storage_test_volume.mount_group }}, found: {{ storage_test_found_mount_group.stdout }})"

Check failure on line 83 in tests/test-verify-volume-mount.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (229 > 80 characters)
when: _storage_test_volume_present and storage_test_volume.mount_point and storage_test_volume.mount_group

Check failure on line 84 in tests/test-verify-volume-mount.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (108 > 80 characters)

- name: Verify mount directory permissions
assert:
that: "{{ storage_test_volume.mount_permissions == storage_test_found_mount_permissions.stdout }}"

Check failure on line 88 in tests/test-verify-volume-mount.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (102 > 80 characters)
msg: "Mount directory {{ storage_test_volume.mount_point }} of volume {{ storage_test_volume.name }}) has unexcepted permissions (expected: {{ storage_test_volume.mount_permissions }}, found: {{ storage_test_found_mount_permissions.stdout }})"
when: _storage_test_volume_present and storage_test_volume.mount_point and storage_test_volume.mount_permissions

#
# Verify mount fs type.
#
Expand Down Expand Up @@ -100,3 +136,5 @@
storage_test_swap_expected_matches: null
storage_test_sys_node: null
storage_test_swaps: null
storage_test_found_mount_user: null
storage_test_found_mount_user: null
6 changes: 6 additions & 0 deletions tests/tests_create_disk_then_remove.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
disks: "{{ unused_disks[0] }}"
fs_type: ext4
mount_point: "{{ mount_location }}"
mount_user: "nobody"
mount_group: "nobody"
mount_permissions: "777"
- name: Verify role results
include_tasks: verify-role-results.yml
Expand All @@ -48,6 +51,9 @@
type: disk
disks: "{{ unused_disks }}"
mount_point: "{{ mount_location }}"
mount_user: "root"
mount_group: "root"
mount_permissions: "755"

- name: Assert file system is preserved on existing partition volume
assert:
Expand Down

0 comments on commit a638c00

Please sign in to comment.