LFCS · Question #393
An SELinux security context is required to ensure that all files in /opt have the default context of system_u:object_r:usr_t. How should the corresponding configuration entry be formatted?
The correct answer is B. /opt/.* system_u:object_r:usr_t. To configure the default SELinux context for all files under /opt, the configuration entry should specify the regular expression ^/opt(/.)?$ or ^/opt/.$ followed by the desired context system_u:object_r:usr_t.
Question
Options
- Asystem_u:object_r:usr_t /opt/*
- B/opt/.* system_u:object_r:usr_t
- C/opt/* system_u:object_r:usr_t
- Dsystem_u:object_r:usr_t: /opt/.*
- Esystem_u:object_r:usr_t /opt/.*
How the community answered
(37 responses)- B86% (32)
- C8% (3)
- D3% (1)
- E3% (1)
Why each option
To configure the default SELinux context for all files under `/opt`, the configuration entry should specify the regular expression `^/opt(/.*)?$` or `^/opt/.*$` followed by the desired context `system_u:object_r:usr_t`.
This format places the context before the path and uses a shell glob `*` instead of a regular expression, which is incorrect for SELinux file context configuration.
SELinux file context configuration entries, typically found in files like `file_contexts` or configured with `semanage fcontext`, use regular expressions to match file paths followed by the security context. The pattern `/opt/.*` (or more precisely `^/opt(/.*)?$`) correctly matches the `/opt` directory and all its contents, and the format `path_regexp context` is standard.
This option uses a shell glob `*` instead of a regular expression, which is not how SELinux file contexts are defined in configuration files.
This format places the context before the path, includes an extra colon after the context, and uses a regular expression that doesn't fully match the common pattern for `/opt` and its contents.
This format places the context before the path, which is incorrect for common SELinux file context configuration files like `file_contexts` where the path regexp comes first.
Concept tested: SELinux file context configuration
Source: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/using_selinux/using-semanage-and-restorecon-to-manage-selinux-file-contexts_using-selinux
Topics
Community Discussion
No community discussion yet for this question.