Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
DobbySpecConfig.h
1/*
2* If not stated otherwise in this file or this component's LICENSE file the
3* following copyright and licenses apply:
4*
5* Copyright 2016 Sky UK
6*
7* Licensed under the Apache License, Version 2.0 (the "License");
8* you may not use this file except in compliance with the License.
9* You may obtain a copy of the License at
10*
11* http://www.apache.org/licenses/LICENSE-2.0
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*/
19/*
20 * File: DobbySpecConfig.h
21 *
22 */
23#ifndef DOBBYSPECCONFIG_H
24#define DOBBYSPECCONFIG_H
25
26#include "DobbyConfig.h"
27#include "DobbyBundle.h"
28
29#include <set>
30#include <bitset>
31#include <memory>
32
33namespace ctemplate {
34 class TemplateDictionary;
35}
36
37
38// -----------------------------------------------------------------------------
54{
55public:
56 DobbySpecConfig(const std::shared_ptr<IDobbyUtils>& utils,
57 const std::shared_ptr<const IDobbySettings>& settings,
58 const ContainerId& id,
59 const std::shared_ptr<const DobbyBundle>& bundle,
60 const std::string& specJson);
61 DobbySpecConfig(const std::shared_ptr<IDobbyUtils>& utils,
62 const std::shared_ptr<const IDobbySettings>& settings,
63 const std::shared_ptr<const DobbyBundle>& bundle,
64 const std::string& specJson);
66
67public:
68 bool isValid() const override;
69
70public:
71 const std::string spec() const override;
72
73public:
74 uid_t userId() const override;
75 gid_t groupId() const override;
76
77public:
78 IDobbyIPCUtils::BusType systemDbus() const override;
79 IDobbyIPCUtils::BusType sessionDbus() const override;
80 IDobbyIPCUtils::BusType debugDbus() const override;
81
82public:
83 bool restartOnCrash() const override;
84
85public:
86 std::shared_ptr<rt_dobby_schema> config() const override;
87
88public:
89 const std::string& etcHosts() const;
90 const std::string& etcServices() const;
91 const std::string& etcPasswd() const;
92 const std::string& etcGroup() const;
93 const std::string& etcLdSoPreload() const;
94
95public:
96 bool consoleDisabled() const override;
97 ssize_t consoleLimit() const override;
98 const std::string& consolePath() const override;
99
100public:
101 const std::map<std::string, Json::Value>& legacyPlugins() const override;
102 const std::map<std::string, Json::Value>& rdkPlugins() const override;
103
104public:
105 typedef struct _MountPoint
106 {
107 enum Type { Directory, File } type;
108 std::string destination;
109 } MountPoint;
110 std::vector<MountPoint> mountPoints() const;
111
112public:
113 const std::string& rootfsPath() const override;
114
115private:
116 bool parseSpec(ctemplate::TemplateDictionary* dictionary,
117 const std::string& json,
118 int bundleFd);
119
120private:
121 #define JSON_FIELD_PROCESSOR(x) \
122 bool x(const Json::Value&, ctemplate::TemplateDictionary*)
123
124 JSON_FIELD_PROCESSOR(processAppId);
125 JSON_FIELD_PROCESSOR(processEnv);
126 JSON_FIELD_PROCESSOR(processArgs);
127 JSON_FIELD_PROCESSOR(processCwd);
128 JSON_FIELD_PROCESSOR(processConsole);
129 JSON_FIELD_PROCESSOR(processUser);
130 JSON_FIELD_PROCESSOR(processUserNs);
131 JSON_FIELD_PROCESSOR(processEtc);
132 JSON_FIELD_PROCESSOR(processNetwork);
133 JSON_FIELD_PROCESSOR(processRtPriority);
134 JSON_FIELD_PROCESSOR(processRestartOnCrash);
135 JSON_FIELD_PROCESSOR(processMounts);
136 JSON_FIELD_PROCESSOR(processLegacyPlugins);
137 JSON_FIELD_PROCESSOR(processMemLimit);
138 JSON_FIELD_PROCESSOR(processGpu);
139 JSON_FIELD_PROCESSOR(processVpu);
140 JSON_FIELD_PROCESSOR(processDbus);
141 JSON_FIELD_PROCESSOR(processSyslog);
142 JSON_FIELD_PROCESSOR(processCpu);
143 JSON_FIELD_PROCESSOR(processDevices);
144 JSON_FIELD_PROCESSOR(processCapabilities);
145 JSON_FIELD_PROCESSOR(processSeccomp);
146
147 #undef JSON_FIELD_PROCESSOR
148
149 bool processLoopMount(const Json::Value& value,
150 ctemplate::TemplateDictionary* dictionary,
151 Json::Value& loopMntData);
152
153private:
154 void insertIntoRdkPluginJson(const std::string& pluginName,
155 const Json::Value& pluginData);
156 bool processRdkPlugins(const Json::Value& value,
157 ctemplate::TemplateDictionary* dictionary);
158 bool validateSeccompAction(const Json::Value& value) const;
159
160private:
161 template <std::size_t N>
162 std::bitset<N> parseBitset(const std::string& str) const;
163
164private:
165 void storeMountPoint(const std::string &type,
166 const std::string &source,
167 const std::string &destination);
168
169private:
170 std::string jsonToString(const Json::Value& jsonObject);
171
172private:
173 static void addGpuDevNodes(const std::shared_ptr<const IDobbySettings::HardwareAccessSettings> &settings,
174 ctemplate::TemplateDictionary *dict);
175
176 static void addVpuDevNodes(const std::shared_ptr<const IDobbySettings::HardwareAccessSettings> &settings,
177 ctemplate::TemplateDictionary *dict);
178
179private:
180 const std::shared_ptr<IDobbyUtils> mUtilities;
181 const std::shared_ptr<const IDobbySettings::HardwareAccessSettings> mGpuSettings;
182 const std::shared_ptr<const IDobbySettings::HardwareAccessSettings> mVpuSettings;
183 const std::vector<std::string> mDefaultPlugins;
184 const Json::Value mRdkPluginsData;
185
186private:
187 bool mValid;
188 ctemplate::TemplateDictionary* mDictionary;
189
190private:
191 Json::Value mSpec;
192 Json::Value mRdkPluginsJson;
193 std::shared_ptr<rt_dobby_schema> mConf;
194
195private:
196 enum class SpecVersion {
197 Unknown,
198 Version1_0,
199 Version1_1,
200 } mSpecVersion;
201
202private:
203 uid_t mUserId;
204 gid_t mGroupId;
205
206private:
207 bool mRestartOnCrash;
208
209private:
210 IDobbyIPCUtils::BusType mSystemDbus;
211 IDobbyIPCUtils::BusType mSessionDbus;
212 IDobbyIPCUtils::BusType mDebugDbus;
213
214private:
215 bool mConsoleDisabled;
216 std::string mConsolePath;
217 ssize_t mConsoleLimit;
218
219private:
220 std::map<std::string, Json::Value> mLegacyPlugins;
221 std::map<std::string, Json::Value> mRdkPlugins;
222
223private:
224 std::vector<MountPoint> mMountPoints;
225
226private:
227 std::string mEtcHosts;
228 std::string mEtcServices;
229 std::string mEtcPasswd;
230 std::string mEtcGroup;
231 std::string mEtcLdSoPreload;
232
233private:
234 static int mNumCores;
235
236private:
237 static const std::map<std::string, int> mAllowedCaps;
238
239private:
240 std::string mRootfsPath;
241
242};
243
244
245#endif // !defined(DOBBYSPECCONFIG_H)
A wrapper around a std::string, used to add some type definition to to an id and also to sanity check...
Definition ContainerId.h:41
Interface that configuration file parser classes have to implement.
Definition DobbyConfig.h:66
Takes a JSON formatted spec file in the constructor, parses it and extracts the relevant fields.
Definition DobbySpecConfig.h:54
std::string jsonToString(const Json::Value &jsonObject)
Use the JsonCpp streamwriter builder to convert a Json object into a string for use in ctemplate.
Definition DobbySpecConfig.cpp:670
void insertIntoRdkPluginJson(const std::string &pluginName, const Json::Value &pluginData)
Inserts rdkPlugin json into existing json.
Definition DobbySpecConfig.cpp:2683
bool parseSpec(ctemplate::TemplateDictionary *dictionary, const std::string &json, int bundleFd)
Generates the OCI.
Definition DobbySpecConfig.cpp:468
bool validateSeccompAction(const Json::Value &value) const
Validates the seccomp action field value.
Definition DobbySpecConfig.cpp:2651
void storeMountPoint(const std::string &type, const std::string &source, const std::string &destination)
Stores the mount point internally so it can be created by in the rootfs component.
Definition DobbySpecConfig.cpp:1870
bool processRdkPlugins(const Json::Value &value, ctemplate::TemplateDictionary *dictionary)
Processes the rdkPlugins field of the json spec.
Definition DobbySpecConfig.cpp:2732
std::bitset< N > parseBitset(const std::string &str) const
Parses a string to create a bitset for the appropriate bits set.
Definition DobbySpecConfig.cpp:1677
static void addVpuDevNodes(const std::shared_ptr< const IDobbySettings::HardwareAccessSettings > &settings, ctemplate::TemplateDictionary *dict)
Adds the VPU device nodes (if any) to supplied dictionary.
Definition DobbySpecConfig.cpp:1333
bool processLoopMount(const Json::Value &value, ctemplate::TemplateDictionary *dictionary, Json::Value &loopMntData)
Processes a loop mount field of the json spec.
Definition DobbySpecConfig.cpp:2045
bool isValid() const override
Getters used for plugins.
Definition DobbySpecConfig.cpp:345
static void addGpuDevNodes(const std::shared_ptr< const IDobbySettings::HardwareAccessSettings > &settings, ctemplate::TemplateDictionary *dict)
Adds the GPU device nodes (if any) to supplied dictionary.
Definition DobbySpecConfig.cpp:1289
BusType
The type of dbus to call methods on / emit signals.
Definition IDobbyIPCUtils.h:60
Definition DobbySpecConfig.h:106