Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
DobbySpecConfig Class Reference

Takes a JSON formatted spec file in the constructor, parses it and extracts the relevant fields. More...

#include <DobbySpecConfig.h>

Inheritance diagram for DobbySpecConfig:
Inheritance graph
[legend]
Collaboration diagram for DobbySpecConfig:
Collaboration graph
[legend]

Classes

struct  _MountPoint
 

Public Types

typedef struct DobbySpecConfig::_MountPoint MountPoint
 
- Public Types inherited from DobbyConfig
enum class  NetworkType { None , Nat , Open }
 Network type used for Network plugin.
 
typedef struct DobbyConfig::_LoopMount LoopMount
 Loopmount struct used for Storage plugin.
 

Public Member Functions

 DobbySpecConfig (const std::shared_ptr< IDobbyUtils > &utils, const std::shared_ptr< const IDobbySettings > &settings, const ContainerId &id, const std::shared_ptr< const DobbyBundle > &bundle, const std::string &specJson)
 Constructor used to parse a Dobby spec file into an OCI config file.
 
 DobbySpecConfig (const std::shared_ptr< IDobbyUtils > &utils, const std::shared_ptr< const IDobbySettings > &settings, const std::shared_ptr< const DobbyBundle > &bundle, const std::string &specJson)
 Constructor used to parse a Dobby spec file into an OCI config file. Used with bundle generation.
 
bool isValid () const override
 Getters used for plugins.
 
const std::string spec () const override
 
uid_t userId () const override
 
gid_t groupId () const override
 
IDobbyIPCUtils::BusType systemDbus () const override
 
IDobbyIPCUtils::BusType sessionDbus () const override
 
IDobbyIPCUtils::BusType debugDbus () const override
 
bool restartOnCrash () const override
 
std::shared_ptr< rt_dobby_schema > config () const override
 
const std::string & etcHosts () const
 
const std::string & etcServices () const
 
const std::string & etcPasswd () const
 
const std::string & etcGroup () const
 
const std::string & etcLdSoPreload () const
 
bool consoleDisabled () const override
 
ssize_t consoleLimit () const override
 
const std::string & consolePath () const override
 
const std::map< std::string, Json::Value > & legacyPlugins () const override
 
const std::map< std::string, Json::Value > & rdkPlugins () const override
 
std::vector< MountPointmountPoints () const
 
const std::string & rootfsPath () const override
 
- Public Member Functions inherited from DobbyConfig
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.
 
bool addEnvironmentVar (const std::string &envVar)
 Public api to allow for adding additional env variables.
 
bool changeProcessArgs (const std::string &command)
 
bool addWesterosMount (const std::string &socketPath)
 
bool writeConfigJson (const std::string &filePath) const
 Writes bundle config string to a file.
 
const std::string configJson () const
 Get OCI bundle config json as string.
 
void printCommand () const
 
bool enableSTrace (const std::string &logsDir)
 Enables strace for the container.
 
void setApparmorProfile (const std::string &profileName)
 Set apparmor profile in config.
 
void setPidsLimit (int limit)
 Set cgroup pids limit.
 

Private Types

enum class  SpecVersion { Unknown , Version1_0 , Version1_1 }
 

Private Member Functions

bool parseSpec (ctemplate::TemplateDictionary *dictionary, const std::string &json, int bundleFd)
 Generates the OCI.
 
 JSON_FIELD_PROCESSOR (processAppId)
 
 JSON_FIELD_PROCESSOR (processEnv)
 
 JSON_FIELD_PROCESSOR (processArgs)
 
 JSON_FIELD_PROCESSOR (processCwd)
 
 JSON_FIELD_PROCESSOR (processConsole)
 
 JSON_FIELD_PROCESSOR (processUser)
 
 JSON_FIELD_PROCESSOR (processUserNs)
 
 JSON_FIELD_PROCESSOR (processEtc)
 
 JSON_FIELD_PROCESSOR (processNetwork)
 
 JSON_FIELD_PROCESSOR (processRtPriority)
 
 JSON_FIELD_PROCESSOR (processRestartOnCrash)
 
 JSON_FIELD_PROCESSOR (processMounts)
 
 JSON_FIELD_PROCESSOR (processLegacyPlugins)
 
 JSON_FIELD_PROCESSOR (processMemLimit)
 
 JSON_FIELD_PROCESSOR (processGpu)
 
 JSON_FIELD_PROCESSOR (processVpu)
 
 JSON_FIELD_PROCESSOR (processDbus)
 
 JSON_FIELD_PROCESSOR (processSyslog)
 
 JSON_FIELD_PROCESSOR (processCpu)
 
 JSON_FIELD_PROCESSOR (processDevices)
 
 JSON_FIELD_PROCESSOR (processCapabilities)
 
 JSON_FIELD_PROCESSOR (processSeccomp)
 
