Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
DobbyConfig.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: DobbyConfig.h
21 *
22 */
23#ifndef DOBBYCONFIG_H
24#define DOBBYCONFIG_H
25
26#include "IDobbyUtils.h"
27#include "ContainerId.h"
28#include <IDobbyIPCUtils.h>
29#include <IDobbySettings.h>
30#include <Logging.h>
31
32#if defined(RDK)
33# include <json/json.h>
34#else
35# include <jsoncpp/json.h>
36#endif
37
38#define PLUGINLAUNCHER_PATH "/usr/bin/DobbyPluginLauncher"
39
40#include "rt_dobby_schema.h"
41
42#include <sstream>
43#include <map>
44#include <list>
45#include <mutex>
46#include <string>
47#include <vector>
48#include <sys/types.h>
49#include <sys/mount.h>
50
51// Names of the RDK Plugins in the extended bundle
52#define RDK_NETWORK_PLUGIN_NAME "networking"
53#define RDK_LOGGING_PLUGIN_NAME "logging"
54#define RDK_IPC_PLUGIN_NAME "ipc"
55#define RDK_STORAGE_PLUGIN_NAME "storage"
56#define RDK_GPU_PLUGIN_NAME "gpu"
57#define RDK_RTSCHEDULING_PLUGIN_NAME "rtscheduling"
58
59
60// -----------------------------------------------------------------------------
66{
67public:
68 virtual ~DobbyConfig() = default;
69
73 enum class NetworkType { None, Nat, Open };
74
78 typedef struct _LoopMount
79 {
80 std::string fsImagePath;
81 std::string fsImageType;
82 std::string destination;
83 std::list<std::string> mountOptions;
84 unsigned long mountFlags;
86
87
88// virtual methods to be overridden in derived classes
89public:
93 virtual bool isValid() const = 0;
94 virtual uid_t userId() const = 0;
95 virtual gid_t groupId() const = 0;
96 virtual IDobbyIPCUtils::BusType systemDbus() const = 0;
97 virtual IDobbyIPCUtils::BusType sessionDbus() const = 0;
98 virtual IDobbyIPCUtils::BusType debugDbus() const = 0;
99 virtual bool consoleDisabled() const = 0;
100 virtual ssize_t consoleLimit() const = 0;
101 virtual const std::string& consolePath() const = 0;
102 virtual bool restartOnCrash() const = 0;
103 virtual const std::string& rootfsPath() const = 0;
104 virtual std::shared_ptr<rt_dobby_schema> config() const = 0;
105 virtual const std::map<std::string, Json::Value>& rdkPlugins() const = 0;
106
107#if defined(LEGACY_COMPONENTS)
108 virtual const std::map<std::string, Json::Value>& legacyPlugins() const = 0;
109
113 virtual const std::string spec() const
114 { return std::string(); }
115#endif //defined(LEGACY_COMPONENTS)
116
117
118// non-virtual methods for default use
119public:
120 bool addMount(const std::string& source,
121 const std::string& target,
122 const std::string& fsType,
123 unsigned long mountFlags,
124 const std::list<std::string>& mountOptions);
125 bool addEnvironmentVar(const std::string& envVar);
126 bool changeProcessArgs(const std::string& command);
127 bool addWesterosMount(const std::string& socketPath);
128 bool writeConfigJson(const std::string& filePath) const;
129
130 const std::string configJson() const;
131
132 void printCommand() const;
133 bool enableSTrace(const std::string& logsDir);
134 void setApparmorProfile(const std::string& profileName);
135 void setPidsLimit(int limit);
136
137// protected methods for derived classes to use
138protected:
139 bool writeConfigJsonImpl(const std::string& filePath) const;
140 bool updateBundleConfig(const ContainerId& id,
141 std::shared_ptr<rt_dobby_schema> cfg,
142 const std::string& bundlePath);
144 std::shared_ptr<rt_dobby_schema> cfg,
145 const std::string& bundlePath);
146 bool convertToCompliant(const ContainerId& id,
147 std::shared_ptr<rt_dobby_schema> cfg,
148 const std::string& bundlePath);
149 bool isApparmorProfileLoaded(const char *profile) const;
150
151 struct DevNode
152 {
153 std::string path;
154 dev_t major;
155 dev_t minor;
156 mode_t mode;
157 };
158
159 static std::list<DevNode> scanDevNodes(const std::list<std::string> &devNodes);
160
161 mutable std::mutex mLock;
162
163private:
164 void addPluginLauncherHooks(std::shared_ptr<rt_dobby_schema> cfg, const std::string& bundlePath);
165 void setPluginHookEntry(rt_defs_hook* entry, const std::string& name, const std::string& configPath);
166 bool findPluginLauncherHookEntry(rt_defs_hook** hook, int len);
167};
168
169
170#endif // !defined(DOBBYCONFIG_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
void printCommand() const
Definition DobbyConfig.cpp:320
bool addEnvironmentVar(const std::string &envVar)
Public api to allow for adding additional env variables.
Definition DobbyConfig.cpp:234
bool updateBundleConfig(const ContainerId &id, std::shared_ptr< rt_dobby_schema > cfg, const std::string &bundlePath)
Convert the input config.json into an OCI compliant bundle config that adds support for DobbyPluginLa...
Definition DobbyConfig.cpp:726
bool changeProcessArgs(const std::string &command)
Definition DobbyConfig.cpp:276
bool addWesterosMount(const std::string &socketPath)
Definition DobbyConfig.cpp:408
void setApparmorProfile(const std::string &profileName)
Set apparmor profile in config.
Definition DobbyConfig.cpp:819
virtual bool isValid() const =0
Getters used for plugins.
static std::list< DevNode > scanDevNodes(const std::list< std::string > &devNodes)
Takes a list of glob patterns corresponding to dev node paths and returns a list of structs with thei...
Definition DobbyConfig.cpp:47
bool setHostnameToContainerId(const ContainerId &id, std::shared_ptr< rt_dobby_schema > cfg, const std::string &bundlePath)
Sets the container hostname to the container ID.
Definition DobbyConfig.cpp:697
void addPluginLauncherHooks(std::shared_ptr< rt_dobby_schema > cfg, const std::string &bundlePath)
Adds OCI hooks to the config.
Definition DobbyConfig.cpp:641
void setPidsLimit(int limit)
Set cgroup pids limit.
Definition DobbyConfig.cpp:858
bool findPluginLauncherHookEntry(rt_defs_hook **hook, int len)
Checks a hook for Dobby plugin launcher entries.
Definition DobbyConfig.cpp:564
bool enableSTrace(const std::string &logsDir)
Enables strace for the container.
Definition DobbyConfig.cpp:347
bool convertToCompliant(const ContainerId &id, std::shared_ptr< rt_dobby_schema > cfg, const std::string &bundlePath)
Convert the input config.json into an OCI compliant bundle config that adds support for DobbyPluginLa...
Definition DobbyConfig.cpp:889
const std::string configJson() const
Get OCI bundle config json as string.
Definition DobbyConfig.cpp:452
struct DobbyConfig::_LoopMount LoopMount
Loopmount struct used for Storage plugin.
bool writeConfigJson(const std::string &filePath) const
Writes bundle config string to a file.
Definition DobbyConfig.cpp:491
void setPluginHookEntry(rt_defs_hook *entry, const std::string &name, const std::string &configPath)
Populates a hook entry structure with DobbyPluginLauncher data.
Definition DobbyConfig.cpp:591
bool addMount(const std::string &source, const std::string &target, const std::string &fsType, unsigned long mountFlags, const std::list< std::string > &mountOptions)
Public api to allow for adding additional mounts.
Definition DobbyConfig.cpp:129
bool isApparmorProfileLoaded(const char *profile) const
Check if apparmor profile is loaded.
Definition DobbyConfig.cpp:782
NetworkType
Network type used for Network plugin.
Definition DobbyConfig.h:73
BusType
The type of dbus to call methods on / emit signals.
Definition IDobbyIPCUtils.h:60
Definition DobbyConfig.h:152
Loopmount struct used for Storage plugin.
Definition DobbyConfig.h:79