Verify Permissions on /usr/share/keyrings Directory

Description

To properly set the permissions of /usr/share/keyrings, run the command:

$ sudo chmod 0755 /usr/share/keyrings

Rationale

A non-root user should not be able to add or remove package repository keys from /usr/share/keyrings.

Remediation

Shell script

The following script can be run on the host to remediate the issue.

#!/bin/bash

find -H /usr/share/keyrings/ -maxdepth 0 -perm /u+s,g+ws,o+wt -type d -exec chmod u-s,g-ws,o-wt {} \;

Ansible playbook

The following playbook can be run with Ansible to remediate the issue.

- name: Find /usr/share/keyrings/ file(s)
  ansible.builtin.command: 'find -P /usr/share/keyrings/ -maxdepth 0 -perm /u+s,g+ws,o+wt  -type
    d '
  register: files_found
  changed_when: false
  failed_when: false
  check_mode: false
  tags:
  - configure_strategy
  - directory_permissions_usr_share_keyrings
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Set permissions for /usr/share/keyrings/ file(s)
  ansible.builtin.file:
    path: '{{ item }}'
    mode: u-s,g-ws,o-wt
    state: directory
  with_items:
  - '{{ files_found.stdout_lines }}'
  tags:
  - configure_strategy
  - directory_permissions_usr_share_keyrings
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed