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

cfsignal: add proxy support #234

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

jpculp
Copy link
Member

@jpculp jpculp commented Nov 1, 2024

Description of changes:

Adds support for sending signals to CloudFormation through a set proxy.

Testing done:

Launched an aws-ecs-2 node with the following userdata:

[settings.ecs]
cluster = "<MY_CLUSTER>"

[settings.network]
https-proxy = "<MY_PROXY>:8888"

[settings.cloudformation]
should-signal = true
stack-name = "<MY_STACK>"
logical-resource-id = "<MY_RESOURCE>"

Status of cfsignal.service:

bash-5.1# systemctl status cfsignal
○ cfsignal.service - Send signal to CloudFormation Stack
     Loaded: loaded (/aarch64-bottlerocket-linux-gnu/sys-root/usr/lib/systemd/system/cfsignal.service; enabled; preset: enabled)
     Active: inactive (dead) since Fri 2024-11-01 00:19:10 UTC; 6min ago
   Duration: 2.483s
   Main PID: 1157 (code=exited, status=0/SUCCESS)
        CPU: 25ms

Nov 01 00:19:07 localhost systemd[1]: Started Send signal to CloudFormation Stack.
Nov 01 00:19:09 ip-XXX-XXX-XX-XX.us-west-2.compute.internal cfsignal[1157]: 00:19:09 [INFO] System status is: running [0]
Nov 01 00:19:09 ip-XXX-XXX-XX-XX.us-west-2.compute.internal cfsignal[1157]: 00:19:09 [INFO] Connecting to IMDS
Nov 01 00:19:10 ip-XXX-XXX-XX-XX.us-west-2.compute.internal cfsignal[1157]: 00:19:10 [INFO] Received meta-data/instance-id
Nov 01 00:19:10 ip-XXX-XXX-XX-XX.us-west-2.compute.internal cfsignal[1157]: 00:19:10 [INFO] Received dynamic/instance-identity/document
Nov 01 00:19:10 ip-XXX-XXX-XX-XX.us-west-2.compute.internal cfsignal[1157]: 00:19:10 [INFO] Region: "us-west-2" - InstanceID: "<MY_INSTANCE>" - Signal: "SUCCESS"
Nov 01 00:19:10 ip-XXX-XXX-XX-XX.us-west-2.compute.internal cfsignal[1157]: 00:19:10 [INFO] lazy_load_identity;
Nov 01 00:19:10 ip-XXX-XXX-XX-XX.us-west-2.compute.internal systemd[1]: cfsignal.service: Deactivated successfully.

Excerpts from CloudTrail:

"eventName": "SignalResource",
"eventSource": "cloudformation.amazonaws.com",
"eventTime": "2024-11-01T00:19:10Z",
"eventType": "AwsApiCall",
"eventVersion": "1.08",
"managementEvent": true,
"readOnly": false,

...

"requestParameters": {
    "logicalResourceId": "<MY_RESOURCE>",
    "stackName": "<MY_STACK>",
    "status": "SUCCESS",
    "uniqueId": "<MY_INSTANCE>"
},

...

"sourceIPAddress": "<MY_PROXY>",
"userAgent": "aws-sdk-rust/1.3.3 os/linux lang/rust/1.81.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.

Signed-off-by: Patrick J.P. Culp <jpculp@amazon.com>
Copy link
Contributor

@vyaghras vyaghras left a comment

Choose a reason for hiding this comment

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

🚢

let http_client = HyperClientBuilder::new()
.crypto_mode(crypto_mode)
.build_https();
let https_proxy: Option<String> = match env::var_os("HTTPS_PROXY") {
Copy link
Contributor

Choose a reason for hiding this comment

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

style nit: match statements like this are more idiomatically written using Option::map.

Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
let https_proxy: Option<String> = match env::var_os("HTTPS_PROXY") {
let https_proxy = env::var("HTTPS_PROXY").ok();
let no_proxy = env::var("NO_PROXY")
.ok()
.map(|n| n.split(',').map(|s| s.to_string()).collect::<Vec<_>>());

So in practice like this. It does look clean, but since we already have approvals I think we can save it for next time we're in the crate or if clippy flags it.

@jpculp jpculp merged commit 115bb2e into bottlerocket-os:develop Nov 4, 2024
2 checks passed
@jpculp jpculp deleted the cfsignal-proxy-support branch November 4, 2024 19:26
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