From 916d1364dd84da02aaf22604a967332f96ac5021 Mon Sep 17 00:00:00 2001 From: Nicholas Blair Date: Tue, 12 Nov 2024 22:01:22 +0000 Subject: [PATCH 1/3] feat: extend startup domain to linux This adds the ability for linux hosts to join MS Active Directory domains using the realmd package. Some light refactoring of when/where we check for the startup app to do it once before all hosts. --- src/go/app/startup.go | 42 ++++++++++++++++++++----- src/go/tmpl/templates/linux_domain.tmpl | 3 ++ 2 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 src/go/tmpl/templates/linux_domain.tmpl diff --git a/src/go/app/startup.go b/src/go/app/startup.go index ca883040..bf05233e 100644 --- a/src/go/app/startup.go +++ b/src/go/app/startup.go @@ -99,6 +99,15 @@ func (this Startup) PreStart(ctx context.Context, exp *types.Experiment) error { continue } + // Check to see if a scenario exists for this experiment and if it + // contains a "startup" app. If so, store it for later use + var startupApp ifaces.ScenarioApp + for _, app := range exp.Apps() { + if app.Name() == "startup" { + startupApp = app + } + } + switch strings.ToLower(node.Hardware().OSType()) { case "linux", "rhel", "centos": var ( @@ -138,6 +147,26 @@ func (this Startup) PreStart(ctx context.Context, exp *types.Experiment) error { if err := tmpl.CreateFileFromTemplate("linux_interfaces.tmpl", node, ifaceFile); err != nil { return fmt.Errorf("generating linux interfaces script: %w", err) } + + if startupApp != nil { + for _, host := range startupApp.Hosts() { + if host.Hostname() == node.General().Hostname() { + + var domainFile = startupDir + "/" + node.General().Hostname() + "-domain.sh" + + node.AddInject( + domainFile, + "/etc/phenix/startup/4_domain-start.sh", + "0755", "", + ) + + if err := tmpl.CreateFileFromTemplate("linux_domain.tmpl", host.Metadata(), domainFile); err != nil { + return fmt.Errorf("generating linux domain script: %w", err) + } + } + } + } + case "windows": startupFile := startupDir + "/" + node.General().Hostname() + "-startup.ps1" @@ -178,15 +207,12 @@ func (this Startup) PreStart(ctx context.Context, exp *types.Experiment) error { Metadata: make(map[string]interface{}), } - // Check to see if a scenario exists for this experiment and if it - // contains a "startup" app. If so, see if this node has a metadata entry + // If startup app exists, see if this node has a metadata entry // in the scenario app configuration. - for _, app := range exp.Apps() { - if app.Name() == "startup" { - for _, host := range app.Hosts() { - if host.Hostname() == node.General().Hostname() { - data.Metadata = host.Metadata() - } + if startupApp != nil { + for _, host := range startupApp.Hosts() { + if host.Hostname() == node.General().Hostname() { + data.Metadata = host.Metadata() } } } diff --git a/src/go/tmpl/templates/linux_domain.tmpl b/src/go/tmpl/templates/linux_domain.tmpl new file mode 100644 index 00000000..4407c8c4 --- /dev/null +++ b/src/go/tmpl/templates/linux_domain.tmpl @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "{{ .domain_controller.password }}" | realm --username={{ .domain_controller.username }} {{ .domain_controller.domain }} \ No newline at end of file From 6cfe02779b24ad0df8970dc6aef63ec0759aa17a Mon Sep 17 00:00:00 2001 From: Nicholas Blair Date: Tue, 12 Nov 2024 23:38:48 +0000 Subject: [PATCH 2/3] !fixup --- src/go/tmpl/templates/linux_domain.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/go/tmpl/templates/linux_domain.tmpl b/src/go/tmpl/templates/linux_domain.tmpl index 4407c8c4..edd7b8a5 100644 --- a/src/go/tmpl/templates/linux_domain.tmpl +++ b/src/go/tmpl/templates/linux_domain.tmpl @@ -1,3 +1,3 @@ #!/bin/bash -echo "{{ .domain_controller.password }}" | realm --username={{ .domain_controller.username }} {{ .domain_controller.domain }} \ No newline at end of file +echo "{{ .domain_controller.password }}" | realm join --username={{ .domain_controller.username }} {{ .domain_controller.domain }} From c8223558e02202d1f2ba3d8a03d4dc1a22c9c135 Mon Sep 17 00:00:00 2001 From: Nicholas Blair Date: Wed, 13 Nov 2024 00:23:20 +0000 Subject: [PATCH 3/3] !fixup --- src/go/tmpl/templates/linux_domain.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/go/tmpl/templates/linux_domain.tmpl b/src/go/tmpl/templates/linux_domain.tmpl index edd7b8a5..ae7c7cd2 100644 --- a/src/go/tmpl/templates/linux_domain.tmpl +++ b/src/go/tmpl/templates/linux_domain.tmpl @@ -1,3 +1,3 @@ #!/bin/bash -echo "{{ .domain_controller.password }}" | realm join --username={{ .domain_controller.username }} {{ .domain_controller.domain }} +echo "{{ .domain_controller.password }}" | realm join --user={{ .domain_controller.username }} {{ .domain_controller.domain }}