bool processLoopMount (const Json::Value &value, ctemplate::TemplateDictionary *dictionary, Json::Value &loopMntData)
 Processes a loop mount field of the json spec.
 
void insertIntoRdkPluginJson (const std::string &pluginName, const Json::Value &pluginData)
 Inserts rdkPlugin json into existing json.
 
bool processRdkPlugins (const Json::Value &value, ctemplate::TemplateDictionary *dictionary)
 Processes the rdkPlugins field of the json spec.
 
bool validateSeccompAction (const Json::Value &value) const
 Validates the seccomp action field value.
 
template<std::size_t N>
std::bitset< N > parseBitset (const std::string &str) const
 Parses a string to create a bitset for the appropriate bits set.
 
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.
 
std::string jsonToString (const Json::Value &jsonObject)
 Use the JsonCpp streamwriter builder to convert a Json object into a string for use in ctemplate.
 

Static Private Member Functions

static void addGpuDevNodes (const std::shared_ptr< const IDobbySettings::HardwareAccessSettings > &settings, ctemplate::TemplateDictionary *dict)
 Adds the GPU device nodes (if any) to supplied dictionary.
 
static void addVpuDevNodes (const std::shared_ptr< const IDobbySettings::HardwareAccessSettings > &settings, ctemplate::TemplateDictionary *dict)
 Adds the VPU device nodes (if any) to supplied dictionary.
 

Private Attributes

const std::shared_ptr< IDobbyUtilsmUtilities
 
const std::shared_ptr< const IDobbySettings::HardwareAccessSettingsmGpuSettings
 
const std::shared_ptr< const IDobbySettings::HardwareAccessSettingsmVpuSettings
 
const std::vector< std::string > mDefaultPlugins
 
const Json::Value mRdkPluginsData
 
bool mValid
 
ctemplate::TemplateDictionary * mDictionary
 
Json::Value mSpec
 
Json::Value mRdkPluginsJson
 
std::shared_ptr< rt_dobby_schema > mConf
 
enum DobbySpecConfig::SpecVersion mSpecVersion
 
uid_t mUserId
 
gid_t mGroupId
 
bool mRestartOnCrash
 
IDobbyIPCUtils::BusType mSystemDbus
 
IDobbyIPCUtils::BusType mSessionDbus
 
IDobbyIPCUtils::BusType mDebugDbus
 
bool mConsoleDisabled
 
std::string mConsolePath
 
ssize_t mConsoleLimit
 
std::map< std::string, Json::Value > mLegacyPlugins
 
std::map< std::string, Json::Value > mRdkPlugins
 
std::vector< MountPointmMountPoints
 
std::string mEtcHosts
 
std::string mEtcServices
 
std::string mEtcPasswd
 
std::string mEtcGroup
 
std::string mEtcLdSoPreload
 
std::string mRootfsPath
 

Static Private Attributes

static int mNumCores = -1
 
static const std::map< std::string, int > mAllowedCaps
 

Additional Inherited Members

- Protected Member Functions inherited from DobbyConfig
bool writeConfigJsonImpl (const std::string &filePath) const
 
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 DobbyPluginLauncher to work with rdkPlugins.
 
bool setHostnameToContainerId (const ContainerId &id, std::shared_ptr< rt_dobby_schema > cfg, const std::string &bundlePath)
 Sets the container hostname to the container ID.
 
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 DobbyPluginLauncher to work with rdkPlugins.
 
bool isApparmorProfileLoaded (const char *profile) const
 Check if apparmor profile is loaded.
 
- Static Protected Member Functions inherited from DobbyConfig
static std::list< DevNodescanDevNodes (const std::list< std::string > &devNodes)
 Takes a list of glob patterns corresponding to dev node paths and returns a list of structs with their details.
 
- Protected Attributes inherited from DobbyConfig
std::mutex mLock
 

Detailed Description

Takes a JSON formatted spec file in the constructor, parses it and extracts the relevant fields.

The JSON should be in our custom 'dobby' container format, this includes extra custom fields for things like /etc files, plugin configurations and so forth.

