@@ -33,9 +33,11 @@ const (
3333 linuxPrivilegedUpdateHelperPath = "/usr/local/libexec/noderax-agent-self-update"
3434 linuxRootProfileHelperPath = "/usr/local/libexec/noderax-agent-root-profile"
3535 linuxPackageMutationHelperPath = "/usr/local/libexec/noderax-agent-package-mutation"
36+ linuxOperationalLogScanHelperPath = "/usr/local/libexec/noderax-agent-operational-log-scan"
3637 linuxTaskRootHelperPath = "/usr/local/libexec/noderax-agent-task-root"
3738 linuxPrivilegedUpdateRequestPath = linuxServiceHome + "/update-request.json"
3839 linuxPackageMutationRequestPath = linuxServiceHome + "/package-mutation-request.txt"
40+ linuxOperationalLogScanRequestPath = linuxServiceHome + "/operational-log-scan-request.json"
3941 linuxTaskRootRequestPath = linuxServiceHome + "/task-root-request.txt"
4042 linuxConfigPath = "/etc/noderax-agent/config.json"
4143 linuxStatePath = "/var/lib/noderax-agent/agent_identity.json"
@@ -63,6 +65,7 @@ type platformSpec struct {
6365 PrivilegedUpdateHelperPath string
6466 RootProfileHelperPath string
6567 PackageMutationHelperPath string
68+ OperationalLogScanHelperPath string
6669 TaskRootHelperPath string
6770 BaseSudoersPath string
6871 RootAccessSudoersPath string
@@ -247,6 +250,9 @@ func (c CLI) Install(ctx context.Context, args []string) error {
247250 if err := writePackageMutationHelper (spec ); err != nil {
248251 return fmt .Errorf ("write package mutation helper: %w" , err )
249252 }
253+ if err := writeOperationalLogScanHelper (spec ); err != nil {
254+ return fmt .Errorf ("write operational log scan helper: %w" , err )
255+ }
250256 if err := writeTaskRootHelper (spec ); err != nil {
251257 return fmt .Errorf ("write task root helper: %w" , err )
252258 }
@@ -426,6 +432,18 @@ func (c CLI) Uninstall(ctx context.Context) error {
426432 packageMutationHelperRemoved ,
427433 )
428434
435+ operationalLogScanHelperRemoved , err := removeFileIfExists (spec .OperationalLogScanHelperPath )
436+ if err != nil {
437+ return err
438+ }
439+ recordRemovalResult (
440+ & removed ,
441+ & missing ,
442+ "operational log scan helper" ,
443+ spec .OperationalLogScanHelperPath ,
444+ operationalLogScanHelperRemoved ,
445+ )
446+
429447 taskRootHelperRemoved , err := removeFileIfExists (spec .TaskRootHelperPath )
430448 if err != nil {
431449 return err
@@ -615,6 +633,7 @@ func currentPlatformSpec() (platformSpec, error) {
615633 PrivilegedUpdateHelperPath : linuxPrivilegedUpdateHelperPath ,
616634 RootProfileHelperPath : linuxRootProfileHelperPath ,
617635 PackageMutationHelperPath : linuxPackageMutationHelperPath ,
636+ OperationalLogScanHelperPath : linuxOperationalLogScanHelperPath ,
618637 TaskRootHelperPath : linuxTaskRootHelperPath ,
619638 BaseSudoersPath : linuxBaseSudoersPath ,
620639 RootAccessSudoersPath : linuxRootAccessSudoersPath ,
@@ -638,6 +657,7 @@ func currentPlatformSpec() (platformSpec, error) {
638657 PrivilegedUpdateHelperPath : "" ,
639658 RootProfileHelperPath : "" ,
640659 PackageMutationHelperPath : "" ,
660+ OperationalLogScanHelperPath : "" ,
641661 TaskRootHelperPath : "" ,
642662 BaseSudoersPath : "" ,
643663 RootAccessSudoersPath : "" ,
@@ -1223,6 +1243,24 @@ func writePackageMutationHelper(spec platformSpec) error {
12231243 return nil
12241244}
12251245
1246+ func writeOperationalLogScanHelper (spec platformSpec ) error {
1247+ path := strings .TrimSpace (spec .OperationalLogScanHelperPath )
1248+ if path == "" {
1249+ return nil
1250+ }
1251+
1252+ if err := os .MkdirAll (filepath .Dir (path ), 0o755 ); err != nil {
1253+ return fmt .Errorf ("create helper directory for %s: %w" , path , err )
1254+ }
1255+
1256+ content := renderOperationalLogScanHelper (spec )
1257+ if err := os .WriteFile (path , []byte (content ), 0o755 ); err != nil {
1258+ return fmt .Errorf ("write helper %s: %w" , path , err )
1259+ }
1260+
1261+ return nil
1262+ }
1263+
12261264func writeTaskRootHelper (spec platformSpec ) error {
12271265 path := strings .TrimSpace (spec .TaskRootHelperPath )
12281266 if path == "" {
@@ -1414,6 +1452,28 @@ esac
14141452` , spec .PackageMutationHelperPath , linuxPackageMutationRequestPath )
14151453}
14161454
1455+ func renderOperationalLogScanHelper (spec platformSpec ) string {
1456+ return fmt .Sprintf (`#!/bin/sh
1457+ set -eu
1458+
1459+ HELPER_PATH=%q
1460+ REQUEST_FILE=%q
1461+ AGENT_BINARY=%q
1462+
1463+ if [ "$#" -ne 0 ]; then
1464+ echo "usage: ${HELPER_PATH}" >&2
1465+ exit 64
1466+ fi
1467+
1468+ if [ ! -f "${REQUEST_FILE}" ]; then
1469+ echo "operational log scan request file is missing" >&2
1470+ exit 1
1471+ fi
1472+
1473+ exec "${AGENT_BINARY}" log-scan --request "${REQUEST_FILE}"
1474+ ` , spec .OperationalLogScanHelperPath , linuxOperationalLogScanRequestPath , spec .BinaryPath )
1475+ }
1476+
14171477func renderTaskRootHelper (spec platformSpec ) string {
14181478 return fmt .Sprintf (`#!/bin/sh
14191479set -eu
@@ -1483,6 +1543,7 @@ SERVICE_USER=%q
14831543SERVICE_NAME=%q
14841544SUDOERS_FILE=%q
14851545PACKAGE_MUTATION_HELPER=%q
1546+ OPERATIONAL_LOG_SCAN_HELPER=%q
14861547TASK_ROOT_HELPER=%q
14871548
14881549if [ "$#" -ne 2 ] || [ "$1" != "apply" ]; then
@@ -1529,6 +1590,11 @@ append_operational_profile() {
15291590 append_alias "NODERAX_AGENT_PACKAGE_MUTATIONS"
15301591 fi
15311592
1593+ if [ -x "${OPERATIONAL_LOG_SCAN_HELPER}" ]; then
1594+ append_line "Cmnd_Alias NODERAX_AGENT_OPERATIONAL_LOG_SCAN = ${OPERATIONAL_LOG_SCAN_HELPER}"
1595+ append_alias "NODERAX_AGENT_OPERATIONAL_LOG_SCAN"
1596+ fi
1597+
15321598 if [ -n "${SYSTEMCTL_PATH}" ]; then
15331599 append_line "Cmnd_Alias NODERAX_AGENT_SERVICE_CONTROL = ${SYSTEMCTL_PATH} restart ${SERVICE_NAME}, ${SYSTEMCTL_PATH} restart ${SERVICE_NAME%%.service}"
15341600 append_alias "NODERAX_AGENT_SERVICE_CONTROL"
@@ -1628,7 +1694,7 @@ if command -v visudo >/dev/null 2>&1; then
16281694fi
16291695
16301696install -o root -g root -m 0440 "${TMP_FILE}" "${SUDOERS_FILE}"
1631- ` , spec .RootProfileHelperPath , spec .ServiceUser , spec .ServiceName , spec .RootAccessSudoersPath , spec .PackageMutationHelperPath , spec .TaskRootHelperPath )
1697+ ` , spec .RootProfileHelperPath , spec .ServiceUser , spec .ServiceName , spec .RootAccessSudoersPath , spec .PackageMutationHelperPath , spec .OperationalLogScanHelperPath , spec . TaskRootHelperPath )
16321698}
16331699
16341700func writeServiceUnit (path , content string ) error {
0 commit comments