Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configd: T6504: send sudo_user on session init and set env variable #3701

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/services/vyos-configd
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,13 @@ def initialization(socket):
pid_string = socket.recv().decode("utf-8", "ignore")
resp = "pid"
socket.send(resp.encode())
sudo_user_string = socket.recv().decode("utf-8", "ignore")
resp = "sudo_user"
socket.send(resp.encode())

logger.debug(f"config session pid is {pid_string}")
logger.debug(f"config session sudo_user is {sudo_user_string}")

try:
session_out = os.readlink(f"/proc/{pid_string}/fd/1")
session_mode = 'w'
Expand All @@ -192,6 +197,8 @@ def initialization(socket):
session_out = script_stdout_log
session_mode = 'a'

os.environ['SUDO_USER'] = sudo_user_string

try:
configsource = ConfigSourceString(running_config_text=active_string,
session_config_text=session_string)
Expand Down Expand Up @@ -266,9 +273,6 @@ if __name__ == '__main__':
cfg_group = grp.getgrnam(CFG_GROUP)
os.setgid(cfg_group.gr_gid)

os.environ['SUDO_USER'] = 'vyos'
os.environ['SUDO_GID'] = str(cfg_group.gr_gid)

def sig_handler(signum, frame):
shutdown()

Expand Down
11 changes: 11 additions & 0 deletions src/shim/vyshim.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ int initialization(void* Requester)
strsep(&pid_val, "_");
debug_print("config session pid: %s\n", pid_val);

char *sudo_user = getenv("SUDO_USER");
if (!sudo_user) {
char nobody[] = "nobody";
sudo_user = nobody;
}
debug_print("sudo_user is %s\n", sudo_user);

debug_print("Sending init announcement\n");
char *init_announce = mkjson(MKJSON_OBJ, 1,
MKJSON_STRING, "type", "init");
Expand Down Expand Up @@ -240,6 +247,10 @@ int initialization(void* Requester)
zmq_recv(Requester, buffer, 16, 0);
debug_print("Received pid receipt\n");

debug_print("Sending config session sudo_user\n");
zmq_send(Requester, sudo_user, strlen(sudo_user), 0);
zmq_recv(Requester, buffer, 16, 0);
debug_print("Received sudo_user receipt\n");

return 0;
}
Expand Down
Loading