Add "json_pretty" log format, currently the same as "json".

In a future version, "json" will be an alias for "json_compact"
instead.  GitHub issue #357.
This commit is contained in:
Todd C. Miller
2024-03-09 10:59:54 -07:00
parent 1debad3bec
commit 46e31a74d7
14 changed files with 135 additions and 92 deletions

View File

@@ -16,7 +16,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.TH "SUDO_LOGSRVD.CONF" "@mansectform@" "March 8, 2024" "Sudo @PACKAGE_VERSION@" "File Formats Manual" .TH "SUDO_LOGSRVD.CONF" "@mansectform@" "March 9, 2024" "Sudo @PACKAGE_VERSION@" "File Formats Manual"
.nh .nh
.if n .ad l .if n .ad l
.SH "NAME" .SH "NAME"
@@ -688,30 +688,40 @@ Supported log formats are:
.PD 0 .PD 0
.TP 6n .TP 6n
json json
Log events in JSON format. Currently, this is an alias for
The JSON log entries contain the full contents of the accept, reject, exit \fIjson_pretty\fR.
In a future version of
\fBsudo_logsrvd\fR,
\fIjson\fR
will be equivalent to
\fIjson_compact\fR.
JSON log entries contain the full contents of the accept, reject, exit
and alert messages. and alert messages.
.PD
.TP 6n
json_compact
Log events in
\(lqcompact\(rq
(minified) JSON format.
Each event is written as a separate JSON object on single line without
extraneous white space.
Due to limitations of the protocol, JSON events sent via
\fIsyslog\fR
may be truncated.
.TP 6n
json_pretty
Log events in
\(lqpretty\(rq
JSON format.
When logging to a file, the entire file is treated as a single JSON When logging to a file, the entire file is treated as a single JSON
object consisting of multiple events, each event spanning multiple lines. object consisting of multiple events, each event spanning multiple lines.
When logging via When logging via
\fIsyslog\fR, \fIsyslog\fR,
events are stored in compact (minified) format, described below.
.PD
.TP 6n
json_compact
Log events in compact (minified) JSON format.
Each event is written as a separate JSON object on single line without
extraneous white space.
When logging via
\fIsyslog\fR,
there is no difference between the there is no difference between the
\fIjson\fR \fIjson_pretty\fR
and and
\fIjson_compact\fR \fIjson_compact\fR
formats. formats.
Due to limitations of the protocol, JSON events sent via
\fIsyslog\fR
may be truncated.
.TP 6n .TP 6n
sudo sudo
Log events in traditional sudo-style log format. Log events in traditional sudo-style log format.

View File

@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd March 8, 2024 .Dd March 9, 2024
.Dt SUDO_LOGSRVD.CONF @mansectform@ .Dt SUDO_LOGSRVD.CONF @mansectform@
.Os Sudo @PACKAGE_VERSION@ .Os Sudo @PACKAGE_VERSION@
.Sh NAME .Sh NAME
@@ -614,28 +614,37 @@ The event log format.
Supported log formats are: Supported log formats are:
.Bl -tag -width 4n .Bl -tag -width 4n
.It json .It json
Log events in JSON format. Currently, this is an alias for
The JSON log entries contain the full contents of the accept, reject, exit .Em json_pretty .
In a future version of
.Nm sudo_logsrvd ,
.Em json
will be equivalent to
.Em json_compact .
JSON log entries contain the full contents of the accept, reject, exit
and alert messages. and alert messages.
.It json_compact
Log events in
.Dq compact
(minified) JSON format.
Each event is written as a separate JSON object on single line without
extraneous white space.
Due to limitations of the protocol, JSON events sent via
.Em syslog
may be truncated.
.It json_pretty
Log events in
.Dq pretty
JSON format.
When logging to a file, the entire file is treated as a single JSON When logging to a file, the entire file is treated as a single JSON
object consisting of multiple events, each event spanning multiple lines. object consisting of multiple events, each event spanning multiple lines.
When logging via When logging via
.Em syslog , .Em syslog ,
events are stored in compact (minified) format, described below.
.It json_compact
Log events in compact (minified) JSON format.
Each event is written as a separate JSON object on single line without
extraneous white space.
When logging via
.Em syslog ,
there is no difference between the there is no difference between the
.Em json .Em json_pretty
and and
.Em json_compact .Em json_compact
formats. formats.
Due to limitations of the protocol, JSON events sent via
.Em syslog
may be truncated.
.It sudo .It sudo
Log events in traditional sudo-style log format. Log events in traditional sudo-style log format.
See the See the

View File

@@ -25,7 +25,7 @@
.nr BA @BAMAN@ .nr BA @BAMAN@
.nr LC @LCMAN@ .nr LC @LCMAN@
.nr PS @PSMAN@ .nr PS @PSMAN@
.TH "SUDOERS" "@mansectform@" "March 8, 2024" "Sudo @PACKAGE_VERSION@" "File Formats Manual" .TH "SUDOERS" "@mansectform@" "March 9, 2024" "Sudo @PACKAGE_VERSION@" "File Formats Manual"
.nh .nh
.if n .ad l .if n .ad l
.SH "NAME" .SH "NAME"
@@ -5381,30 +5381,40 @@ Supported log formats are:
.PD 0 .PD 0
.TP 6n .TP 6n
json json
Log events in JSON format. Currently, this is an alias for
\fIjson_pretty\fR.
In a future version of
\fBsudo\fR,
\fIjson\fR
will be equivalent to
\fIjson_compact\fR.
JSON log entries contain the full user details as well as the execution JSON log entries contain the full user details as well as the execution
environment if the command was allowed. environment if the command was allowed.
.PD
.TP 6n
json_compact
Log events in
\(lqcompact\(rq
(minified) JSON format.
Each event is written as a separate JSON object on single line without
extraneous white space.
Due to limitations of the protocol, JSON events sent via
\fIsyslog\fR
may be truncated.
.TP 6n
json_pretty
Log events in
\(lqpretty\(rq
JSON format.
When logging to a file, the entire file is treated as a single JSON When logging to a file, the entire file is treated as a single JSON
object consisting of multiple events, each event spanning multiple lines. object consisting of multiple events, each event spanning multiple lines.
When logging via When logging via
\fIsyslog\fR, \fIsyslog\fR,
events are stored in compact (minified) format, described below.
.PD
.TP 6n
json_compact
Log events in compact (minified) JSON format.
Each event is written as a separate JSON object on single line without
extraneous white space.
When logging via
\fIsyslog\fR,
there is no difference between the there is no difference between the
\fIjson\fR \fIjson_pretty\fR
and and
\fIjson_compact\fR \fIjson_compact\fR
formats. formats.
Due to limitations of the protocol, JSON events sent via
\fIsyslog\fR
may be truncated.
.TP 6n .TP 6n
sudo sudo
Log events in traditional sudo-style format, see Log events in traditional sudo-style format, see

View File

@@ -25,7 +25,7 @@
.nr BA @BAMAN@ .nr BA @BAMAN@
.nr LC @LCMAN@ .nr LC @LCMAN@
.nr PS @PSMAN@ .nr PS @PSMAN@
.Dd March 8, 2024 .Dd March 9, 2024
.Dt SUDOERS @mansectform@ .Dt SUDOERS @mansectform@
.Os Sudo @PACKAGE_VERSION@ .Os Sudo @PACKAGE_VERSION@
.Sh NAME .Sh NAME
@@ -5054,28 +5054,37 @@ The event log format.
Supported log formats are: Supported log formats are:
.Bl -tag -width 4n .Bl -tag -width 4n
.It json .It json
Log events in JSON format. Currently, this is an alias for
.Em json_pretty .
In a future version of
.Nm sudo ,
.Em json
will be equivalent to
.Em json_compact .
JSON log entries contain the full user details as well as the execution JSON log entries contain the full user details as well as the execution
environment if the command was allowed. environment if the command was allowed.
.It json_compact
Log events in
.Dq compact
(minified) JSON format.
Each event is written as a separate JSON object on single line without
extraneous white space.
Due to limitations of the protocol, JSON events sent via
.Em syslog
may be truncated.
.It json_pretty
Log events in
.Dq pretty
JSON format.
When logging to a file, the entire file is treated as a single JSON When logging to a file, the entire file is treated as a single JSON
object consisting of multiple events, each event spanning multiple lines. object consisting of multiple events, each event spanning multiple lines.
When logging via When logging via
.Em syslog , .Em syslog ,
events are stored in compact (minified) format, described below.
.It json_compact
Log events in compact (minified) JSON format.
Each event is written as a separate JSON object on single line without
extraneous white space.
When logging via
.Em syslog ,
there is no difference between the there is no difference between the
.Em json .Em json_pretty
and and
.Em json_compact .Em json_compact
formats. formats.
Due to limitations of the protocol, JSON events sent via
.Em syslog
may be truncated.
.It sudo .It sudo
Log events in traditional sudo-style format, see Log events in traditional sudo-style format, see
.Sx "EVENT LOGGING" .Sx "EVENT LOGGING"

View File

@@ -44,7 +44,8 @@ enum event_type {
enum eventlog_format { enum eventlog_format {
EVLOG_SUDO, EVLOG_SUDO,
EVLOG_JSON, EVLOG_JSON,
EVLOG_JSON_COMPACT EVLOG_JSON_COMPACT,
EVLOG_JSON_PRETTY
}; };
/* Eventlog flag values. */ /* Eventlog flag values. */

View File

@@ -1132,6 +1132,7 @@ do_syslog(int event_type, int flags, struct eventlog_args *args,
break; break;
case EVLOG_JSON: case EVLOG_JSON:
case EVLOG_JSON_COMPACT: case EVLOG_JSON_COMPACT:
case EVLOG_JSON_PRETTY:
ret = do_syslog_json(pri, event_type, args, evlog); ret = do_syslog_json(pri, event_type, args, evlog);
break; break;
default: default:
@@ -1304,6 +1305,7 @@ do_logfile(int event_type, int flags, struct eventlog_args *args,
break; break;
case EVLOG_JSON: case EVLOG_JSON:
case EVLOG_JSON_COMPACT: case EVLOG_JSON_COMPACT:
case EVLOG_JSON_PRETTY:
ret = do_logfile_json(evl_conf->format, event_type, args, evlog); ret = do_logfile_json(evl_conf->format, event_type, args, evlog);
break; break;
default: default:

View File

@@ -905,6 +905,8 @@ cb_eventlog_format(struct logsrvd_config *config, const char *str, size_t offset
config->eventlog.log_format = EVLOG_JSON; config->eventlog.log_format = EVLOG_JSON;
else if (strcmp(str, "json_compact") == 0) else if (strcmp(str, "json_compact") == 0)
config->eventlog.log_format = EVLOG_JSON_COMPACT; config->eventlog.log_format = EVLOG_JSON_COMPACT;
else if (strcmp(str, "json_pretty") == 0)
config->eventlog.log_format = EVLOG_JSON_PRETTY;
else if (strcmp(str, "sudo") == 0) else if (strcmp(str, "sudo") == 0)
config->eventlog.log_format = EVLOG_SUDO; config->eventlog.log_format = EVLOG_SUDO;
else else

View File

@@ -42,6 +42,7 @@ static struct def_values def_data_log_format[] = {
{ "sudo", sudo }, { "sudo", sudo },
{ "json", json }, { "json", json },
{ "json_compact", json_compact }, { "json_compact", json_compact },
{ "json_pretty", json_pretty },
{ NULL, 0 }, { NULL, 0 },
}; };

View File

@@ -339,6 +339,7 @@ enum def_tuple {
sudo, sudo,
json, json,
json_compact, json_compact,
json_pretty,
dso, dso,
trace trace
}; };

View File

@@ -426,7 +426,7 @@ runchroot
log_format log_format
T_TUPLE T_TUPLE
"The format of logs to produce: %s" "The format of logs to produce: %s"
sudo json json_compact sudo json json_compact json_pretty
selinux selinux
T_FLAG T_FLAG
"Enable SELinux RBAC support" "Enable SELinux RBAC support"

View File

@@ -1132,29 +1132,16 @@ sudoers_log_close(int type, FILE *fp)
void void
init_eventlog_config(void) init_eventlog_config(void)
{ {
enum eventlog_format format;
int logtype = 0; int logtype = 0;
debug_decl(init_eventlog_config, SUDOERS_DEBUG_LOGGING); debug_decl(init_eventlog_config, SUDOERS_DEBUG_LOGGING);
switch (def_log_format) {
case json:
format = EVLOG_JSON;
break;
case json_compact:
format = EVLOG_JSON_COMPACT;
break;
default:
format = EVLOG_SUDO;
break;
}
if (def_syslog) if (def_syslog)
logtype |= EVLOG_SYSLOG; logtype |= EVLOG_SYSLOG;
if (def_logfile) if (def_logfile)
logtype |= EVLOG_FILE; logtype |= EVLOG_FILE;
sudoers_set_log_format(def_log_format);
eventlog_set_type(logtype); eventlog_set_type(logtype);
eventlog_set_format(format);
eventlog_set_syslog_acceptpri(def_syslog_goodpri); eventlog_set_syslog_acceptpri(def_syslog_goodpri);
eventlog_set_syslog_rejectpri(def_syslog_badpri); eventlog_set_syslog_rejectpri(def_syslog_badpri);
eventlog_set_syslog_alertpri(def_syslog_badpri); eventlog_set_syslog_alertpri(def_syslog_badpri);

View File

@@ -1554,3 +1554,30 @@ sudoers_get_context(void)
{ {
return &sudoers_ctx; return &sudoers_ctx;
} }
bool
sudoers_set_log_format(enum def_tuple tuple)
{
enum eventlog_format format;
debug_decl(cb_log_format, SUDOERS_DEBUG_PLUGIN);
switch (tuple) {
case json:
format = EVLOG_JSON;
break;
case json_compact:
format = EVLOG_JSON_COMPACT;
break;
case json_pretty:
format = EVLOG_JSON_PRETTY;
break;
case sudo:
format = EVLOG_SUDO;
break;
default:
debug_return_bool(false);
}
eventlog_set_format(format);
debug_return_bool(true);
}

View File

@@ -459,6 +459,7 @@ void sudoers_cleanup(void);
bool sudoers_override_umask(void); bool sudoers_override_umask(void);
const struct sudoers_context *sudoers_get_context(void); const struct sudoers_context *sudoers_get_context(void);
bool sudoers_set_mode(unsigned int flags, unsigned int mask); bool sudoers_set_mode(unsigned int flags, unsigned int mask);
bool sudoers_set_log_format(enum def_tuple tuple);
/* sudoers_ctx_free.c */ /* sudoers_ctx_free.c */
void sudoers_ctx_free(struct sudoers_context *ctx); void sudoers_ctx_free(struct sudoers_context *ctx);

View File

@@ -228,24 +228,7 @@ static bool
cb_log_format(struct sudoers_context *ctx, const char *file, cb_log_format(struct sudoers_context *ctx, const char *file,
int line, int column, const union sudo_defs_val *sd_un, int op) int line, int column, const union sudo_defs_val *sd_un, int op)
{ {
enum eventlog_format format; return sudoers_set_log_format(sd_un->tuple);
debug_decl(cb_log_format, SUDOERS_DEBUG_PLUGIN);
switch (sd_un->tuple) {
case json:
format = EVLOG_JSON;
break;
case json_compact:
format = EVLOG_JSON_COMPACT;
break;
default:
format = EVLOG_SUDO;
break;
}
eventlog_set_format(format);
debug_return_bool(true);
} }
static bool static bool