Skip to content

Commit b04afad

Browse files
committed
bind out proxy settings for profile and web identity creds provider
1 parent a1bf93b commit b04afad

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

include/aws/crt/auth/Credentials.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ namespace Aws
209209
* If using BYO_CRYPTO, you must provide the TLS context since it cannot be created automatically.
210210
*/
211211
Io::TlsContext *TlsContext;
212+
213+
/**
214+
* (Optional) Http proxy configuration for the http request that fetches credentials.
215+
*/
216+
Optional<Http::ProxyEnvVarOptions> ProxyEnvVarOptions;
212217
};
213218

214219
/**
@@ -492,6 +497,11 @@ namespace Aws
492497
* TLS configuration for secure socket connections.
493498
*/
494499
Io::TlsConnectionOptions TlsConnectionOptions;
500+
501+
/**
502+
* (Optional) Http proxy configuration for the http request that fetches credentials.
503+
*/
504+
Optional<Http::ProxyEnvVarOptions> ProxyEnvVarOptions;
495505
};
496506

497507
/**

include/aws/crt/http/HttpConnection.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,72 @@ namespace Aws
340340
String BasicAuthPassword;
341341
};
342342

343+
/**
344+
* Configuration to enable or disable environment variable based proxy lookup.
345+
*/
346+
enum class ProxyEnvVarType
347+
{
348+
/**
349+
* Default.
350+
* Disable reading from environment variable for proxy.
351+
*/
352+
Disabled = AWS_HPEV_DISABLE,
353+
/**
354+
* Enable get proxy URL from environment variable, when the manual proxy options of connection manager
355+
* is not set. env HTTPS_PROXY/https_proxy will be checked when the main connection use tls. env
356+
* HTTP_PROXY/http_proxy will be checked when the main connection NOT use tls. env NO_PROXY/no_proxy
357+
* will be checked to bypass proxy if the host match the pattern. Check `aws_http_host_matches_no_proxy`
358+
* for detail. This function can also be used with a direct no_proxy parameter. The lower case version
359+
* has precedence.
360+
*/
361+
Enabled = AWS_HPEV_ENABLE,
362+
};
363+
364+
/**
365+
* Configuration structure that holds all proxy-related http connection options
366+
*/
367+
class AWS_CRT_CPP_API ProxyEnvVarOptions
368+
{
369+
public:
370+
ProxyEnvVarOptions();
371+
ProxyEnvVarOptions(const ProxyEnvVarOptions &rhs) = default;
372+
ProxyEnvVarOptions(ProxyEnvVarOptions &&rhs) = default;
373+
374+
ProxyEnvVarOptions &operator=(const ProxyEnvVarOptions &rhs) = default;
375+
ProxyEnvVarOptions &operator=(ProxyEnvVarOptions &&rhs) = default;
376+
377+
~ProxyEnvVarOptions() = default;
378+
379+
/**
380+
* Intended for internal use only. Initializes the C proxy configuration structure,
381+
* aws_http_proxy_options, from an HttpClientConnectionProxyOptions instance.
382+
*
383+
* @param raw_options - output parameter containing low level proxy options to be passed to the C
384+
* interface
385+
*
386+
*/
387+
void InitializeRawProxyOptions(struct proxy_env_var_settings &raw_options) const;
388+
389+
/**
390+
* Enables or disables env var lookup for proxy variables.
391+
*/
392+
ProxyEnvVarType proxyEnvVarType;
393+
394+
/**
395+
* Optional.
396+
* If not set:
397+
* If tls options are provided (for the main connection) use tunnel proxy type
398+
* If tls options are not provided (for the main connection) use forward proxy type
399+
*/
400+
AwsHttpProxyConnectionType connectionType;
401+
402+
/**
403+
* Sets the TLS options for the connection to the proxy.
404+
* Optional.
405+
*/
406+
Optional<Io::TlsConnectionOptions> TlsOptions;
407+
};
408+
343409
/**
344410
* Configuration structure holding all options relating to http connection establishment
345411
*/

source/auth/Credentials.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ namespace Aws
238238
raw_config.profile_name_override = config.ProfileNameOverride;
239239
raw_config.bootstrap = config.Bootstrap ? config.Bootstrap->GetUnderlyingHandle() : nullptr;
240240
raw_config.tls_ctx = config.TlsContext ? config.TlsContext->GetUnderlyingHandle() : nullptr;
241+
struct proxy_env_var_settings proxy_options;
242+
AWS_ZERO_STRUCT(proxy_options);
243+
if (config.ProxyEnvVarOptions.has_value())
244+
{
245+
const Http::ProxyEnvVarOptions &proxy_config = config.ProxyEnvVarOptions.value();
246+
proxy_config.InitializeRawProxyOptions(proxy_options);
247+
248+
raw_config.proxy_ev_settings = &proxy_options;
249+
}
241250

242251
return s_CreateWrappedProvider(aws_credentials_provider_new_profile(allocator, &raw_config), allocator);
243252
}
@@ -511,6 +520,17 @@ namespace Aws
511520
{
512521
raw_config.tls_ctx = connectionOptions->ctx;
513522
}
523+
524+
struct proxy_env_var_settings proxy_options;
525+
AWS_ZERO_STRUCT(proxy_options);
526+
if (config.ProxyEnvVarOptions.has_value())
527+
{
528+
const Http::ProxyEnvVarOptions &proxy_config = config.ProxyEnvVarOptions.value();
529+
proxy_config.InitializeRawProxyOptions(proxy_options);
530+
531+
raw_config.proxy_ev_settings = &proxy_options;
532+
}
533+
514534
return s_CreateWrappedProvider(
515535
aws_credentials_provider_new_sts_web_identity(allocator, &raw_config), allocator);
516536
}

source/http/HttpConnection.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,18 @@ namespace Aws
398398
}
399399
}
400400

401+
void ProxyEnvVarOptions::InitializeRawProxyOptions(struct proxy_env_var_settings &rawOptions) const
402+
{
403+
AWS_ZERO_STRUCT(rawOptions);
404+
rawOptions.env_var_type = (enum aws_http_proxy_env_var_type)proxyEnvVarType;
405+
rawOptions.connection_type = (enum aws_http_proxy_connection_type)connectionType;
406+
407+
if (TlsOptions.has_value())
408+
{
409+
rawOptions.tls_options = TlsOptions->GetUnderlyingHandle();
410+
}
411+
}
412+
401413
HttpClientConnectionOptions::HttpClientConnectionOptions()
402414
: Bootstrap(nullptr), InitialWindowSize(SIZE_MAX), OnConnectionSetupCallback(),
403415
OnConnectionShutdownCallback(), HostName(), Port(0), SocketOptions(), TlsOptions(), ProxyOptions(),

0 commit comments

Comments
 (0)