It's main purpose is to convert the dobby spec file to a OCI conformant JSON file.

Constructor & Destructor Documentation

◆ DobbySpecConfig() [1/2]

DobbySpecConfig::DobbySpecConfig ( const std::shared_ptr< IDobbyUtils > &  utils,
const std::shared_ptr< const IDobbySettings > &  settings,
const ContainerId id,
const std::shared_ptr< const DobbyBundle > &  bundle,
const std::string &  specJson 
)

Constructor used to parse a Dobby spec file into an OCI config file.

Parameters
[in]utilsThe daemon utils object.
[in]settingsDobby settings object.
[in]idContainer ID.
[in]bundlean instance of the DobbyBundle object
[in]specJsonJSON containing the Dobby spec

◆ DobbySpecConfig() [2/2]

DobbySpecConfig::DobbySpecConfig ( const std::shared_ptr< IDobbyUtils > &  utils,
const std::shared_ptr< const IDobbySettings > &  settings,
const std::shared_ptr< const DobbyBundle > &  bundle,
const std::string &  specJson 
)

Constructor used to parse a Dobby spec file into an OCI config file. Used with bundle generation.

Parameters
[in]utilsThe daemon utils object.
[in]settingsDobby settings object.
[in]bundlean instance of the DobbyBundle object
[in]specJsonJSON containing the Dobby spec

Member Function Documentation

◆ addGpuDevNodes()

void DobbySpecConfig::addGpuDevNodes ( const std::shared_ptr< const IDobbySettings::HardwareAccessSettings > &  settings,
ctemplate::TemplateDictionary *  dictionary 
)
staticprivate

Adds the GPU device nodes (if any) to supplied dictionary.

This function gathers the dev node details from the settings and system the first time it runs, for all subsequent times it uses the initial cached details.

Parameters
[in]settingsThe settings containing the list of dev nodes paths or glob patterns. Only used the first time called.
[in]dictionaryThe dictionary to add the details to.

◆ addVpuDevNodes()

void DobbySpecConfig::addVpuDevNodes ( const std::shared_ptr< const IDobbySettings::HardwareAccessSettings > &  settings,
ctemplate::TemplateDictionary *  dictionary 
)
staticprivate

Adds the VPU device nodes (if any) to supplied dictionary.

This function gathers the dev node details from the settings and system the first time it runs, for all subsequent times it uses the initial cached details.

Parameters
[in]settingsThe settings containing the list of dev nodes paths or glob patterns. Only used the first time called.
[in]dictionaryThe dictionary to add the details to.

◆ config()

std::shared_ptr< rt_dobby_schema > DobbySpecConfig::config ( ) const
overridevirtual

Implements DobbyConfig.

◆ consoleDisabled()

bool DobbySpecConfig::consoleDisabled ( ) const
overridevirtual

Implements DobbyConfig.

◆ consoleLimit()

ssize_t DobbySpecConfig::consoleLimit ( ) const
overridevirtual

Implements DobbyConfig.

◆ consolePath()

const std::string & DobbySpecConfig::consolePath ( ) const
overridevirtual

Implements DobbyConfig.

◆ debugDbus()

IDobbyIPCUtils::BusType DobbySpecConfig::debugDbus ( ) const
overridevirtual

Implements DobbyConfig.

◆ groupId()

gid_t DobbySpecConfig::groupId ( ) const
overridevirtual

Implements DobbyConfig.

◆ insertIntoRdkPluginJson()

void DobbySpecConfig::insertIntoRdkPluginJson ( const std::string &  pluginName,
const Json::Value &  pluginData 
)
private

Inserts rdkPlugin json into existing json.

Instead of blindly overwriting the plugin data, we only overwrite sections of the plugin data that have been set in the rdkPlugin field of the spec.

This allows us to set smaller portions of the plugin data and merge them with the data set by the processor methods.

Parameters
[in]valueThe rdkPlugins field from the json spec
[in]dictionaryPointer to the OCI dictionary to populate
Returns
true if correctly processed the value, otherwise false.

◆ isValid()

bool DobbySpecConfig::isValid ( ) const
overridevirtual

Getters used for plugins.

Implements DobbyConfig.

◆ jsonToString()

std::string DobbySpecConfig::jsonToString ( const Json::Value &  jsonObject)
private

Use the JsonCpp streamwriter builder to convert a Json object into a string for use in ctemplate.

