Apache Mesos
capabilities.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __LINUX_CAPABILITIES_HPP__
18 #define __LINUX_CAPABILITIES_HPP__
19 
20 #include <set>
21 
22 #include <stout/flags.hpp>
23 #include <stout/nothing.hpp>
24 #include <stout/protobuf.hpp>
25 #include <stout/try.hpp>
26 
27 #include <mesos/mesos.hpp>
28 
29 namespace mesos {
30 namespace internal {
31 namespace capabilities {
32 
33 // Superset of all capabilities. This is the set currently supported
34 // by linux (kernel 5.9).
35 enum Capability : int
36 {
37  CHOWN = 0,
40  FOWNER = 3,
41  FSETID = 4,
42  KILL = 5,
43  SETGID = 6,
44  SETUID = 7,
45  SETPCAP = 8,
49  NET_ADMIN = 12,
50  NET_RAW = 13,
51  IPC_LOCK = 14,
52  IPC_OWNER = 15,
53  SYS_MODULE = 16,
54  SYS_RAWIO = 17,
55  SYS_CHROOT = 18,
56  SYS_PTRACE = 19,
57  SYS_PACCT = 20,
58  SYS_ADMIN = 21,
59  SYS_BOOT = 22,
60  SYS_NICE = 23,
62  SYS_TIME = 25,
64  MKNOD = 27,
65  LEASE = 28,
68  SETFCAP = 31,
70  MAC_ADMIN = 33,
71  SYSLOG = 34,
72  WAKE_ALARM = 35,
74  AUDIT_READ = 37,
75  PERFMON = 38,
76  BPF = 39,
79 };
80 
81 
82 enum Type
83 {
89 };
90 
91 
96 {
97 public:
98  const std::set<Capability>& get(const Type& type) const;
99  void set(const Type& type, const std::set<Capability>& capabilities);
100  void add(const Type& type, const Capability& capability);
101  void drop(const Type& type, const Capability& capability);
102 
103  bool operator==(const ProcessCapabilities& right) const
104  {
105  return right.effective == effective &&
106  right.permitted == permitted &&
107  right.inheritable == inheritable &&
108  right.bounding == bounding &&
109  right.ambient == ambient;
110  }
111 
112 private:
113  friend std::ostream& operator<<(
114  std::ostream& stream,
115  const ProcessCapabilities& processCapabilities);
116 
117  std::set<Capability> effective;
118  std::set<Capability> permitted;
119  std::set<Capability> inheritable;
120  std::set<Capability> bounding;
121  std::set<Capability> ambient;
122 };
123 
124 
135 {
136 public:
147  static Try<Capabilities> create();
148 
155  Try<ProcessCapabilities> get() const;
156 
164  Try<Nothing> set(const ProcessCapabilities& processCapabilities);
165 
173  Try<Nothing> setKeepCaps();
174 
180  std::set<Capability> getAllSupportedCapabilities();
181 
189 
190 private:
191  Capabilities(int _lastCap, bool _ambientSupported);
192 
193  // Maximum count of capabilities supported by the system.
194  const int lastCap;
195 };
196 
197 
199 std::set<Capability> convert(const CapabilityInfo& capabilityInfo);
200 CapabilityInfo convert(const std::set<Capability>& capabilitySet);
201 
202 
203 std::ostream& operator<<(
204  std::ostream& stream,
205  const Capability& capability);
206 
207 
208 std::ostream& operator<<(
209  std::ostream& stream,
210  const Type& type);
211 
212 
213 std::ostream& operator<<(
214  std::ostream& stream,
215  const ProcessCapabilities& capabilities);
216 
217 } // namespace capabilities {
218 } // namespace internal {
219 } // namespace mesos {
220 
221 #endif // __LINUX_CAPABILITIES_HPP__
Definition: capabilities.hpp:57
Encapsulation of capability value sets.
Definition: capabilities.hpp:95
Definition: capabilities.hpp:38
Definition: capabilities.hpp:42
Definition: capabilities.hpp:63
friend std::ostream & operator<<(std::ostream &stream, const ProcessCapabilities &processCapabilities)
Definition: capabilities.hpp:70
Definition: capabilities.hpp:85
Definition: capabilities.hpp:48
Definition: check.hpp:33
Definition: capabilities.hpp:59
Definition: capabilities.hpp:64
Definition: capabilities.hpp:68
Definition: capabilities.hpp:88
void drop(const Type &type, const Capability &capability)
Definition: capabilities.hpp:40
Definition: capabilities.hpp:58
Capability
Definition: capabilities.hpp:35
Definition: capabilities.hpp:76
Definition: capabilities.hpp:44
bool operator==(const ProcessCapabilities &right) const
Definition: capabilities.hpp:103
Definition: capabilities.hpp:46
Definition: capabilities.hpp:37
Definition: capabilities.hpp:52
Definition: capabilities.hpp:50
const bool ambientCapabilitiesSupported
Whether ambient capabilities are supported on this host.
Definition: capabilities.hpp:188
void add(const Type &type, const Capability &capability)
Definition: capabilities.hpp:54
Definition: capabilities.hpp:86
Definition: capabilities.hpp:87
Definition: capabilities.hpp:53
Definition: capabilities.hpp:62
Definition: capabilities.hpp:56
Definition: agent.hpp:25
Definition: capabilities.hpp:72
Definition: capabilities.hpp:55
Definition: capabilities.hpp:43
Capability convert(const CapabilityInfo::Capability &capability)
Definition: capabilities.hpp:74
Definition: capabilities.hpp:75
Definition: capabilities.hpp:39
Definition: capabilities.hpp:41
Definition: capabilities.hpp:49
Definition: attributes.hpp:24
Definition: capabilities.hpp:71
Definition: capabilities.hpp:60
Type
Definition: capabilities.hpp:82
Definition: capabilities.hpp:84
Definition: capabilities.hpp:73
Try< uint32_t > type(const std::string &path)
Definition: capabilities.hpp:69
Definition: capabilities.hpp:67
Definition: capabilities.hpp:45
Try< Nothing > create(const std::string &hierarchy, const std::string &cgroup, bool recursive=false)
Definition: capabilities.hpp:61
Definition: capabilities.hpp:65
Definition: capabilities.hpp:66
Definition: capabilities.hpp:51
Definition: capabilities.hpp:78
Provides wrapper for the linux process capabilities interface.
Definition: capabilities.hpp:134