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

pluto: handle auth info in https_proxy #3639

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

etungsten
Copy link
Contributor

@etungsten etungsten commented Dec 5, 2023

Issue number:
Resolves #3525

Description of changes:

    pluto: handle auth info in https_proxy
    
    Need to parse out auth info in `https_proxy` and set to proxy header.

Testing done:
Unit tests pass.

Set up my own tiny proxy host and launched new Bottlerocket host with the following settings:

[settings.network]
https-proxy = "http://user:pass@my_proxy:9898"

The boot succeeds, pluto successfully fetches instance information through AWS EC2 API.
In cloudtrail, i can see the source of the DescribeInstance event as being my proxy:

{
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": ".....i-0d2d921de0b0a9aad",
        "arn": "..../i-0d2d921de0b0a9aad",
...
    "eventTime": "2023-12-05T23:51:56Z",
    "eventSource": "ec2.amazonaws.com",
    "eventName": "DescribeInstances",
    "awsRegion": "us-west-2",
    "sourceIPAddress": "<my_proxy_url>",
    "userAgent": "aws-sdk-rust/0.55.3 os/linux lang/rust/1.73.0",

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

@etungsten etungsten marked this pull request as ready for review December 5, 2023 23:54
sources/api/pluto/src/proxy.rs Outdated Show resolved Hide resolved
sources/api/pluto/src/hyper_proxy/mod.rs Outdated Show resolved Hide resolved
@etungsten
Copy link
Contributor Author

Push above addresses @bcressey's comments.

Retested, same behavior as observed in cloudtrail:

    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "...:i-03de3baa30b4d01f0",
        "arn": "...i-03de3baa30b4d01f0",
...
        }
    },
    "eventSource": "ec2.amazonaws.com",
    "eventName": "DescribeInstances",
    "awsRegion": "us-west-2",
    "sourceIPAddress": "my_proxy",
    "userAgent": "aws-sdk-rust/0.55.3 os/linux lang/rust/1.73.0",

Copy link
Contributor

@yeazelm yeazelm left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines 99 to 95
if !proxy_url.username().is_empty() {
proxy.set_authorization(Authorization::basic(
proxy_url.username(),
proxy_url.password().unwrap_or_default(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't done much with Proxy-Authorization but my read of the header documentation and my understanding of URL username/password encoding makes me think that it's valid to provide a passphrase without a username.

Should we be inserting the header if a password is given without a username?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe so. Good catch

@etungsten
Copy link
Contributor Author

Push above addresses @cbgbt 's comment

Need to parse out auth info in `https_proxy` and set to proxy header.
@jpculp jpculp merged commit 3aadc59 into bottlerocket-os:develop Dec 7, 2023
46 checks passed
Comment on lines +127 to +139
/// Set `Proxy` authorization
pub fn set_authorization<C: Credentials + Clone>(&mut self, credentials: Authorization<C>) {
match self.intercept {
Intercept::Https => {
self.headers.typed_insert(ProxyAuthorization(credentials.0));
}
_ => {
self.headers
.typed_insert(Authorization(credentials.0.clone()));
self.headers.typed_insert(ProxyAuthorization(credentials.0));
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to set the authorization headers in the _ (specifically, None) case where connections aren't going through the proxy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was lifted from hyper_proxy source and it's not super clear to me either. In any case, we shouldn't be reaching this path since we're only proxying HTTPS traffic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After some digging, we've determined that the Auth header here will never get sent if the proxy doesn't "match" with the destination URL. We'll go ahead and simplify this logic here so it only contains the case we care about, i.e. proxying HTTPS traffic.

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.

pluto doesn't handle proxy credentials in https_proxy
6 participants