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

Dropping privilege logging issue one VM (requires root)[BUG] #66

Open
vcrocher opened this issue Feb 15, 2023 · 0 comments
Open

Dropping privilege logging issue one VM (requires root)[BUG] #66

vcrocher opened this issue Feb 15, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@vcrocher
Copy link
Member

vcrocher commented Feb 15, 2023

Description

CORC intentionally drop privileges to create log files even when run as root or sudoing. This is a problem when creating and writing to log requires these privileges: typically in VM with shared folder.

Actual Behavior

In VM, within a shared folder, requires specific user and group rights.
Works fine when run as user (not sudoing).
Fail with impossible log creation (spdlog exception) when run with sudo:

terminate called after throwing an instance of 'spdlog::spdlog_ex'
  what():  Failed opening file logs/CORC.log for writing: Permission denied
Aborted

Possible Fix

One idea would be to get actual user id and gid when sudoing but this is not sufficient and still fail:

/* Privileges management */

static uid_t uid, gid; //Saved uid and gid

void save_privileges() {

    uid = getuid();

    gid = getgid();

}

int drop_privileges() {

    if (uid == 0) {

        //If sudoing and not directly root (likely): use sudoer uid to create log files

        if(getenv("SUDO_UID")) {

            //Drop group privileges first

            if( setegid(atoi(getenv("SUDO_GID")))<0 || seteuid(atoi(getenv("SUDO_UID")))<0 ) {

                CO_errExit("Failed to drop privileges.");

                return -1;

            }

        }

        else {

            //Drop group privileges first

            if( setegid(1000)<0 || seteuid(1000)<0 ) {

                CO_errExit("Failed to drop privileges.");

                return -1;

            }

        }

    }

    return 0;

}

int restore_privileges() {

    if( setreuid(uid, gid)<0 ) {

        CO_errExit("Failed to restore privileges.");

        return -1;

    }

    return 0;

}
/* --------------------- */

=> This still produces the same error.
Workaround can be to not drop privileges in any cases and so create log files only accessible by root.

@vcrocher vcrocher added the bug Something isn't working label Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant