aws / amazon-ssm-agent

An agent to enable remote management of your EC2 instances, on-premises servers, or virtual machines (VMs).
https://aws.amazon.com/systems-manager/
Apache License 2.0
1.04k stars 323 forks source link

Request enhancements to hostname setting #328

Open michaelsmoody opened 3 years ago

michaelsmoody commented 3 years ago

Good afternoon to you all!

If you're in the USA (or outside of it, but observant), I hope you had a wonderful Thanksgiving!

Our organization has a few requests for enhancements to the seamless domain join for Linux/Unix instances that would make our lives tremendously easier:

I'll start (in this issue) with ones to the hostname setting. Specifically, this function:

https://github.com/aws/amazon-ssm-agent/blob/215d334a3d8204f37883399a5b81882b47951650/agent/plugins/domainjoin/domainjoin_unix_script.go#L60

(First, it's good work, it's well documented, and it's a clever approach).

Enhancements in no particular order

  1. Move to 15 characters for random hostnames - While collisions are unlikely in the 6 character name space, 15 characters is the same amount that you would get with full IP addresses, with all octets filled and dots or dashes, for consistency. xxx.xxx.xxx.xxx for instance, same as 15 characters. It's mostly just a consistency suggestion. No other reason.

  2. Allow the hostname to be overriden with a userdata variable. What this variable should be is up to you, but you already set REGION in another step via a curl call, so it's possible. Minor error checking to see if the variable is set, and then use the userdata supplied variable for hostname setting. Yes, there are cases where it wouldn't work (duplicates), in which case, a random name could be used, which would be a further enhancement, true.

  3. Similar to a userdata variable, allow the hostname to overriden with an EC2 tag (again, what this tag name should be is up to you). This would be extraordinarily helpful as well.

  4. Simply allow existing hostname to be obeyed and not set to a new random hostname. We set the hostname specifically, and having a random hostname set upon join is quite frustrating at times. There's no straightforward way to change it. We have to leave/join the domain again to change it. It would be far simple if we simply set the hostname to what we want, and this script would allow a variable, option, or userdata, to not mangle it, and join with the shortname/hostname already set.

Thank you again for the excellent work on this, and while helpful, these enhancements are requests. The most important one, if I had to choose would be either an override, or obey existing. Either of those two options. Yes, that might result in instances where the system didn't join (duplicates), but that could be reflected in the documentation as a real genuine risk.

michaelsmoody commented 3 years ago

@anetheredge For you to review

smhmhmd commented 3 years ago

@michaelsmoody Request for 4) to add an optional parameter to the SSM doc is queued, I will ask about 2) and 3)

smhmhmd commented 2 years ago

Here is an example, as tested on Linux, see hostname regex as well in the script

{
  "schemaVersion": "1.0",
  "description": "Automatic Domain Join Configuration created by EC2 Console.",
  "runtimeConfig": {
    "aws:domainJoin": {
      "properties": {
        "directoryId": "d-xxxxxxx",
        "directoryName": "[x.y.com](http://x.y.com/)",
        "dnsIpAddresses": [
          "A.B.C.D",
          "E.F.G.H"
        ],
        "hostName": "myhostname1234"
      }
    }
  }
}
Chandra2108 commented 1 year ago

Hi I getting "An argument named "hostname" is not expected here." error for the above code

suhailfouzan commented 1 year ago

Hello,

I tested the script in Amazon Linux 2 and also with the latest SSM Agent 3.2.582.0, it works fine.

{
  "schemaVersion": "1.0",
  "description": "Automatic Domain Join Configuration created by EC2 Console.",
  "runtimeConfig": {
    "aws:domainJoin": {
      "properties": {
        "directoryId": "d-xxxxxxx",
        "directoryName": "example.com",
        "dnsIpAddresses": [
          "a.b.c.d",
          "e.f.g.h"
        ],
        "hostName": "myhostname"
      }
    }
  }
}
smhmhmd commented 1 year ago

Thanks @suhailfouzan

@Chandra2108 I also tested same as above and the domain-join + host-rename worked fine. (AL2 in us-west-1)

Chandra2108 commented 1 year ago

Thanks @smhmhmd, @suhailfouzan. Working fine :)