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

Dynamically get network interface name in domainjoin_unix_script.go #469

Open
DanielTeraSky opened this issue Sep 22, 2022 · 5 comments
Open

Comments

@DanielTeraSky
Copy link

As part of the domain join script for Unix, there is a line where we get the interface IP address, but the interface name is hard-coded (eth0) as you can see here:

ip_address="$(ip -o -4 addr show eth0 | awk '{print $4}' | cut -d/ -f1)"

Although this works for t2 instance types, it doesn't work for t3and t3a since the network interface name has changed to ensX.

I suggest to change this line to dynamically fetch the the IP without specifying the interface name.
There are 2 options to do this:

# Option 1:
ip_address="$(hostname -I)"

# Option 2:
ip_address="$(ip -o -4 addr show $(ip route list | grep default | grep -E  'dev (\w+)' -o | awk '{print $2}') | awk '{print $4}' | cut -d/ -f1)"

This is an important fix as there is currently an issue with this script when running on newer machine types

@smhmhmd
Copy link
Contributor

smhmhmd commented Sep 22, 2022

Thanks for the feedback @DanielTeraSky , the second option looks more portable.
Could you submit a pull-request ?

@smhmhmd
Copy link
Contributor

smhmhmd commented Sep 22, 2022

When you submit the PR, also mention what testing you have done.

@jaseblenner
Copy link

jaseblenner commented Jan 16, 2023

Thanks for opening this issue @DanielTeraSky - the interface name (eth0) is also hardcoded at line #608 this should be set dynamically also.

A potential solution may be setting an $IF_NAME or similar var early on in the execution.
Something like this may work:

"IF_NAME=$(ip -br l | awk '$1 !~ "lo|vir|wl" { print $1}')"

I have come up with a hacky workaround for my builds in the interim but unfortunately my bash skills aren't up to par to submit a PR for this.

edit: disregard, i see your PR has now been merged. Opened PR #499 as a follow up

@smhmhmd
Copy link
Contributor

smhmhmd commented Jan 16, 2023

The PR has been pushed, it may take sometime to deploy to all regions, please keep your agent uptodate.

https://github.com/aws/amazon-ssm-agent/blob/mainline/agent/plugins/domainjoin/domainjoin_unix_script.go#L556

@smhmhmd
Copy link
Contributor

smhmhmd commented Jan 16, 2023

@jaseblenner,

You are right, for Ubuntu, there is one more spot where eth0 has not been fixed.
Thanks for opening PR #499 , I will incorporate it

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

No branches or pull requests

3 participants