Skip to content

Commit 04b523d

Browse files
committed
starter: Run cilium-envoy with the target uid
Signed-off-by: Tam Mach <[email protected]>
1 parent 4356534 commit 04b523d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

starter/main.cc

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/capability.h>
2121
#include <linux/limits.h>
2222
#include <linux/prctl.h>
23+
#include <sys/stat.h>
2324

2425
#include "starter/privileged_service_protocol.h"
2526
#include "starter/privileged_service_server.h"
@@ -166,6 +167,19 @@ int main(int argc, char** argv) {
166167
}
167168

168169
envoy_args.push_back(nullptr);
170+
171+
// Get the file's owner UID
172+
struct stat file_stat;
173+
if (stat(path, &file_stat) != 0) {
174+
perror("stat failed");
175+
exit(1);
176+
}
177+
// Switch to the target user
178+
if (setuid(file_stat.st_uid) != 0) {
179+
perror("setuid failed");
180+
exit(1);
181+
}
182+
169183
execv(path, &envoy_args[0]);
170184
perror("execv");
171185
exit(1);

0 commit comments

Comments
 (0)