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

log/syslog: local messages (syslog.New()) do not work on macOS Monterey/Ventura #59229

Open
craig65535 opened this issue Mar 24, 2023 · 3 comments
Labels
help wanted NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. OS-Darwin
Milestone

Comments

@craig65535
Copy link

craig65535 commented Mar 24, 2023

What version of Go are you using (go version)?

$ go version
1.18.10

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

darwin/arm64

$ sw_vers
ProductName:            macOS
ProductVersion:         13.2.1
BuildVersion:           22D68

What did you do?

package main

import (
	"log/syslog"
)

func main() {
	msgStr := `hello`
	w, err := syslog.New(syslog.LOG_WARNING|syslog.LOG_DAEMON, ``)
	if err != nil {
		panic(err)
	}
	w.Err(msgStr)
	w.Close()
}

What did you expect to see?

hello logged to the macOS Console.app

What did you see instead?

Nothing is logged.

I noticed that I can get this working with cgo -

package main

// #include <syslog.h>
// void doLog(int facility, const char *msg) {
//	syslog(facility, "%s", msg);
//}
import "C"

func main() {
	msgStr := `hello`
	C.doLog(C.LOG_ERR|C.LOG_DAEMON, C.CString(msgStr))
}

So syslog is working and this is not a configuration issue. I think the problem is that macOS's logd no longer accepts syslog messages on /var/run/syslog, or perhaps the expected format has changed.

I can see that it's listening:

$ sudo lsof|grep var/run/syslog
launchd       1                  root    3u     unix 0x3a45c3be17aa6ff3          0t0                     /private//var/run/syslog
logd        313                  root    7u     unix 0x3a45c3be17aa6ff3          0t0                     /private//var/run/syslog

But I'm not sure if calling syslog(3) is using some other mechanism to reach logd.

@craig65535
Copy link
Author

This was noted by the Python people: python/cpython#91070

@craig65535 craig65535 changed the title log/syslog: local messages (syslog.New()) do not work on Darwin log/syslog: local messages (syslog.New()) do not work on macOS Monterey/Ventura Mar 26, 2023
@mdempsky mdempsky added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 27, 2023
@mdempsky mdempsky added this to the Go1.21 milestone Mar 27, 2023
@craig65535
Copy link
Author

FWIW I do have a (terrible) workaround for this that doesn't involve cgo. I exec /usr/bin/logger -p <facility>.<severity> and then feed it messages over stdin. It doesn't tag the messages as coming from my process, but it does get logs into the Console and log store.

@mauri870
Copy link
Member

mauri870 commented Jul 19, 2023

This should at least be documented properly, something akin to this by the python folks:

   .. note:: On macOS 12.x (Monterey), Apple has changed the behaviour of their
      syslog daemon - it no longer listens on a domain socket. Therefore, you cannot
      expect :class:`SysLogHandler` to work on this system.

      See :gh:`91070` for more information.

@gopherbot gopherbot modified the milestones: Go1.21, Go1.22 Aug 8, 2023
jaysoffian pushed a commit to jaysoffian/pam-ysshca that referenced this issue Aug 31, 2023
Use raw syscalls to retrieve the command line under Darwin, since macOS
does not provide a `/proc` filesystem.

The code to do this is from https://github.com/elastic/go-sysinfo which
can be sanity checked against:

https://github.com/apple-oss-distributions/adv_cmds/blob/adv_cmds-205/ps/print.c#L115

I've verified with these changes that `pam_sshca.so` works as expected
under macOS 13 (Ventura) on an arm64 host.

Issues:

1. The Linux `pam.d/sudo` configuration line:

       "auth   [success=done default=die]   pam_sshca.so"

   Does not work on Darwin. Instead use one of the following:

       "auth   requisite   /path/to/pam_sshca.so"

   Or:

       "auth   required   /path/to/pam_sshca.so"

    Neither is identical to "[success=done default=die]" whose
    semantics are impossible under Darwin. See the `pam.conf` man pages
    on Linux and macOS for details.

2. The "log/syslog" module does not work under macOS >= 12 (Monterey).
   Log messages are silently dropped:

   golang/go#59229

3. The `kern.procargs2` syscall panics under macOS 10.15 (Catalina) due
   to a bug in that OS version.

   elastic/go-sysinfo#173
jaysoffian pushed a commit to jaysoffian/pam-ysshca that referenced this issue Aug 31, 2023
Use raw syscalls to retrieve the command line under Darwin, since macOS
does not provide a `/proc` filesystem.

The code to do this is from https://github.com/elastic/go-sysinfo which
can be sanity checked against:

https://github.com/apple-oss-distributions/adv_cmds/blob/adv_cmds-205/ps/print.c#L115

I've verified with these changes that `pam_sshca.so` works as expected
under macOS 13 (Ventura) on an arm64 host.

Issues:

1. The Linux `pam.d/sudo` configuration line:

       "auth   [success=done default=die]   pam_sshca.so"

   Does not work on Darwin. Instead use one of the following:

       "auth   requisite   /path/to/pam_sshca.so"

   Or:

       "auth   required   /path/to/pam_sshca.so"

    Neither is identical to "[success=done default=die]" whose
    semantics are impossible under Darwin. See the `pam.conf` man pages
    on Linux and macOS for details.

2. The "log/syslog" module does not work under macOS >= 12 (Monterey).
   Log messages are silently dropped:

   golang/go#59229

3. The `kern.procargs2` syscall returns incorrect data under macOS
   10.15 (Catalina) due to a bug in that OS version. The code won't
   panic under that OS version but it won't return a command line:

   - elastic/go-sysinfo#172
   - elastic/go-sysinfo#173
jaysoffian pushed a commit to jaysoffian/pam-ysshca that referenced this issue Aug 31, 2023
Use raw syscalls to retrieve the command line under Darwin, since macOS
does not provide a `/proc` filesystem.

The code to do this is from https://github.com/elastic/go-sysinfo which
can be sanity checked against:

https://github.com/apple-oss-distributions/adv_cmds/blob/adv_cmds-205/ps/print.c#L115

I've verified with these changes that `pam_sshca.so` works as expected
under macOS 13 (Ventura) on an arm64 host.

Issues:

1. The Linux `pam.d/sudo` configuration line:

       "auth   [success=done default=die]   pam_sshca.so"

   Does not work on Darwin. Instead use one of the following:

       "auth   requisite   /path/to/pam_sshca.so"

   Or:

       "auth   required   /path/to/pam_sshca.so"

    Neither is identical to `[success=done default=die]` whose
    semantics are impossible under Darwin. See the `pam.conf` man pages
    on Linux and macOS for details.

2. The `log/syslog` module does not work under macOS >= 12 (Monterey).
   Log messages are silently dropped:

   golang/go#59229

3. The `kern.procargs2` syscall returns incorrect data under macOS
   10.15 (Catalina) due to a bug in that OS version. The code won't
   panic under that OS version but it won't return a command line:

   elastic/go-sysinfo#172
@odeke-em odeke-em modified the milestones: Go1.22, Go1.23 Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. OS-Darwin
Projects
None yet
Development

No branches or pull requests

6 participants