pub struct HmacAuthPlugin {
access_key: Option<String>,
secret_key: Option<String>,
algorithm: HmacAlgorithm,
clock_skew: u64,
signed_headers: Vec<String>,
use_consumers: bool,
anonymous_consumer: Option<String>,
keep_headers: bool,
hide_credentials: bool,
realm: String,
resources: Arc<PluginResources>,
}Expand description
Authenticates requests by verifying an HMAC signature over a canonical signing string.
With inline access_key/secret_key a single credential is accepted. With
use_consumers: true the presented access_key is resolved against the
gateway’s consumers: section (their hmac-auth: {access_key, secret_key}
credentials) and, on a valid signature, the consumer’s identity is attached
to the request. Both may be enabled together — the inline key is checked
first.
Fields§
§access_key: Option<String>Inline credential access key (the keyId), if configured.
secret_key: Option<String>Inline secret paired with access_key.
algorithm: HmacAlgorithmThe single algorithm this node accepts.
clock_skew: u64Maximum allowed difference between the Date header and now, in
seconds; 0 disables the check.
signed_headers: Vec<String>Header names the client MUST have included in its signature.
use_consumers: boolWhen true, keys are also resolved against the consumer store.
anonymous_consumer: Option<String>Consumer attached when no credential matches (instead of rejecting).
keep_headers: boolWhen false (default), the X-HMAC-* proof headers are stripped before proxying upstream.
hide_credentials: boolWhen true, the Authorization header is stripped before proxying.
realm: StringRealm advertised in the WWW-Authenticate challenge.
resources: Arc<PluginResources>Implementations§
Source§impl HmacAuthPlugin
impl HmacAuthPlugin
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:
use_consumers(bool, defaultfalse): resolve theaccess_keyagainst the gateway’sconsumers:section and attach the consumer.access_key(string, optional): inline single-credential key id.secret_key(string, required whenaccess_keyis set): the paired secret.- At least one of
access_key/use_consumersmust be provided. algorithm(string, default"hmac-sha256"): one ofhmac-sha1,hmac-sha256,hmac-sha512.clock_skew(integer seconds, default300): maxDatedrift;0disables the check.signed_headers(array of strings, optional): headers the client must have signed; a request omitting any is rejected.keep_headers(bool, defaultfalse): keep theX-HMAC-*proof headers when proxying (they are stripped by default).hide_credentials(bool, defaultfalse): strip theAuthorizationheader before proxying.anonymous_consumer(string, optional): consumer attached when no credential matches, instead of rejecting.realm(string, default"hmac"):WWW-Authenticaterealm.
type: hmac-auth
config:
use_consumers: true
algorithm: hmac-sha256
clock_skew: 300
signed_headers: [date]Sourcefn reject(
&self,
ctx: Context,
msg: &str,
) -> Result<PluginOutput, PluginExecutionError>
fn reject( &self, ctx: Context, msg: &str, ) -> Result<PluginOutput, PluginExecutionError>
Builds the 401 rejection routed through the error port with code
HMAC_INVALID.
Sourcefn header<'a>(ctx: &'a Context, name: &str) -> Option<&'a str>
fn header<'a>(ctx: &'a Context, name: &str) -> Option<&'a str>
Reads a single-valued request header (lowercased key).
Sourcefn retrieve_params(ctx: &Context) -> Option<HmacParams>
fn retrieve_params(ctx: &Context) -> Option<HmacParams>
Extracts the signature parameters from the Authorization: Signature
header or, failing that, the X-HMAC-* headers.
Parses the comma-separated keyId="..",algorithm="..",headers="..",signature=".."
field list (the part after Signature ).
Sourcefn request_uri(ctx: &Context) -> String
fn request_uri(ctx: &Context) -> String
Reconstructs the request URI (path plus a sorted query string) used for
the @request-target pseudo-header.
Sourcefn signing_string(&self, ctx: &Context, params: &HmacParams) -> String
fn signing_string(&self, ctx: &Context, params: &HmacParams) -> String
Builds the canonical signing string from the presented signed headers.
Sourcefn verify_signature(
&self,
ctx: &Context,
params: &HmacParams,
secret: &str,
) -> bool
fn verify_signature( &self, ctx: &Context, params: &HmacParams, secret: &str, ) -> bool
Verifies the client signature against the recomputed one.
Sourcefn validate_common(
&self,
ctx: &Context,
params: &HmacParams,
) -> Result<(), String>
fn validate_common( &self, ctx: &Context, params: &HmacParams, ) -> Result<(), String>
Enforces the algorithm, clock skew, and required signed headers common
to both credential sources. Returns Err(reason) on any violation.
Sourcefn strip_headers(&self, ctx: &mut Context)
fn strip_headers(&self, ctx: &mut Context)
Strips the proof/credential headers per keep_headers/hide_credentials.
Source§impl HmacAuthPlugin
impl HmacAuthPlugin
Sourcefn attach_anonymous(
&self,
ctx: Context,
) -> Result<PluginOutput, PluginExecutionError>
fn attach_anonymous( &self, ctx: Context, ) -> Result<PluginOutput, PluginExecutionError>
Attaches the configured anonymous consumer, or rejects if it is unknown.
Trait Implementations§
Source§impl Plugin for HmacAuthPlugin
impl Plugin for HmacAuthPlugin
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 HmacAuthPlugin
impl !RefUnwindSafe for HmacAuthPlugin
impl Send for HmacAuthPlugin
impl Sync for HmacAuthPlugin
impl Unpin for HmacAuthPlugin
impl UnsafeUnpin for HmacAuthPlugin
impl !UnwindSafe for HmacAuthPlugin
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