Loading src/authdb.cpp +34 −22 Changes for src/authdb.cpp: 34 added lines, 22 removed lines. Original line number Diff line number Diff line Loading @@ -549,6 +549,17 @@ int main(int argc,char *argv[]){ } } /* Pre-create store directory with authdb ownership before cluster.init() creates files as root */ #ifndef _WIN32 if (!ccfg.store_path.empty() && getuid() == 0) { mkdir(ccfg.store_path.c_str(), 0755); struct passwd *pw = getpwnam("authdb"); if (pw) chown(ccfg.store_path.c_str(), pw->pw_uid, pw->pw_gid); } #endif cluster.init(ccfg); cluster.start(); authdb::g_Cluster = &cluster; Loading Loading @@ -577,6 +588,29 @@ int main(int argc,char *argv[]){ authdb::AuthDB authdb(backend,httpd.getServerSockets()); /* Drop privileges after binding sockets */ #ifndef _WIN32 if (getuid() == 0) { struct passwd *pw = getpwnam("authdb"); if (pw) { if (setgid(pw->pw_gid) != 0) { std::cerr << "setgid failed" << std::endl; return 1; } if (initgroups("authdb", pw->pw_gid) != 0) { std::cerr << "initgroups failed" << std::endl; return 1; } if (setuid(pw->pw_uid) != 0) { std::cerr << "setuid failed" << std::endl; return 1; } } else { std::cerr << "user authdb not found, running as root" << std::endl; } } #endif if(cmd.getCmdbyKey("debug")->getValue()=="true"){ authdb::DEBUG=true; authdb.threads=1; Loading Loading @@ -644,28 +678,6 @@ int main(int argc,char *argv[]){ pluginThreads.back().detach(); } #ifndef _WIN32 if ( getuid() == 0) { struct passwd *pw = getpwnam("authdb"); if (pw) { if (setgid(pw->pw_gid) != 0) { std::cerr << "setgid failed" << std::endl; return 1; } if (initgroups("authdb", pw->pw_gid) != 0) { std::cerr << "initgroups failed" << std::endl; return 1; } if (setuid(pw->pw_uid) != 0) { std::cerr << "setuid failed" << std::endl; return 1; } } else { std::cerr << "user authdb not found, running as root" << std::endl; } } #endif authdb.runEventloop(); /* Shutdown cluster */ Loading test/docker/Dockerfile +3 −2 Changes for test/docker/Dockerfile: 3 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -45,8 +45,8 @@ RUN addgroup authdb && \ RUN apk update && apk upgrade && \ apk add --no-cache yaml brotli openssl json-c libuuid libstdc++ RUN mkdir -p /etc/authdb/certs /var/lib/authdb /usr/local/share/authdb /var/log/authdb && \ chown authdb:authdb /var/lib/authdb /var/log/authdb RUN mkdir -p /etc/authdb/certs /var/lib/authdb/cluster /usr/local/share/authdb /var/log/authdb && \ chown -R authdb:authdb /var/lib/authdb /var/log/authdb COPY --from=build /usr/local/bin/authdb /usr/local/bin/ COPY --from=build /usr/local/lib /usr/local/lib/ Loading @@ -56,4 +56,5 @@ COPY --from=build /usr/local/share/authdb /usr/local/share/authdb # Ports: 9090 = HTTP API, 4433 = cluster QUIC EXPOSE 9090 4433 USER authdb CMD ["authdb", "-f", "true", "-c", "yaml:///etc/authdb/config.yaml"] Loading
src/authdb.cpp +34 −22 Changes for src/authdb.cpp: 34 added lines, 22 removed lines. Original line number Diff line number Diff line Loading @@ -549,6 +549,17 @@ int main(int argc,char *argv[]){ } } /* Pre-create store directory with authdb ownership before cluster.init() creates files as root */ #ifndef _WIN32 if (!ccfg.store_path.empty() && getuid() == 0) { mkdir(ccfg.store_path.c_str(), 0755); struct passwd *pw = getpwnam("authdb"); if (pw) chown(ccfg.store_path.c_str(), pw->pw_uid, pw->pw_gid); } #endif cluster.init(ccfg); cluster.start(); authdb::g_Cluster = &cluster; Loading Loading @@ -577,6 +588,29 @@ int main(int argc,char *argv[]){ authdb::AuthDB authdb(backend,httpd.getServerSockets()); /* Drop privileges after binding sockets */ #ifndef _WIN32 if (getuid() == 0) { struct passwd *pw = getpwnam("authdb"); if (pw) { if (setgid(pw->pw_gid) != 0) { std::cerr << "setgid failed" << std::endl; return 1; } if (initgroups("authdb", pw->pw_gid) != 0) { std::cerr << "initgroups failed" << std::endl; return 1; } if (setuid(pw->pw_uid) != 0) { std::cerr << "setuid failed" << std::endl; return 1; } } else { std::cerr << "user authdb not found, running as root" << std::endl; } } #endif if(cmd.getCmdbyKey("debug")->getValue()=="true"){ authdb::DEBUG=true; authdb.threads=1; Loading Loading @@ -644,28 +678,6 @@ int main(int argc,char *argv[]){ pluginThreads.back().detach(); } #ifndef _WIN32 if ( getuid() == 0) { struct passwd *pw = getpwnam("authdb"); if (pw) { if (setgid(pw->pw_gid) != 0) { std::cerr << "setgid failed" << std::endl; return 1; } if (initgroups("authdb", pw->pw_gid) != 0) { std::cerr << "initgroups failed" << std::endl; return 1; } if (setuid(pw->pw_uid) != 0) { std::cerr << "setuid failed" << std::endl; return 1; } } else { std::cerr << "user authdb not found, running as root" << std::endl; } } #endif authdb.runEventloop(); /* Shutdown cluster */ Loading
test/docker/Dockerfile +3 −2 Changes for test/docker/Dockerfile: 3 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -45,8 +45,8 @@ RUN addgroup authdb && \ RUN apk update && apk upgrade && \ apk add --no-cache yaml brotli openssl json-c libuuid libstdc++ RUN mkdir -p /etc/authdb/certs /var/lib/authdb /usr/local/share/authdb /var/log/authdb && \ chown authdb:authdb /var/lib/authdb /var/log/authdb RUN mkdir -p /etc/authdb/certs /var/lib/authdb/cluster /usr/local/share/authdb /var/log/authdb && \ chown -R authdb:authdb /var/lib/authdb /var/log/authdb COPY --from=build /usr/local/bin/authdb /usr/local/bin/ COPY --from=build /usr/local/lib /usr/local/lib/ Loading @@ -56,4 +56,5 @@ COPY --from=build /usr/local/share/authdb /usr/local/share/authdb # Ports: 9090 = HTTP API, 4433 = cluster QUIC EXPOSE 9090 4433 USER authdb CMD ["authdb", "-f", "true", "-c", "yaml:///etc/authdb/config.yaml"]