Parameters
[in]jsonObjectobject to convert to string
Returns
JSON string of the input object

◆ parseBitset()

template<std::size_t N>
std::bitset< N > DobbySpecConfig::parseBitset ( const std::string &  str) const
private

Parses a string to create a bitset for the appropriate bits set.

Note
This code has been borrowed from the linux kernel's __bitmap_parselist function.

Input format is a comma-separated list of decimal numbers and ranges. Consecutively set bits are shown as two hyphen-separated decimal numbers, the smallest and largest bit numbers set in the range.

Parameters
[in]strThe string containing the bits set
Returns
the set of bits in the string, in case of an error an empty bitset will be returned.

◆ parseSpec()

bool DobbySpecConfig::parseSpec ( ctemplate::TemplateDictionary *  dictionary,
const std::string &  json,
int  bundleFd 
)
private

Generates the OCI.

This function will only work once, subsequent attempts to set the workspace path will fail. The function is atomic, therefore it returns true you can guarantee it suck and will be set for the lifetime of the function.

Parameters
[in]dictionaryPointer to the OCI dictionary to populate
[in]jsonThe json spec document from the client
[in]bundleFdFile descriptor of the bundle directory
Returns
true if the path was set, otherwise false.

◆ processLoopMount()

bool DobbySpecConfig::processLoopMount ( const Json::Value &  value,
ctemplate::TemplateDictionary *  dictionary,
Json::Value &  loopMntData 
)
private

Processes a loop mount field of the json spec.

Example json:

{
    "destination": "/home/private",
    "type": "loop",
    "fstype": "ext4",
    "source": "/mnt/apps/data.img",
    "options": [ "nosuid", "nodev", "noexec", "strictatime" ]
}
Parameters
[in]valueThe json spec document from the client
[in]dictionaryIgnored
Returns
true if correctly processed the value, otherwise false.

◆ processRdkPlugins()

bool DobbySpecConfig::processRdkPlugins ( const Json::Value &  value,
ctemplate::TemplateDictionary *  dictionary 
)
private

Processes the rdkPlugins field of the json spec.

The format is a 1-to-1 match with the actual OCI config file's rdkPlugin section.

If any rdkPlugin has been added to mRdkPluginsJson by the processX methods, the plugin's data fields will be overwritten if the same data member exists in the rdkPlugins field.

Parameters
[in]valueThe rdkPlugins field from the json spec
[in]dictionaryPointer to the OCI dictionary to populate
Returns
true if correctly processed the value, otherwise false.

◆ rdkPlugins()

const std::map< std::string, Json::Value > & DobbySpecConfig::rdkPlugins ( ) const
overridevirtual

Implements DobbyConfig.

◆ restartOnCrash()

bool DobbySpecConfig::restartOnCrash ( ) const
overridevirtual

Implements DobbyConfig.

◆ rootfsPath()

const std::string & DobbySpecConfig::rootfsPath ( ) const
overridevirtual

Implements DobbyConfig.

◆ sessionDbus()

IDobbyIPCUtils::BusType DobbySpecConfig::sessionDbus ( ) const
overridevirtual

Implements DobbyConfig.

◆ storeMountPoint()

void DobbySpecConfig::storeMountPoint ( const std::string &  type,
const std::string &  source,
const std::string &  destination 
)
private

Stores the mount point internally so it can be created by in the rootfs component.

Parameters
[in]typeThe type of the mount.
[in]sourceThe mount source.
[in]sourceThe mount destination within the rootfs.

◆ systemDbus()

IDobbyIPCUtils::BusType DobbySpecConfig::systemDbus ( ) const
overridevirtual

Implements DobbyConfig.

◆ userId()

uid_t DobbySpecConfig::userId ( ) const
overridevirtual

Implements DobbyConfig.

◆ validateSeccompAction()

bool DobbySpecConfig::validateSeccompAction ( const Json::Value &  value) const
private

Validates the seccomp action field value.

Parameters
[in]valueseccomp action field value
Returns
true if correct seccomp action value, otherwise false.

Member Data Documentation

◆ mAllowedCaps

const std::map< std::string, int > DobbySpecConfig::mAllowedCaps
staticprivate
Initial value:
=
{
{ "CAP_NET_BIND_SERVICE", CAP_NET_BIND_SERVICE },
{ "CAP_NET_BROADCAST", CAP_NET_BROADCAST },
{ "CAP_NET_RAW", CAP_NET_RAW },
}

The documentation for this class was generated from the following files: