Skip to content

Commit

Permalink
[TUNING] Make the 'dropping CAP_SETUID' feature configurable, default…
Browse files Browse the repository at this point in the history
… to off.
  • Loading branch information
gwanglst committed Feb 18, 2021
1 parent 1837cfa commit 878b2d9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/extensions/extworkerconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ExtWorkerConfig::ExtWorkerConfig(const char *pName)
, m_gid(-1)
, m_pServerAddr(new GSockAddr())
, m_pOrgEnv(NULL)
, m_iDropCaps(0)
{
}

Expand All @@ -72,6 +73,7 @@ ExtWorkerConfig::ExtWorkerConfig()
, m_gid(-1)
, m_pServerAddr(new GSockAddr())
, m_pOrgEnv(NULL)
, m_iDropCaps(0)
{}


Expand Down Expand Up @@ -102,6 +104,7 @@ ExtWorkerConfig::ExtWorkerConfig(const ExtWorkerConfig &rhs)
m_iDaemonSuEXEC = rhs.m_iDaemonSuEXEC;
m_uid = rhs.m_uid;
m_gid = rhs.m_gid;
m_iDropCaps = rhs.m_iDropCaps;
if (m_iRefAddr)
m_pServerAddr = rhs.m_pServerAddr;
else
Expand Down
3 changes: 2 additions & 1 deletion src/extensions/localworkerconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,5 +407,6 @@ void LocalWorkerConfig::configExtAppUserGroup(const XmlNode *pNode,
lstrncpy(sHomeDir, "/home/nobody", szHomeDir); //If failed, use default as
}
setUGid(uid, gid);
setDropCaps(1);
if (!HttpServerConfig::getInstance().getAllowExtAppSetuid())
setDropCaps(1);
}
1 change: 1 addition & 0 deletions src/http/httpserverconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ HttpServerConfig::HttpServerConfig()
, m_pGlobalVHost(NULL)
, m_bwrap(BWRAP_DISABLED)
, m_pBwrapCmdLine(NULL)
, m_iAllowExtAppSetuid(1)
{
m_pDeniedDir = new DeniedDir();
}
Expand Down
4 changes: 4 additions & 0 deletions src/http/httpserverconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class HttpServerConfig : public TSingleton<HttpServerConfig>
int m_iEnableH2c;
int m_iProcNo;
int m_iChildren;
int m_iAllowExtAppSetuid;

const char *m_pAdminSock;
DeniedDir *m_pDeniedDir;
Expand Down Expand Up @@ -223,6 +224,9 @@ class HttpServerConfig : public TSingleton<HttpServerConfig>

void setBwrapCmdLine(const char *c) { m_pBwrapCmdLine = c; }
const char *getBwrapCmdLine() const { return m_pBwrapCmdLine; }

void setAllowExtAppSetuid(int val) { m_iAllowExtAppSetuid = val; }
int getAllowExtAppSetuid() const { return m_iAllowExtAppSetuid; }
};

LS_SINGLETON_DECL(HttpServerConfig);
Expand Down
6 changes: 6 additions & 0 deletions src/main/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,12 @@ int HttpServerImpl::configSecurity(const XmlNode *pRoot)
"banPeriod", 1, INT_MAX, 60));
}

const int iAllowExtAppSetuid = currentCtx.getLongValue(pNode,
"allowExtAppSetuid", 0, 1, 1);
LS_INFO("setuid %s allowed in Ext Apps",
iAllowExtAppSetuid ? "is" : "is not");
config.setAllowExtAppSetuid(iAllowExtAppSetuid);

// CGI
CgidWorker *pWorker = (CgidWorker *) ExtAppRegistry::addApp(
EA_CGID, LSCGID_NAME);
Expand Down
2 changes: 2 additions & 0 deletions src/main/plainconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ plainconfKeywords plainconf::sKeywords[] =
{"quicidletimeout", NULL},
{"quicpush", NULL},
{"quiccongestionctrl", NULL},

{"allowextappsetuid", NULL},
};

static HashStringMap<plainconfKeywords *> allKeyword(29, GHash::hfCiString,
Expand Down

0 comments on commit 878b2d9

Please sign in to comment.