Support specifying log levels for the attributes in an OpenAPI spec #5174
ae-ou
started this conversation in
Enhancements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Currently, when I define an OpenAPI spec, there is no clear-cut way for me to specify (or consistently control) which attributes can/should be logged by the users of the spec. This means that there has to be an implicit level of trust that the user of the API spec will log the data appropriately - which presents a couple of problems:
print()statement in code that we only intended for use during debugging.openapi2kongtool.TLDR: In the absence of proper information about which attributes are loggable, users of OpenAPI specs have to practice self-restraint with logging. Whilst a cautious approach is good, it directly impacts observability - which can hinder debugging efforts. Furthermore, since this self-restraint falls to individual developers, there are inherent inconsistencies in approach, and there’s an ever-present risk of a slip-up resulting in the leaking of sensitive information.
Request
I would like to be able to specify logging expectations as part of an OpenAPI spec. This would allow us to move from implicitly trusting developers/services to handle logging (and any redaction that may need to occur), to explicitly declaring expectations around logging. I think that this would provide a few benefits:
Potential Approach
Suggested Changes to OpenAPI
I think that we should be able to specify logging expectations for individual object attributes inside of an OpenAPI schema - this could be done by adding a field called
loggability. Thisloggabilityfield could then beused to specify when an attribute can appear in logs (i.e. the log levels at which it can be added as a log field).
Potential Values for the
loggabilityFieldLog levels differ between programming languages and log packages, so we could base the values for
loggabilityon the OpenTelemetry severity levels. Since OpenTelemetry is a platform-agnostic open standard (backed by the CNCF), there shouldn't be any concerns about favouring a specific language/log package/service provider.It would make sense to only log an attribute when the
loggabilityfield is explicitly defined. This default behaviour is beneficial for two reasons:In addition to not logging attributes by default, we could add a value to represent explicitly denying the logging of a field (e.g.
DO_NOT_LOG). This would allow the maintainers of an OpenAPI spec to explicitly communicate that they do not want a field to be logged.Given the aforementioned considerations, the values for
loggabilitycould look like thisTRACETRACElevel.DEBUGDEBUGlevel or lower (i.e.DEBUGorTRACE).INFOINFOis the default log level. In comparison, the default for theloggabilityfield is to be unset, and when this field is unset, the corresponding attribute should not be logged at all.WARNERRORloggability: ERRORcould be added to the error log (assuming that the malformed payload is still parseable).FATAL/ unsetloggabilityfield (which is the default). If an attribute has nologgabilityfield defined, the attribute shouldn't be logged.DO_NOT_LOGSENSITIVE(or another value) instead, but this could be misinterpreted as an instruction to redact data.Examples
Error
In the above example, the
fruitattribute hasloggability: ERRORset on it - which means that the attribute can be added to logs that areERRORlevel or lower.With this configuration, we may log the attribute if a payload [containing the attribute] fails validation (e.g. if somebody specified
"fruit": "guava").Not Set/Default
In the above example, the
loggabilityfield hasn't been set on thecolourattribute - socolourshould never be output to logs.Do Not Log
In the above example, both
emailandmobileNumberhaveloggability: DO_NOT_LOG. This shows that a conscious decision has been made to prevent the logging of the attributes under any circumstances (since both attributes contain PII).Possible Language-specific Usages
Go
The
loggabilityfield could be used in multiple places when generating Go bindings for an OpenAPI spec:loggabilityfield. Struct tags are relatively free form, so purpose-specific struct tags could be set that suit individual needs.json:"-"on a struct field if there is a correspondingloggability: DO_NOT_LOGin the OpenAPI speclog/slogpackage defines aLogValuerinterface which allows developers to control how a struct should be logged - we could autogenerate implementations of this interface based on theloggabilityfields within the OpenAPI spec.LogValuerinterface can be used to hide sensitive fields.LogObjectMarshalerinterface which operates in a similar manner.Marshalerinterface in order to control how a struct is marshalled into JSON.Java
The
loggabilityfield could be used in multiple places when generating Java bindings for an OpenAPI spec:toString()method to control which fields are output/masked.Considerations
OpenAPI Extension
I was initially going to suggest this as an OpenAPI Extension since logging isn't fully related to OpenAPI, however, there are a few reasons that I'm suggesting it as part of the wider OpenAPI spec:
loggabilityfield (e.g.ERROR,DEBUG,DO_NOT_LOG) would extend the OpenTelemetry specification. Extending/altering a specification usually triggers debate, and I figured that suggesting thisloggabilityfield as a part of the wider OpenAPI specification would be more conducive to such a debate.traceparent,tracestate, andX-Request-IDheaders).Related Work/Issues
#4330 requested an
x-sensitive-datafield and suggested some excellent approaches for redacting sensitive data.My
loggability: DO_NOT_LOGfield would behave similarly to @cristigirbovan'sfullmasking proposal:Both of our suggestions would seek to completely eliminate specified fields from logs, but the difference is that my
loggability: DO_NOT_LOGfield isn't specific to sensitive data - it's for any field that we explicitly don't want to log.Whilst their proposal focuses on known sensitive data (and the most effective ways to redact it), my proposal
is focused on logging in general (including attributes that aren't sensitive). Realistically, our proposals are complimentary
since my proposal focuses on when to log attributes, and theirs focuses on how to log [known sensitive] attributes.
Hypothetically, our proposals could be combined into one overarching spec change that governs logging and redaction as
a whole. For example:
The above sample shows my proposal in conjunction with @cristigirbovan's
x-sensitive-dataproposal. Both of ourproposed fields have been centralised under the
loggingfield, thex-prefix has been removed, and I'm using myDO_NOT_LOGin lieu ofmask: full.Beta Was this translation helpful? Give feedback.
All reactions