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

Use Hostname in PSC registration #1066

Merged
7 commits merged into from Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions installer/build/scripts/admiral/configure_admiral.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ function secure {
function detectHostname {
hostname=$(hostnamectl status --static) || true
if [ -n "$hostname" ]; then
if [ "$hostname" = "localhost.localdomain" ]; then
hostname=""
return
fi
echo "Get hostname from command 'hostnamectl status --static': $hostname"
return
fi
Expand All @@ -187,11 +183,11 @@ secure

configureScript $admiral_start_script ADMIRAL_DATA_LOCATION $data_dir
configureScript $admiral_start_script ADMIRAL_EXPOSED_PORT "$ADMIRAL_PORT"
configureScript $admiral_start_script OVA_VM_IP "$ip_address"
configureScript $admiral_start_script OVA_VM_IP "${hostname}"

configureScript $admiral_add_default_users_script ADMIRAL_DATA_LOCATION $data_dir
configureScript $admiral_add_default_users_script ADMIRAL_EXPOSED_PORT "$ADMIRAL_PORT"
configureScript $admiral_add_default_users_script OVA_VM_IP "$ip_address"
configureScript $admiral_add_default_users_script OVA_VM_IP "${hostname}"

iptables -w -A INPUT -j ACCEPT -p tcp --dport "$ADMIRAL_PORT"

Expand Down
4 changes: 0 additions & 4 deletions installer/build/scripts/fileserver/configure_fileserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ function secure {
function detectHostname {
hostname=$(hostnamectl status --static) || true
if [ -n "$hostname" ]; then
if [ "$hostname" = "localhost.localdomain" ]; then
hostname=""
return
fi
echo "Get hostname from command 'hostnamectl status --static': $hostname"
return
fi
Expand Down
4 changes: 0 additions & 4 deletions installer/build/scripts/harbor/configure_harbor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ function configureHarborCfgOnce {
function detectHostname {
hostname=$(hostnamectl status --static) || true
if [ -n "$hostname" ]; then
if [ "$hostname" = "localhost.localdomain" ]; then
hostname=""
return
fi
echo "Get hostname from command 'hostnamectl status --static': $hostname"
return
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ function secure {
function detectHostname {
hostname=$(hostnamectl status --static) || true
if [ -n "$hostname" ]; then
if [ "$hostname" = "localhost.localdomain" ]; then
hostname=""
return
fi
echo "Get hostname from command 'hostnamectl status --static': $hostname"
return
fi
Expand Down
2 changes: 1 addition & 1 deletion installer/build/vic-unified.ovf
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ EVALUATION LICENSE. If You are licensing the Software for evaluation purposes, Y
<Label>2.5. Domain Search Path</Label>
<Description>The domain search path (space separated domain names) for this VM. Leave blank if DHCP is desired.</Description>
</Property>
<Property ovf:key="fqdn" ovf:type="string" ovf:userConfigurable="true" ovf:value="localhost.localdomain">
<Property ovf:key="fqdn" ovf:type="string" ovf:userConfigurable="true">
<Label>2.6. FQDN</Label>
<Description>The fully qualified domain name of this VM. Leave blank if DHCP is desired.</Description>
</Property>
Expand Down
17 changes: 9 additions & 8 deletions installer/engine_installer/engine_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ type EngineInstaller struct {

// AuthHTML holds the invalid login variable
type AuthHTML struct {
InvalidLogin bool
InvalidLogin bool
ConnectionError bool
}

// ExecHTMLOptions contains fields for html templating in exec.html
Expand All @@ -75,7 +76,7 @@ func NewEngineInstaller() *EngineInstaller {
return &EngineInstaller{Name: "default-vch"}
}

func (ei *EngineInstaller) populateConfigOptions() *EngineInstallerConfigOptions {
func (ei *EngineInstaller) populateConfigOptions() (*EngineInstallerConfigOptions, error) {
defer trace.End(trace.Begin(""))

vc := ei.loginInfo.Validator.IsVC()
Expand All @@ -84,7 +85,7 @@ func (ei *EngineInstaller) populateConfigOptions() *EngineInstallerConfigOptions
dcs, err := ei.loginInfo.Validator.ListDatacenters()
if err != nil {
log.Infoln(err)
return nil
return nil, err
}
for _, d := range dcs {
log.Infof("DC: %s\n", d)
Expand All @@ -93,7 +94,7 @@ func (ei *EngineInstaller) populateConfigOptions() *EngineInstallerConfigOptions
comp, err := ei.loginInfo.Validator.ListComputeResource()
if err != nil {
log.Infoln(err)
return nil
return nil, err
}
for _, c := range comp {
log.Infof("compute: %s\n", c)
Expand All @@ -102,7 +103,7 @@ func (ei *EngineInstaller) populateConfigOptions() *EngineInstallerConfigOptions
rp, err := ei.loginInfo.Validator.ListResourcePool("*")
if err != nil {
log.Infoln(err)
return nil
return nil, err
}
for _, p := range rp {
log.Infof("rp: %s\n", p)
Expand All @@ -111,7 +112,7 @@ func (ei *EngineInstaller) populateConfigOptions() *EngineInstallerConfigOptions
nets, err := ei.loginInfo.Validator.ListNetworks(!vc) // set to false for vC
if err != nil {
log.Infoln(err)
return nil
return nil, err
}
for _, n := range nets {
log.Infof("net: %s\n", n)
Expand All @@ -120,7 +121,7 @@ func (ei *EngineInstaller) populateConfigOptions() *EngineInstallerConfigOptions
dss, err := ei.loginInfo.Validator.ListDatastores()
if err != nil {
log.Infoln(err)
return nil
return nil, err
}
for _, d := range dss {
log.Infof("ds: %s\n", d)
Expand All @@ -130,7 +131,7 @@ func (ei *EngineInstaller) populateConfigOptions() *EngineInstallerConfigOptions
Networks: nets,
Datastores: dss,
ResourcePools: rp,
}
}, nil
}

func (ei *EngineInstaller) buildCreateCommand(binaryPath string) {
Expand Down
7 changes: 7 additions & 0 deletions installer/engine_installer/html/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ <h1 id="community">Demo VCH Installer Wizard</h1>
</span>
</div>
{{end}}
{{if .ConnectionError}}
<div class="alert-item">
<span class="alert-text">
Unable to gather config options from vCenter.
</span>
</div>
{{end}}
<form method="post">
<h4>Login to vCenter: </h4>
<div class="form-group">
Expand Down
13 changes: 10 additions & 3 deletions installer/engine_installer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,20 @@ func indexHandler(resp http.ResponseWriter, req *http.Request) {
engineInstaller.loginInfo.Target = req.FormValue("target")
engineInstaller.loginInfo.User = req.FormValue("user")
engineInstaller.loginInfo.Password = req.FormValue("password")
if err := engineInstaller.loginInfo.VerifyLogin(); err != nil {
cancel, err := engineInstaller.loginInfo.VerifyLogin()
defer cancel()
if err != nil {
// login failed so show login form again
log.Errorf("error logging in: %s", err.Error())
renderTemplate(resp, "html/auth.html", &AuthHTML{InvalidLogin: true})
renderTemplate(resp, "html/auth.html", &AuthHTML{InvalidLogin: true, ConnectionError: false})
} else {
// vCenter login successful, set resource drop downs
opts := engineInstaller.populateConfigOptions()
opts, err := engineInstaller.populateConfigOptions()
if err != nil {
log.Errorf("error populating config options: %s", err.Error())
renderTemplate(resp, "html/auth.html", &AuthHTML{InvalidLogin: false, ConnectionError: true})
return
}
html := &ExecHTMLOptions{}

html.PublicNetwork = getSelectOptionHTML(opts.Networks, publicNetName)
Expand Down
4 changes: 3 additions & 1 deletion installer/fileserver/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func registerHandler(resp http.ResponseWriter, req *http.Request) {
admin.Target = r.Target
admin.User = r.User
admin.Password = r.Password
if err := admin.VerifyLogin(); err != nil {
cancel, err := admin.VerifyLogin()
defer cancel()
if err != nil {
http.Error(resp, err.Error(), http.StatusUnauthorized)
return
}
Expand Down
34 changes: 17 additions & 17 deletions installer/fileserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"html/template"
"io/ioutil"
"net"
"net/http"
"os"
"path/filepath"
Expand All @@ -40,16 +39,16 @@ import (
)

type config struct {
addr string
certPath string
keyPath string
cert tls.Certificate
serveDir string
serverIP net.IP
admiralPort string
installerPort string
vicTarName string
logLevel string
addr string
certPath string
keyPath string
cert tls.Certificate
serveDir string
serverHostname string
admiralPort string
installerPort string
vicTarName string
logLevel string
}

// IndexHTMLOptions contains fields for html templating in index.html
Expand Down Expand Up @@ -142,7 +141,7 @@ func Init(conf *config) {
}

if ip, err := ip.FirstIPv4(ip.Eth0Interface); err == nil {
conf.serverIP = ip
conf.serverHostname = getHostname(ovf, ip)
if port, ok := ovf.Properties["management_portal.port"]; ok {
conf.admiralPort = port
}
Expand Down Expand Up @@ -213,8 +212,9 @@ func indexHandler(resp http.ResponseWriter, req *http.Request) {
admin.Password = req.FormValue("password")
pscInstance = req.FormValue("psc")
pscDomain = req.FormValue("pscDomain")

if err := admin.VerifyLogin(); err != nil {
cancel, err := admin.VerifyLogin()
defer cancel()
if err != nil {
log.Infof("Validation failed: %s", err.Error())
html.InvalidLogin = true

Expand All @@ -230,9 +230,9 @@ func indexHandler(resp http.ResponseWriter, req *http.Request) {
}
}

html.AdmiralAddr = fmt.Sprintf("https://%s:%s", c.serverIP.String(), c.admiralPort)
html.DemoVCHAddr = fmt.Sprintf("https://%s:%s", c.serverIP.String(), c.installerPort)
html.FileserverAddr = fmt.Sprintf("https://%s/files/%s", c.serverIP.String()+c.addr, c.vicTarName)
html.AdmiralAddr = fmt.Sprintf("https://%s:%s", c.serverHostname, c.admiralPort)
html.DemoVCHAddr = fmt.Sprintf("https://%s:%s", c.serverHostname, c.installerPort)
html.FileserverAddr = fmt.Sprintf("https://%s%s/files/%s", c.serverHostname, c.addr, c.vicTarName)

renderTemplate(resp, "html/index.html", html)
}
Expand Down
29 changes: 28 additions & 1 deletion installer/fileserver/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"context"
"fmt"
"net"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -105,7 +106,7 @@ func registerWithPSC(ctx context.Context) error {
"--domainController=" + pscInstance,
"--username=" + admin.User,
"--password=" + admin.Password,
"--admiralUrl=" + fmt.Sprintf("https://%s:%s", vmIP.String(), admiralPort),
"--admiralUrl=" + fmt.Sprintf("https://%s:%s", getHostname(ovf, vmIP), admiralPort),
"--configDir=" + pscConfDir,
}

Expand Down Expand Up @@ -133,3 +134,29 @@ func registerWithPSC(ctx context.Context) error {

return nil
}

func getHostname(ovf lib.Environment, vmIP net.IP) string {

// Until we gix transient hostnames, use the static hostname reported by hostnamectl.
// os.Hostname() returns the kernel hostname, with no regard to transient or static classifications.
// fqdn, err := os.Hostname()
// var url string
// if err == nil && fqdn != "" {
// return fqdn
// } else {
// return vmIP.String()
// }

command := "hostnamectl status --static"
// #nosec: Subprocess launching with variable.
out, err := exec.Command("/bin/bash", "-c", command).Output()
if err != nil {
log.Errorf(err.Error())
return vmIP.String()
}
outString := strings.TrimSpace(string(out))
if outString == "" {
return vmIP.String()
}
return outString
}
5 changes: 2 additions & 3 deletions installer/lib/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type LoginInfo struct {
}

// Verify login based on info given, return non nil error if validation fails.
func (info *LoginInfo) VerifyLogin() error {
func (info *LoginInfo) VerifyLogin() (context.CancelFunc, error) {
defer trace.End(trace.Begin(""))

var u url.URL
Expand All @@ -59,7 +59,6 @@ func (info *LoginInfo) VerifyLogin() error {
input.Password = &passwd

ctx, cancel := context.WithTimeout(context.Background(), loginTimeout)
defer cancel()
loginResponse := make(chan error, 1)
var v *validate.Validator
var err error
Expand All @@ -83,5 +82,5 @@ func (info *LoginInfo) VerifyLogin() error {

}

return <-loginResponse
return cancel, <-loginResponse
}