Skip to content
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

Add Sigv4A support for the orchestrator #2890

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion aws/rust-runtime/aws-credential-types/src/credentials_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,21 @@ impl Credentials {
)
}

/// Creates a test `Credentials`.
/// Creates a test `Credentials` without a session token.
#[cfg(feature = "test-util")]
pub fn for_tests() -> Self {
Self::new(
"ANOTREAL",
"notrealrnrELgWzOk3IfjzDKtFBhDby",
None,
None,
"test",
)
}

/// Creates a test `Credentials` with a session token.
#[cfg(feature = "test-util")]
pub fn for_tests_with_session_token() -> Self {
Self::new(
"ANOTREAL",
"notrealrnrELgWzOk3IfjzDKtFBhDby",
Expand Down
36 changes: 18 additions & 18 deletions aws/rust-runtime/aws-endpoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use aws_smithy_types::endpoint::Endpoint as SmithyEndpoint;
use aws_smithy_types::Document;

use aws_types::region::{Region, SigningRegion};
use aws_types::SigningService;
use aws_types::SigningName;

/// Middleware Stage to add authentication information from a Smithy endpoint into the property bag
///
/// AwsAuthStage implements [`MapRequest`](MapRequest). It will:
/// 1. Load an endpoint from the property bag
/// 2. Set the `SigningRegion` and `SigningService` in the property bag to drive downstream
/// 2. Set the `SigningRegion` and `SigningName` in the property bag to drive downstream
/// signing middleware.
#[derive(Clone, Debug)]
pub struct AwsAuthStage;
Expand Down Expand Up @@ -74,21 +74,21 @@ impl MapRequest for AwsAuthStage {
let endpoint = props
.get::<aws_smithy_types::endpoint::Endpoint>()
.ok_or(AwsAuthStageErrorKind::NoEndpointResolver)?;
let (signing_scope_override, signing_service_override) = smithy_to_aws(endpoint)
let (signing_region_override, signing_name_override) = smithy_to_aws(endpoint)
.map_err(|err| AwsAuthStageErrorKind::EndpointResolutionError(err))?;

if let Some(signing_scope) = signing_scope_override {
if let Some(signing_scope) = signing_region_override {
props.insert(signing_scope);
}
if let Some(signing_service) = signing_service_override {
props.insert(signing_service);
if let Some(signing_name) = signing_name_override {
props.insert(signing_name);
}
Ok(http_req)
})
}
}

type EndpointMetadata = (Option<SigningRegion>, Option<SigningService>);
type EndpointMetadata = (Option<SigningRegion>, Option<SigningName>);

fn smithy_to_aws(value: &SmithyEndpoint) -> Result<EndpointMetadata, Box<dyn Error + Send + Sync>> {
// look for v4 as an auth scheme
Expand Down Expand Up @@ -122,17 +122,17 @@ fn smithy_to_aws(value: &SmithyEndpoint) -> Result<EndpointMetadata, Box<dyn Err
)
})?;

let signing_scope = match v4.get("signingRegion") {
let signing_region = match v4.get("signingRegion") {
Some(Document::String(s)) => Some(SigningRegion::from(Region::new(s.clone()))),
None => None,
_ => return Err("unexpected type".into()),
};
let signing_service = match v4.get("signingName") {
Some(Document::String(s)) => Some(SigningService::from(s.to_string())),
let signing_name = match v4.get("signingName") {
Some(Document::String(s)) => Some(SigningName::from(s.to_string())),
None => None,
_ => return Err("unexpected type".into()),
};
Ok((signing_scope, signing_service))
Ok((signing_region, signing_name))
}

#[cfg(test)]
Expand All @@ -147,7 +147,7 @@ mod test {
use http::header::HOST;

use aws_types::region::{Region, SigningRegion};
use aws_types::SigningService;
use aws_types::SigningName;

use crate::AwsAuthStage;

Expand All @@ -162,14 +162,14 @@ mod test {
{
let mut props = req.properties_mut();
props.insert(SigningRegion::from(region.clone()));
props.insert(SigningService::from_static("kinesis"));
props.insert(SigningName::from_static("kinesis"));
props.insert(endpoint);
};
let req = AwsAuthStage.apply(req).expect("should succeed");
assert_eq!(req.properties().get(), Some(&SigningRegion::from(region)));
assert_eq!(
req.properties().get(),
Some(&SigningService::from_static("kinesis"))
Some(&SigningName::from_static("kinesis"))
);

assert!(req.http().headers().get(HOST).is_none());
Expand Down Expand Up @@ -206,7 +206,7 @@ mod test {
{
let mut props = req.properties_mut();
props.insert(region);
props.insert(SigningService::from_static("qldb"));
props.insert(SigningName::from_static("qldb"));
props.insert(endpoint);
};
let req = AwsAuthStage.apply(req).expect("should succeed");
Expand All @@ -216,7 +216,7 @@ mod test {
);
assert_eq!(
req.properties().get(),
Some(&SigningService::from_static("qldb-override"))
Some(&SigningName::from_static("qldb-override"))
);
}

Expand All @@ -229,14 +229,14 @@ mod test {
{
let mut props = req.properties_mut();
props.insert(region.clone());
props.insert(SigningService::from_static("qldb"));
props.insert(SigningName::from_static("qldb"));
props.insert(endpoint);
};
let req = AwsAuthStage.apply(req).expect("should succeed");
assert_eq!(req.properties().get(), Some(&region));
assert_eq!(
req.properties().get(),
Some(&SigningService::from_static("qldb"))
Some(&SigningName::from_static("qldb"))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// This code is referenced in generated code, so the compiler doesn't realize it is used.
#![allow(dead_code)]

use aws_runtime::auth::sigv4::SigV4OperationSigningConfig;
use aws_runtime::auth::SigV4OperationSigningConfig;
use aws_sigv4::http_request::SignableBody;
use aws_smithy_http::body::SdkBody;
use aws_smithy_http::byte_stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! Interceptor for handling Smithy `@httpChecksum` request checksumming with AWS SigV4

use aws_http::content_encoding::{AwsChunkedBody, AwsChunkedBodyOptions};
use aws_runtime::auth::sigv4::SigV4OperationSigningConfig;
use aws_runtime::auth::SigV4OperationSigningConfig;
use aws_sigv4::http_request::SignableBody;
use aws_smithy_checksums::ChecksumAlgorithm;
use aws_smithy_checksums::{body::calculate, http::HttpChecksum};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

use crate::presigning::PresigningConfig;
use crate::serialization_settings::HeaderSerializationSettings;
use aws_runtime::auth::sigv4::{HttpSignatureType, SigV4OperationSigningConfig};
use aws_runtime::auth::HttpSignatureType;
use aws_runtime::auth::SigV4OperationSigningConfig;
use aws_runtime::invocation_id::InvocationIdInterceptor;
use aws_runtime::request_info::RequestInfoInterceptor;
use aws_runtime::user_agent::UserAgentInterceptor;
Expand Down
33 changes: 16 additions & 17 deletions aws/rust-runtime/aws-inlineable/tests/middleware_e2e_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

use std::convert::Infallible;
use std::error::Error;
use std::fmt;
use std::fmt::{Display, Formatter};
use std::time::{Duration, UNIX_EPOCH};

use aws_credential_types::cache::CredentialsCache;
use aws_credential_types::provider::SharedCredentialsProvider;
use aws_credential_types::Credentials;
use aws_http::retry::AwsResponseRetryClassifier;
use aws_http::user_agent::AwsUserAgent;
use aws_inlineable::middleware::DefaultMiddleware;
use aws_sig_auth::signer::OperationSigningConfig;
use aws_smithy_async::time::SharedTimeSource;
use aws_smithy_client::erase::DynConnector;
use aws_smithy_client::test_connection::TestConnection;
use aws_smithy_http::body::SdkBody;
Expand All @@ -20,17 +19,16 @@ use aws_smithy_http::operation::Operation;
use aws_smithy_http::response::ParseHttpResponse;
use aws_smithy_types::endpoint::Endpoint;
use aws_smithy_types::retry::{ErrorKind, ProvideErrorKind};
use aws_types::region::SigningRegion;
use aws_types::SigningName;
use bytes::Bytes;
use http::header::{AUTHORIZATION, USER_AGENT};
use http::{self, Uri};

use aws_http::retry::AwsResponseRetryClassifier;
use aws_http::user_agent::AwsUserAgent;
use aws_inlineable::middleware::DefaultMiddleware;
use aws_sig_auth::signer::OperationSigningConfig;
use aws_smithy_async::time::SharedTimeSource;
use aws_types::region::SigningRegion;
use aws_types::SigningService;
use std::convert::Infallible;
use std::error::Error;
use std::fmt;
use std::fmt::{Display, Formatter};
use std::time::{Duration, UNIX_EPOCH};

type Client<C> = aws_smithy_client::Client<C, DefaultMiddleware>;

Expand Down Expand Up @@ -89,12 +87,13 @@ fn test_operation() -> Operation<TestOperationParser, AwsResponseRetryClassifier
));
aws_http::auth::set_credentials_cache(
conf,
CredentialsCache::lazy()
.create_cache(SharedCredentialsProvider::new(Credentials::for_tests())),
CredentialsCache::lazy().create_cache(SharedCredentialsProvider::new(
Credentials::for_tests_with_session_token(),
)),
);
conf.insert(SigningRegion::from_static("test-region"));
conf.insert(OperationSigningConfig::default_config());
conf.insert(SigningService::from_static("test-service-signing"));
conf.insert(SigningName::from_static("test-service-signing"));
conf.insert(SharedTimeSource::new(
UNIX_EPOCH + Duration::from_secs(1613414417),
));
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test-util = []
[dependencies]
aws-credential-types = { path = "../aws-credential-types" }
aws-http = { path = "../aws-http" }
aws-sigv4 = { path = "../aws-sigv4" }
aws-sigv4 = { path = "../aws-sigv4", features = ["sigv4a"] }
aws-smithy-async = { path = "../../../rust-runtime/aws-smithy-async" }
aws-smithy-eventstream = { path = "../../../rust-runtime/aws-smithy-eventstream", optional = true }
aws-smithy-http = { path = "../../../rust-runtime/aws-smithy-http" }
Expand Down
Loading