-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tracing for authorization (#80815)
* Can be turned off with xpack.security.authz.tracing: false * AuthZ is tied to relevant task by traceparent (it however does not cover the first authZ) * x-opaque-id is auto configured at rest layer if not already exists. This helps chain all relevant actions together. * ApmIT now has security enabled.
- Loading branch information
Showing
12 changed files
with
237 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
73 changes: 73 additions & 0 deletions
73
...k/plugin/security/src/main/java/org/elasticsearch/xpack/security/AuthorizationTracer.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.security; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.message.ParameterizedMessage; | ||
import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
import org.elasticsearch.tracing.Traceable; | ||
import org.elasticsearch.tracing.Tracer; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
public class AuthorizationTracer { | ||
|
||
private static final Logger logger = LogManager.getLogger(AuthorizationTracer.class); | ||
|
||
private final ThreadContext threadContext; | ||
private final List<Tracer> tracers = new CopyOnWriteArrayList<>(); | ||
|
||
public AuthorizationTracer(ThreadContext threadContext) { | ||
this.threadContext = threadContext; | ||
} | ||
|
||
public void addTracer(Tracer tracer) { | ||
if (tracer != null) { | ||
tracers.add(tracer); | ||
} | ||
} | ||
|
||
public Runnable startTracing(Traceable traceable) { | ||
for (Tracer tracer : tracers) { | ||
try { | ||
tracer.onTraceStarted(traceable); | ||
} catch (Exception e) { | ||
assert false : e; | ||
logger.warn( | ||
new ParameterizedMessage( | ||
"authorization tracing listener [{}] failed on starting tracing of [{}][{}]", | ||
tracer, | ||
traceable.getSpanId(), | ||
traceable.getSpanName() | ||
), | ||
e | ||
); | ||
} | ||
} | ||
return () -> { | ||
for (Tracer tracer : tracers) { | ||
try { | ||
tracer.onTraceStopped(traceable); | ||
} catch (Exception e) { | ||
assert false : e; | ||
logger.warn( | ||
new ParameterizedMessage( | ||
"authorization tracing listener [{}] failed on stopping tracing of [{}][{}]", | ||
tracer, | ||
traceable.getSpanId(), | ||
traceable.getSpanName() | ||
), | ||
e | ||
); | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.