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 credentials exposure test & fix STS + SSO #2603

Merged
merged 3 commits into from
Apr 20, 2023
Merged

Conversation

rcoh
Copy link
Collaborator

@rcoh rcoh commented Apr 19, 2023

Motivation and Context

  • credentials providers may leak credentials in the HTTP body at the debug level

Description

This adds a test to aws-config that looks for leaked credentials in all of our provider integration tests—since these test use AWS APIs under the hood, this also serves to test AWS services in general.

To support this, sensitive was added to the ParseHttpResponse trait and code was generated to take action based on this change.

  • Add environment variable to force logging of the body
  • consider if we want to suppress request body logging as well

Testing

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@rcoh rcoh force-pushed the credentials-exposure-test branch from a777342 to e750d89 Compare April 19, 2023 18:55
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

rcoh and others added 3 commits April 20, 2023 08:33
This adds a test to aws-config that looks for leaked credentials in all of our provider integration tests—since these test use AWS APIs under the hood, this also serves to test AWS services in general.

To support this, `sensitive` was added to the ParseHttpResponse trait and code was generated to take action based on this change.
…ial_process/fs/home/.aws/config

Co-authored-by: John DiSanti <jdisanti@amazon.com>
@rcoh rcoh force-pushed the credentials-exposure-test branch from cd1a864 to 75461b9 Compare April 20, 2023 12:33
@rcoh rcoh marked this pull request as ready for review April 20, 2023 12:37
@rcoh rcoh requested review from a team as code owners April 20, 2023 12:37
@rcoh rcoh requested review from pose and crisidev April 20, 2023 12:37
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link
Contributor

@ysaito1001 ysaito1001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR, handling the business of logging sensitive info holistically both in models and AWS runtime crates.

@@ -132,7 +134,15 @@ where
};

let http_response = http::Response::from_parts(parts, Bytes::from(body));
trace!(http_response = ?http_response, "read HTTP response body");
if !handler.sensitive()
|| std::env::var(LOG_SENSITIVE_BODIES)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to provide an escape hatch to still be able to print.

@@ -417,7 +417,7 @@ mod loader {
///
/// # Example: Using a custom profile name
///
/// ```
/// ```no_run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we want to run these anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't be running doc tests ever, these were misses. They should only be compiled—running them will try to load up an SSL chain etc. and makes them very slow

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably do a pass (as a separate PR) and check that we aren't running them elsewhere.

Comment on lines +148 to +149
/// *Why use this instead of traced_test?*
/// This captures _all_ logs, not just logs produced by the current crate.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty for adding this comment! It's exactly what I would have asked.

@@ -256,7 +256,7 @@ fn calculate_signing_headers<'a>(
// Step 4: https://docs.aws.amazon.com/en_pv/general/latest/gr/sigv4-add-signature-to-request.html
let values = creq.values.as_headers().expect("signing with headers");
let mut headers = HeaderMap::new();
add_header(&mut headers, header::X_AMZ_DATE, &values.date_time);
add_header(&mut headers, header::X_AMZ_DATE, &values.date_time, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth creating an enum for is_sensitive in order to make this easier to understand.

Comment on lines +132 to +137
[[aws-sdk-rust]]
message = """Reduce several instances of credential exposure in the SDK logs:
- IMDS now suppresses the body of the response from logs
- `aws-sigv4` marks the `x-amz-session-token` header as sensitive
- STS & SSO credentials have been manually marked as sensitive which suppresses logging of response bodies for relevant operations
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to render correctly? Seems like the sub bullet points might become top-level bullet points in the rendered changelog.

@rcoh rcoh added this pull request to the merge queue Apr 20, 2023
Merged via the queue into main with commit 9a41e35 Apr 20, 2023
@rcoh rcoh deleted the credentials-exposure-test branch April 20, 2023 17:54
unexge pushed a commit that referenced this pull request Apr 24, 2023
## Motivation and Context
- credentials providers may leak credentials in the HTTP body at the
debug level

## Description
This adds a test to aws-config that looks for leaked credentials in all
of our provider integration tests—since these test use AWS APIs under
the hood, this also serves to test AWS services in general.

To support this, `sensitive` was added to the ParseHttpResponse trait
and code was generated to take action based on this change.

- [x] Add environment variable to force logging of the body
- [x] consider if we want to suppress request body logging as well

## Testing
<!--- Please describe in detail how you tested your changes -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: John DiSanti <jdisanti@amazon.com>
rcoh added a commit that referenced this pull request Apr 24, 2023
## Motivation and Context
- credentials providers may leak credentials in the HTTP body at the
debug level

## Description
This adds a test to aws-config that looks for leaked credentials in all
of our provider integration tests—since these test use AWS APIs under
the hood, this also serves to test AWS services in general.

To support this, `sensitive` was added to the ParseHttpResponse trait
and code was generated to take action based on this change.

- [x] Add environment variable to force logging of the body
- [x] consider if we want to suppress request body logging as well

## Testing
<!--- Please describe in detail how you tested your changes -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: John DiSanti <jdisanti@amazon.com>
github-merge-queue bot pushed a commit that referenced this pull request Sep 8, 2023
## Motivation and Context
Fixes #2926

## Description
This PR ports logic implemented in
#2603. Thankfully, even though
we did not port this at the time of the orchestrator launch, the
orchestrator has not logged sensitive bodies because we have never
logged response bodies in the orchestrator code.

The code changes in this PR
- now logs response bodies in `try_attempt`
- ports the logic from the previous PR in question to the orchestrator,
via an interceptor

Now, when credentials providers in `aws_config` need to say "I want to
redact a response body"
([example](https://github.com/awslabs/smithy-rs/blob/2c27834f90b0585dba60606f9da6246b341227d6/aws/rust-runtime/aws-config/src/http_credential_provider.rs#L48))
when middleware is gone, they can pass an interceptor
`SensitiveOutputInterceptor` to `Config` of whatever clients they are
using.

## Testing
Depends on the existing tests.

Without the logic ported over the orchestrator and by logging response
bodies unconditionally in `try_attempt`, we got the following failures.
After we've ported the logic, they now pass.
```
    default_provider::credentials::test::ecs_assume_role
    default_provider::credentials::test::imds_assume_role
    default_provider::credentials::test::sso_assume_role
    default_provider::credentials::test::web_identity_token_env
    default_provider::credentials::test::web_identity_token_profile
    default_provider::credentials::test::web_identity_token_source_profile
    profile::credentials::test::e2e_assume_role
    profile::credentials::test::region_override
    profile::credentials::test::retry_on_error
```


## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: ysaito1001 <awsaito@amazon.com>
Co-authored-by: John DiSanti <jdisanti@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants