-
Notifications
You must be signed in to change notification settings - Fork 52
feat: enrich Check span with auth decision attributes #670
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
Open
asanzgom
wants to merge
2
commits into
Kuadrant:main
Choose a base branch
from
asanzgom:feat/check-span-enrichment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+232
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import ( | |
|
|
||
| "github.com/kuadrant/authorino/pkg/auth" | ||
| "github.com/kuadrant/authorino/pkg/context" | ||
| "github.com/kuadrant/authorino/pkg/evaluators" | ||
| "github.com/kuadrant/authorino/pkg/index" | ||
| "github.com/kuadrant/authorino/pkg/log" | ||
| "github.com/kuadrant/authorino/pkg/metrics" | ||
|
|
@@ -23,7 +24,9 @@ import ( | |
| envoy_type "github.com/envoyproxy/go-control-plane/envoy/type/v3" | ||
| "github.com/gogo/googleapis/google/rpc" | ||
| "github.com/google/uuid" | ||
| otel_attr "go.opentelemetry.io/otel/attribute" | ||
| otel_codes "go.opentelemetry.io/otel/codes" | ||
| otel_trace "go.opentelemetry.io/otel/trace" | ||
| rpcstatus "google.golang.org/genproto/googleapis/rpc/status" | ||
| "google.golang.org/protobuf/types/known/structpb" | ||
| v1 "k8s.io/api/admission/v1" | ||
|
|
@@ -251,6 +254,7 @@ func (a *AuthService) Check(parentContext gocontext.Context, req *envoy_auth.Che | |
| span.RecordError(err) | ||
| span.SetStatus(otel_codes.Error, err.Error()) | ||
| result := auth.AuthResult{Code: rpc.INVALID_ARGUMENT, Message: RESPONSE_MESSAGE_INVALID_REQUEST} | ||
| setAuthResultSpanAttrs(span, result) | ||
| return a.deniedResponse(result), nil | ||
| } | ||
|
|
||
|
|
@@ -284,12 +288,19 @@ func (a *AuthService) Check(parentContext gocontext.Context, req *envoy_auth.Che | |
| // If we couldn't find the AuthConfig in the config, we return and deny. | ||
| if authConfig == nil { | ||
| result := auth.AuthResult{Code: rpc.NOT_FOUND, Message: RESPONSE_MESSAGE_SERVICE_NOT_FOUND} | ||
| setAuthResultSpanAttrs(span, result) | ||
| a.logAuthResult(result, ctx) | ||
| return a.deniedResponse(result), nil | ||
| } | ||
|
|
||
| span.SetAttributes( | ||
| otel_attr.String(trace.AuthConfigNameAttr, authConfig.Labels["authconfig"]), | ||
| otel_attr.String(trace.AuthConfigNamespaceAttr, authConfig.Labels["namespace"]), | ||
| ) | ||
|
|
||
| if err := context.CheckContext(ctx); err != nil { | ||
| result := auth.AuthResult{Code: rpc.UNAVAILABLE} | ||
| setAuthResultSpanAttrs(span, result) | ||
| a.logAuthResult(result, ctx) | ||
| context.Cancel(ctx) | ||
| span.RecordError(err) | ||
|
|
@@ -308,6 +319,17 @@ func (a *AuthService) Check(parentContext gocontext.Context, req *envoy_auth.Che | |
| span.SetStatus(otel_codes.Error, err.Error()) | ||
| } | ||
|
|
||
| setAuthResultSpanAttrs(span, result) | ||
|
|
||
| if idConfig, _ := pipeline.GetResolvedIdentity(); idConfig != nil { | ||
| if ic, ok := idConfig.(*evaluators.IdentityConfig); ok { | ||
| span.SetAttributes( | ||
| otel_attr.String(trace.IdentitySourceAttr, ic.GetName()), | ||
| otel_attr.String(trace.IdentityTypeAttr, ic.GetType()), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| a.logAuthResult(result, ctx) | ||
|
|
||
| if result.Success() { | ||
|
|
@@ -499,6 +521,18 @@ func closeWithStatus(respStatusCode envoy_type.StatusCode, response http.Respons | |
| context.Cancel(ctx) | ||
| } | ||
|
|
||
| func setAuthResultSpanAttrs(span otel_trace.Span, result auth.AuthResult) { | ||
| if result.Success() { | ||
| span.SetAttributes(otel_attr.String(trace.AuthResultAttr, "ALLOW")) | ||
| } else { | ||
| span.SetAttributes(otel_attr.String(trace.AuthResultAttr, "DENY")) | ||
| if result.Message != "" { | ||
| span.SetAttributes(otel_attr.String(trace.AuthDenialReasonAttr, result.Message)) | ||
| } | ||
| } | ||
| span.SetAttributes(otel_attr.String(trace.AuthResponseCodeAttr, result.Code.String())) | ||
| } | ||
|
Comment on lines
+524
to
+534
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs documentation at https://github.com/Kuadrant/authorino/blob/main/docs/user-guides/observability.md#data-plane-tracing. Other than the new attributes, a couple of things that seem important to get covered IMO:
|
||
|
|
||
| func ensureRequestId(requestIdCandidates ...string) string { | ||
| for _, requestId := range requestIdCandidates { | ||
| if requestId != "" { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should iterate over the AuthConfig labels and set them dynamically into the span, similarly to what we do with the metrics.
I understand the keys wouldn't be the same as proposed, but perhaps this is also an opportunity to standardise them across the different types of observability sources?
E.g.: