Skip to content

Commit

Permalink
feat: extend startup domain to Linux
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nblair2 authored and activeshadow committed Feb 17, 2025
1 parent dc74eac commit 97b6cf2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
42 changes: 34 additions & 8 deletions src/go/app/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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()
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/go/tmpl/templates/linux_domain.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "{{ .domain_controller.password }}" | realm join --user={{ .domain_controller.username }} {{ .domain_controller.domain }}

0 comments on commit 97b6cf2

Please sign in to comment.