privileged.go 719 Bytes
Newer Older
songlinfeng's avatar
songlinfeng committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
# Copyright (c) 2024, HCUOpt CORPORATION.  All rights reserved.
**/

package image

import "github.com/opencontainers/runtime-spec/specs-go"

const (
	capSysAdmin = "CAP_SYS_ADMIN"
)

// IsPrivileged returns true if the container is a privileged container.
func IsPrivileged(s *specs.Spec) bool {
	if s.Process.Capabilities == nil {
		return false
	}

	// We only make sure that the bounding capabibility set has
	// CAP_SYS_ADMIN. This allows us to make sure that the container was
	// actually started as '--privileged', but also allow non-root users to
	// access the privileged DTK capabilities.
	for _, c := range s.Process.Capabilities.Bounding {
		if c == capSysAdmin {
			return true
		}
	}
	return false
}