pub struct ForwardAuthPlugin {
uri: String,
method: Method,
is_post: bool,
request_headers: Vec<String>,
upstream_headers: Vec<String>,
client_headers: Vec<String>,
extra_headers: Vec<(String, String)>,
ssl_verify: bool,
timeout: Duration,
status_on_error: u16,
allow_degradation: bool,
client: Arc<OutboundClient>,
}Expand description
Sends each request to an external authorization endpoint and routes on its verdict: 2xx continues (success port), non-2xx or (non-degrading) callout failure rejects (error port).
Fields§
§uri: StringExternal authorization endpoint.
method: MethodCallout method (GET or POST); POST forwards the client body.
is_post: boolWhether the callout is a POST (forwards the client body).
request_headers: Vec<String>Client request header names copied onto the callout (lowercased).
upstream_headers: Vec<String>Auth-response header names copied onto the request forwarded upstream on success (lowercased).
client_headers: Vec<String>Auth-response header names copied onto the client-facing response on failure (lowercased).
extra_headers: Vec<(String, String)>Extra callout headers whose values may reference $var templates.
ssl_verify: boolTLS certificate verification for https callouts.
timeout: DurationWhole-call callout deadline.
status_on_error: u16Status returned when the callout fails and degradation is disabled.
allow_degradation: boolWhen true, a callout failure lets the request through instead of rejecting it.
client: Arc<OutboundClient>Shared pooled HTTP client (from PluginResources).
Implementations§
Source§impl ForwardAuthPlugin
impl ForwardAuthPlugin
Sourcepub fn from_config(
config: &HashMap<String, Value>,
resources: &Arc<PluginResources>,
) -> Result<Self, String>
pub fn from_config( config: &HashMap<String, Value>, resources: &Arc<PluginResources>, ) -> Result<Self, String>
Builds the plugin from node config.
Accepted keys:
uri(string, required): external authorization endpoint. A missinguriis a config-load error.request_method(string, defaultGET): callout method;GETorPOST. WhenPOST, the buffered client body is forwarded and the client’sContent-Encodingheader is preserved on the callout.request_headers(array of strings, default[]): client header names forwarded to the authorization service (looked up case-insensitively).upstream_headers(array of strings, default[]): auth-response header names copied onto the request forwarded upstream on success. A configured name absent from the auth response removes any client-supplied value.client_headers(array of strings, default[]): auth-response header names copied onto the client-facing response on failure.extra_headers(object of string→string, optional): additional callout headers; values support$var/${var}interpolation (e.g.$remote_addr,$request_uri).ssl_verify(bool, defaulttrue): verify TLS certificates forhttpscallouts.timeout(integer ms, default3000): whole-call callout deadline.status_on_error(integer, default403): status returned when the callout fails andallow_degradationis false.allow_degradation(bool, defaultfalse): when true, a callout failure lets the request continue instead of rejecting it.
type: forward-auth
config:
uri: http://auth-service:8080/verify
request_method: GET
request_headers: [authorization, cookie]
upstream_headers: [x-user-id]
client_headers: [www-authenticate]
ssl_verify: true
timeout: 3000
status_on_error: 403
allow_degradation: falseSourcefn build_callout_headers(&self, ctx: &Context) -> Vec<(String, String)>
fn build_callout_headers(&self, ctx: &Context) -> Vec<(String, String)>
Builds the header list sent on the callout to the authorization
service: the X-Forwarded-* forwarding set, Content-Encoding for
POST, any interpolated extra_headers, and the configured
request_headers copied from the client request.
Sourcefn apply_allow(
&self,
ctx: &mut Context,
resp_headers: &HashMap<String, Vec<String>>,
)
fn apply_allow( &self, ctx: &mut Context, resp_headers: &HashMap<String, Vec<String>>, )
On a 2xx auth reply, copies the configured upstream_headers from the
auth response onto the request forwarded upstream. A configured header
absent from the auth response removes any client-supplied value.
Sourcefn build_deny(
&self,
ctx: Context,
status: u16,
body: Bytes,
resp_headers: &HashMap<String, Vec<String>>,
) -> PluginExecutionError
fn build_deny( &self, ctx: Context, status: u16, body: Bytes, resp_headers: &HashMap<String, Vec<String>>, ) -> PluginExecutionError
On a non-2xx auth reply, mirrors the auth service’s status and body onto
the client-facing response, copies the configured client_headers, and
returns the FORWARD_AUTH_DENIED rejection carrying the context.
Sourcefn build_error(&self, ctx: Context, message: String) -> PluginExecutionError
fn build_error(&self, ctx: Context, message: String) -> PluginExecutionError
Builds the FORWARD_AUTH_ERROR rejection used when the callout fails
and degradation is disabled.
Trait Implementations§
Source§impl Plugin for ForwardAuthPlugin
impl Plugin for ForwardAuthPlugin
Source§fn plugin_type(&self) -> &str
fn plugin_type(&self) -> &str
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl Freeze for ForwardAuthPlugin
impl !RefUnwindSafe for ForwardAuthPlugin
impl Send for ForwardAuthPlugin
impl Sync for ForwardAuthPlugin
impl Unpin for ForwardAuthPlugin
impl UnsafeUnpin for ForwardAuthPlugin
impl !UnwindSafe for ForwardAuthPlugin
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more