mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-15 21:26:57 +00:00
Add __lxc_get_selinux_contexts()
.
List SElinux contexts available. Not clear if this could be only for root or if normal user with `sudo` is also supported. Using `Fedora34` for basic testing. Signed-off-by: Edênis Freindorfer Azevedo <edenisfa@gmail.com>
This commit is contained in:
parent
4cd0915e76
commit
a33d86d20b
@ -239,6 +239,31 @@ __lxc_piped_args() {
|
|||||||
[[ "${#extcompletion[@]}" -gt 1 ]] && compopt -o nospace
|
[[ "${#extcompletion[@]}" -gt 1 ]] && compopt -o nospace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__lxc_get_selinux_contexts() {
|
||||||
|
declare -a sepolicies=()
|
||||||
|
local sepolicy
|
||||||
|
# Check for SElinux tool.
|
||||||
|
if ! command -v semanage > /dev/null 2>&1; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
# Skip header + following empty line.
|
||||||
|
mapfile -s 2 -t output < <(command semanage fcontext -l 2>/dev/null)
|
||||||
|
local -r none="<<None>>"
|
||||||
|
for line in "${output[@]}"; do
|
||||||
|
if [[ "${line}" =~ "SELinux Distribution fcontext Equivalence" ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
read -r -e -a current <<< "${line}"
|
||||||
|
if [[ "${#current[@]}" -gt 0 ]]; then
|
||||||
|
sepolicy="${current[${#current[@]}-1]}"
|
||||||
|
[[ ! "${sepolicy}" =~ ${none} ]] && sepolicies+=("${sepolicy}")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# Default context.
|
||||||
|
sepolicies+=("unconfined_u:object_r:default_t:s0")
|
||||||
|
COMPREPLY=( $( compgen -P'"' -S'"' -W "${sepolicies[*]}" -- "${cur}" ) )
|
||||||
|
}
|
||||||
|
|
||||||
_lxc_attach() {
|
_lxc_attach() {
|
||||||
local cur prev words cword split
|
local cur prev words cword split
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
@ -292,7 +317,7 @@ _lxc_attach() {
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--context | -c )
|
--context | -c )
|
||||||
# @TODO: list all SElinux contexts available.
|
__lxc_get_selinux_contexts
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user