CentOS Stream 9에서 루트가 아닌 사용자로 rsyslogd를 실행할 수 없습니다.

CentOS Stream 9에서 루트가 아닌 사용자로 rsyslogd를 실행할 수 없습니다.

루트가 아닌 사용자로 rsyslogd를 실행하면 다음과 같은 오류가 표시됩니다. 하지만 RHEL에서는 이 작업을 수행할 수 있습니다(8과 9를 시도했습니다).

[drizzlex@ray myrsyslog]$ rsyslogd -f /home/drizzlex/myrsyslog/myrsyslog.conf -i /home/drizzlex/myrsyslog/run/myrsyslog.pid
rsyslog internal message (3,-2455): could not transfer  the  specified  internal posix  capabilities settings to the kernel, capng_apply=-5
 [v8.2102.0-113.el9 try https://www.rsyslog.com/e/2455 ]

이것이 내 conf 파일의 모습입니다

[drizzlex@ray myrsyslog]$ cat myrsyslog.conf 
module(load="imtcp")
input(type="imtcp" port="6601")

*.* /home/drizzlex/myrsyslog/mylog

답변1

rsyslogd이는 누구나 루트 권한 없이 실행할 수 없도록 하는 불행한 변화인 것 같습니다 . 코드는 여기

if ((capng_rc = capng_apply(CAPNG_SELECT_BOTH)) != 0) {
  LogError(0, RS_RET_LIBCAPNG_ERR,
   "could not transfer  the  specified  internal posix  capabilities "
   "settings to the kernel, capng_apply=%d\n", capng_rc);
  exit(-1);
}

CAP_SETUID그러나 13가지 필수 기능은 매우 광범위하며 대부분의 사용자에게는 ID 변경을 허용하는 등의 기능이 없습니다 .

분명히 이 코드는 좋은 아이디어이며 rsyslogd가 루트로 시작된 경우 필요한 기능을 제외한 모든 기능을 제거합니다. 그러나 루트가 아닌 사용자로 시작하거나 특정 기능이 없으면 호출은 exit()잔인합니다.

해결책은 소스에서 rsyslogd를 다운로드하고 구성 옵션 --enable-libcap-ng(기본적으로 존재하지 않음)을 추가하지 않고 다시 빌드하는 것입니다.

capng_apply()또는 0을 반환하도록 간단한 shim-dummy 호출을 만들 수 있습니다 . shim_capng.c다음 내용으로 파일을 만듭니다 .

/*
 * capture calls to a routine and replace with your code
 * https://unix.stackexchange.com/a/747252/119298
 * gcc -Wall -O2 -fpic -shared -ldl -o shim_capng.so shim_capng.c
 * LD_PRELOAD=/path/to/shim_capng.so rsyslogd
 */
#include <stdlib.h>
#include <stdio.h>
#include <cap-ng.h>

int capng_apply(capng_select_t set){
    fprintf(stderr, "not calling real capng_apply\n");
    return 0;
}

그리고 그것을 컴파일

gcc -Wall -O2 -fpic -shared -ldl -o shim_capng.so shim_capng.c

포함 파일을 얻으려면 일부 패키지를 설치해야 할 수도 있습니다. 예를 들어 libcap-ng-devel이름은 배포판에 따라 다릅니다 cap-ng.h.

rsyslogd 명령을 다음으로 바꾸십시오.

LD_PRELOAD=/path/to/shim_capng.so rsyslogd ...

관련 정보