Skip to content
Open
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
1 change: 1 addition & 0 deletions auth_providers/auth_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func (a *CommandAuthConfigBasic) GetServerConfig() *Server {
SkipTLSVerify: a.SkipVerify,
CACertPath: a.CommandCACert,
AuthType: "basic",
ClientTimeout: a.HttpClientTimeout,
}
return &server
}
Expand Down
37 changes: 34 additions & 3 deletions auth_providers/auth_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,28 @@ func cleanHostName(hostName string) string {
return hostName
}

// parseHostPort splits a "hostname:port" string into its parts.
// If no port is present, returns the hostname and 0.
func parseHostPort(hostName string) (string, int) {
if idx := strings.LastIndex(hostName, ":"); idx != -1 {
portStr := hostName[idx+1:]
port := 0
for _, c := range portStr {
if c < '0' || c > '9' {
return hostName, 0
}
port = port*10 + int(c-'0')
}
if port > 0 {
return hostName[:idx], port
}
}
return hostName, 0
}

// WithCommandHostName sets the hostname for authentication to Keyfactor Command API.
// If hostName contains a port (e.g. "host:9443"), the port is extracted and applied
// via WithCommandPort so the SDK does not double-append a port to the URL.
func (c *CommandAuthConfig) WithCommandHostName(hostName string) *CommandAuthConfig {

//check for http or https prefix
Expand All @@ -179,7 +200,13 @@ func (c *CommandAuthConfig) WithCommandHostName(hostName string) *CommandAuthCon
}

hostName = cleanHostName(hostName)
c.CommandHostName = hostName
host, port := parseHostPort(hostName)
if port > 0 {
c.CommandHostName = host
c.CommandPort = port
} else {
c.CommandHostName = hostName
}
return c
}

Expand Down Expand Up @@ -485,11 +512,14 @@ func (c *CommandAuthConfig) Authenticate() error {
headers["Authorization"] = c.AuthHeader
}

authHost := c.CommandHostName
if c.CommandPort > 0 && c.CommandPort != DefaultCommandPort {
authHost = fmt.Sprintf("%s:%d", c.CommandHostName, c.CommandPort)
}
endPoint := fmt.Sprintf(
"%s://%s/%s/Status/Endpoints",
c.HttpProtocol,
c.CommandHostName,
//c.CommandPort,
authHost,
c.CommandAPIPath,
)
log.Printf("[DEBUG] testing auth using endpoint %s ", endPoint)
Expand Down Expand Up @@ -763,6 +793,7 @@ func (c *CommandAuthConfig) GetServerConfig() *Server {
SkipTLSVerify: c.SkipVerify,
CACertPath: c.CommandCACert,
AuthType: "",
ClientTimeout: c.HttpClientTimeout,
}
return &server
}
Expand Down
1 change: 1 addition & 0 deletions auth_providers/auth_kerberos.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ func (k *CommandAuthConfigKerberos) GetServerConfig() *Server {
SkipTLSVerify: k.SkipVerify,
CACertPath: k.CommandCACert,
AuthType: "kerberos",
ClientTimeout: k.HttpClientTimeout,
KerberosRealm: k.Realm,
KerberosKeytab: k.KeytabPath,
KerberosConfig: k.ConfigPath,
Expand Down
1 change: 1 addition & 0 deletions auth_providers/auth_oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ func (b *CommandConfigOauth) GetServerConfig() *Server {
SkipTLSVerify: b.SkipVerify,
CACertPath: b.CommandCACert,
AuthType: "oauth",
ClientTimeout: b.HttpClientTimeout,
}
return &server
}
Expand Down
5 changes: 5 additions & 0 deletions auth_providers/command_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ type Server struct {
CACertPath string `json:"ca_cert_path,omitempty" yaml:"ca_cert_path,omitempty"` // CACertPath is the path to the CA certificate to trust.
AuthType string `json:"auth_type,omitempty" yaml:"auth_type,omitempty"` // AuthType is the type of authentication to use.

// ClientTimeout is the HTTP client timeout in seconds. When zero, kfc-auth
// falls back to the KEYFACTOR_CLIENT_TIMEOUT env var or a built-in
// default. Maps to CommandAuthConfig.HttpClientTimeout.
ClientTimeout int `json:"client_timeout,omitempty" yaml:"client_timeout,omitempty"`

// Kerberos authentication fields
KerberosRealm string `json:"kerberos_realm,omitempty" yaml:"kerberos_realm,omitempty"` // KerberosRealm is the Kerberos realm (uppercase).
KerberosKeytab string `json:"kerberos_keytab,omitempty" yaml:"kerberos_keytab,omitempty"` // KerberosKeytab is the path to the keytab file.
Expand Down
Loading