mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 21:12:07 +00:00
Setup TLS with CA Cert
- Extend config to take a path to a CA Certificate - Use the CA Cert when establishing a connection with the SOAP client Testing We provide certs and keys for tests as fixtures, `vclib/fixtures`. Those were created (and can be regenerated) using `vclib/fixtures/createCerts.sh`. At the moment it's possible to configure a CA path and at the same time allow insecure communication between vsphere cloud provider and vcenter. This may change in the future; we might opt for overwriting the insecure communication if a CA is configured / log and transparently pass the arguments to the vcenter command / other. To be discussed. At the moment the CA is a global level configuration. In other words, all vcenter servers need to use certificates signed by the same CA. There might be use cases for different CA per vcenter server; to be discussed.
This commit is contained in:
parent
ec37c0f643
commit
9fc231e5c0
@ -19,8 +19,12 @@ package vclib
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
|
"errors"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
neturl "net/url"
|
neturl "net/url"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -38,6 +42,7 @@ type VSphereConnection struct {
|
|||||||
Password string
|
Password string
|
||||||
Hostname string
|
Hostname string
|
||||||
Port string
|
Port string
|
||||||
|
CACert string
|
||||||
Insecure bool
|
Insecure bool
|
||||||
RoundTripperCount uint
|
RoundTripperCount uint
|
||||||
credentialsLock sync.Mutex
|
credentialsLock sync.Mutex
|
||||||
@ -130,11 +135,50 @@ func (connection *VSphereConnection) login(ctx context.Context, client *vim25.Cl
|
|||||||
// Logout calls SessionManager.Logout for the given connection.
|
// Logout calls SessionManager.Logout for the given connection.
|
||||||
func (connection *VSphereConnection) Logout(ctx context.Context) {
|
func (connection *VSphereConnection) Logout(ctx context.Context) {
|
||||||
m := session.NewManager(connection.Client)
|
m := session.NewManager(connection.Client)
|
||||||
|
|
||||||
|
hasActiveSession, err := m.SessionIsActive(ctx)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("Logout failed: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !hasActiveSession {
|
||||||
|
glog.Errorf("No active session, cannot logout")
|
||||||
|
return
|
||||||
|
}
|
||||||
if err := m.Logout(ctx); err != nil {
|
if err := m.Logout(ctx); err != nil {
|
||||||
glog.Errorf("Logout failed: %s", err)
|
glog.Errorf("Logout failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrCaCertNotReadable = errors.New("Could not read CA cert file")
|
||||||
|
ErrCaCertInvalid = errors.New("Could not parse CA cert file")
|
||||||
|
ErrUnsupportedTransport = errors.New("Only support HTTP transport if configuring TLS")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (connection *VSphereConnection) ConfigureTransportWithCA(transport http.RoundTripper) error {
|
||||||
|
caCertBytes, err := ioutil.ReadFile(connection.CACert)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("Could not read CA cert file, %s", connection.CACert)
|
||||||
|
return ErrCaCertNotReadable
|
||||||
|
}
|
||||||
|
certPool := x509.NewCertPool()
|
||||||
|
|
||||||
|
if ok := certPool.AppendCertsFromPEM(caCertBytes); !ok {
|
||||||
|
glog.Errorf("Cannot add CA to cert pool")
|
||||||
|
return ErrCaCertInvalid
|
||||||
|
}
|
||||||
|
httpTransport, ok := transport.(*http.Transport)
|
||||||
|
if !ok {
|
||||||
|
glog.Errorf("Failed to http transport")
|
||||||
|
return ErrUnsupportedTransport
|
||||||
|
}
|
||||||
|
|
||||||
|
httpTransport.TLSClientConfig.RootCAs = certPool
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// NewClient creates a new govmomi client for the VSphereConnection obj
|
// NewClient creates a new govmomi client for the VSphereConnection obj
|
||||||
func (connection *VSphereConnection) NewClient(ctx context.Context) (*vim25.Client, error) {
|
func (connection *VSphereConnection) NewClient(ctx context.Context) (*vim25.Client, error) {
|
||||||
url, err := soap.ParseURL(net.JoinHostPort(connection.Hostname, connection.Port))
|
url, err := soap.ParseURL(net.JoinHostPort(connection.Hostname, connection.Port))
|
||||||
@ -144,11 +188,19 @@ func (connection *VSphereConnection) NewClient(ctx context.Context) (*vim25.Clie
|
|||||||
}
|
}
|
||||||
|
|
||||||
sc := soap.NewClient(url, connection.Insecure)
|
sc := soap.NewClient(url, connection.Insecure)
|
||||||
|
|
||||||
|
if connection.CACert != "" {
|
||||||
|
if err := connection.ConfigureTransportWithCA(sc.Client.Transport); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
client, err := vim25.NewClient(ctx, sc)
|
client, err := vim25.NewClient(ctx, sc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to create new client. err: %+v", err)
|
glog.Errorf("Failed to create new client. err: %+v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = connection.login(ctx, client)
|
err = connection.login(ctx, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
122
pkg/cloudprovider/providers/vsphere/vclib/connection_test.go
Normal file
122
pkg/cloudprovider/providers/vsphere/vclib/connection_test.go
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
package vclib_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
|
"crypto/x509"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/vsphere/vclib"
|
||||||
|
)
|
||||||
|
|
||||||
|
func createTestServer(t *testing.T, caCertPath, serverCertPath, serverKeyPath string, handler http.HandlerFunc) *httptest.Server {
|
||||||
|
caCertPEM, err := ioutil.ReadFile(caCertPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not read ca cert from file")
|
||||||
|
}
|
||||||
|
|
||||||
|
serverCert, err := tls.LoadX509KeyPair(serverCertPath, serverKeyPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not load server cert and server key from files: %#v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
certPool := x509.NewCertPool()
|
||||||
|
if ok := certPool.AppendCertsFromPEM(caCertPEM); !ok {
|
||||||
|
t.Fatalf("Cannot add CA to CAPool")
|
||||||
|
}
|
||||||
|
|
||||||
|
server := httptest.NewUnstartedServer(http.HandlerFunc(handler))
|
||||||
|
server.TLS = &tls.Config{
|
||||||
|
Certificates: []tls.Certificate{
|
||||||
|
serverCert,
|
||||||
|
},
|
||||||
|
RootCAs: certPool,
|
||||||
|
}
|
||||||
|
|
||||||
|
return server
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSomething(t *testing.T) {
|
||||||
|
caCertPath := "fixtures/ca.pem"
|
||||||
|
serverCertPath := "fixtures/server.pem"
|
||||||
|
serverKeyPath := "fixtures/server.key"
|
||||||
|
|
||||||
|
gotRequest := false
|
||||||
|
handler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
gotRequest = true
|
||||||
|
}
|
||||||
|
|
||||||
|
server := createTestServer(t, caCertPath, serverCertPath, serverKeyPath, handler)
|
||||||
|
server.StartTLS()
|
||||||
|
|
||||||
|
u, err := url.Parse(server.URL)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Cannot parse URL: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
connection := &vclib.VSphereConnection{
|
||||||
|
Hostname: u.Hostname(),
|
||||||
|
Port: u.Port(),
|
||||||
|
CACert: "fixtures/ca.pem",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignoring error here, because we only care about the TLS connection
|
||||||
|
connection.NewClient(context.Background())
|
||||||
|
|
||||||
|
if !gotRequest {
|
||||||
|
t.Fatalf("Never saw a request, TLS connection could not be established")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWithInvalidCaCertPath(t *testing.T) {
|
||||||
|
connection := &vclib.VSphereConnection{
|
||||||
|
Hostname: "should-not-matter",
|
||||||
|
Port: "should-not-matter",
|
||||||
|
CACert: "invalid-path",
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := connection.NewClient(context.Background())
|
||||||
|
|
||||||
|
if err != vclib.ErrCaCertNotReadable {
|
||||||
|
t.Fatalf("should have occoured")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInvalidCaCert(t *testing.T) {
|
||||||
|
connection := &vclib.VSphereConnection{
|
||||||
|
Hostname: "should-not-matter",
|
||||||
|
Port: "should-not-matter",
|
||||||
|
CACert: "fixtures/invalid.pem",
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := connection.NewClient(context.Background())
|
||||||
|
|
||||||
|
if err != vclib.ErrCaCertInvalid {
|
||||||
|
t.Fatalf("should have occoured")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnsupportedTransport(t *testing.T) {
|
||||||
|
notHttpTransport := new(fakeTransport)
|
||||||
|
|
||||||
|
connection := &vclib.VSphereConnection{
|
||||||
|
Hostname: "should-not-matter",
|
||||||
|
Port: "should-not-matter",
|
||||||
|
CACert: "fixtures/ca.pem",
|
||||||
|
}
|
||||||
|
|
||||||
|
err := connection.ConfigureTransportWithCA(notHttpTransport)
|
||||||
|
if err != vclib.ErrUnsupportedTransport {
|
||||||
|
t.Fatalf("should have occured")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type fakeTransport struct{}
|
||||||
|
|
||||||
|
func (ft fakeTransport) RoundTrip(*http.Request) (*http.Response, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
51
pkg/cloudprovider/providers/vsphere/vclib/fixtures/ca.key
Normal file
51
pkg/cloudprovider/providers/vsphere/vclib/fixtures/ca.key
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
-----BEGIN RSA PRI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WjskxZ6iI+rlfQwbH
|
||||||
|
0qqBurMQYyUPBT1xlfPSB8UkLzX3hPIa6nYlysBcWNjQLDZBeS8gq+wQ5YtxTW+8
|
||||||
|
9ei/6DXGU0QS6LjNbYwDJg9wOillPDijnhUtQnh/gB8MXbObQ0VIAmpZsKLmvnI/
|
||||||
|
yirvAV5216v5rVbIeGquw+6qHw3Imkv6YCgkLwbWt+atIENLBef4w/3p9GAiCanr
|
||||||
|
Z6CInb5f2YeYhv68XMod3XE8vN88P28A3SzxSY2CO3dNHT8T8lpXRr/Q8sNru5u4
|
||||||
|
d7CocCMQaUbilm92TgbVSu6bKdxrGbu03jzbBbcUeYpqR74o+Y9Rgvgb2tIQ
|
||||||
|
-----END RSA PRIVATE KEY-----
|
29
pkg/cloudprovider/providers/vsphere/vclib/fixtures/ca.pem
Normal file
29
pkg/cloudprovider/providers/vsphere/vclib/fixtures/ca.pem
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIE/DCCAuQCCQDsqyXMQlDdzzANBgkqhkiG9w0BAQsFADBAMQswCQYDVQQGEwJV
|
||||||
|
UzELMAkGA1UECAwCQ0ExEzARBgNVBAoMCkFjbWUsIEluYy4xDzANBgNVBAMMBnNv
|
||||||
|
bWVDQTAeFw0xODA2MDQxNDU3NDZaFw00NjA2MTcxNDU3NDZaMEAxCzAJBgNVBAYT
|
||||||
|
AlVTMQswCQYDVQQIDAJDQTETMBEGA1UECgwKQWNtZSwgSW5jLjEPMA0GA1UEAwwG
|
||||||
|
c29tZUNBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAsQRltjBKCgsI
|
||||||
|
C4xGN5OWzJSaIhA1F8l4YO/7yGBj4ehKmEBrjbOFMnUOp7Aq1rj/yrLzHNeKja9P
|
||||||
|
D3fSsLMgbv34DR4JMXlbh2Cm84XBp1ibrqxmqsz9nAGiDcJKf0QodxzAYcq8CZ0X
|
||||||
|
os1glgwHBSuf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LM+
|
||||||
|
aKDnDlB+I4e4WegodvTlDaYvtJUQaAlefGmfP+r9I5fPvbGRJDJ7AoirJnv2MCLs
|
||||||
|
hNbEXk/+/oNWIHAFQTNNzS40U05ytPBrtPoAOL2e+a92rHcWfsZ/ApYSCesZxZNw
|
||||||
|
1k2siPQ8uKBM10AW0fMU8wZs02LYcR5Xq1Zaj/GWooZaAy6QQfZK6AELpdLSZmMs
|
||||||
|
tzPz6gxckswJEnZ3w/wyzHmSMSJrr2+dydYA/UN509V/nQQolgE/ZQoMUlu74wCf
|
||||||
|
HEeQH71L269fQM1RxuAEfBz0RuEZjQc7A9NETm5I0BM=
|
||||||
|
-----END CERTIFICATE-----
|
61
pkg/cloudprovider/providers/vsphere/vclib/fixtures/createCerts.sh
Executable file
61
pkg/cloudprovider/providers/vsphere/vclib/fixtures/createCerts.sh
Executable file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
# 1. create CA key
|
||||||
|
# 2. create CA cert
|
||||||
|
# 3. create CSR with IP SAN
|
||||||
|
# 4. create server cert with IP SAN
|
||||||
|
|
||||||
|
createKey() {
|
||||||
|
openssl genrsa -out "$1" 4096
|
||||||
|
}
|
||||||
|
|
||||||
|
createCaCert() {
|
||||||
|
openssl req -x509 \
|
||||||
|
-subj "/C=US/ST=CA/O=Acme, Inc./CN=someCA" \
|
||||||
|
-new -nodes -key "$2" -sha256 -days 10240 -out "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
createCSR() {
|
||||||
|
openssl req -new -sha256 \
|
||||||
|
-key "$2" \
|
||||||
|
-subj "/C=US/ST=CA/O=Acme, Inc./CN=localhost" \
|
||||||
|
-reqexts SAN \
|
||||||
|
-config <(
|
||||||
|
cat /etc/ssl/openssl.cnf ; \
|
||||||
|
printf '\n[SAN]\n' ; \
|
||||||
|
getSAN
|
||||||
|
) \
|
||||||
|
-out "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
signCSR() {
|
||||||
|
openssl x509 -req -in "$2" \
|
||||||
|
-CA "$3" \
|
||||||
|
-CAkey "$4" \
|
||||||
|
-CAcreateserial \
|
||||||
|
-days 3650 -sha256 \
|
||||||
|
-extfile <( getSAN ) \
|
||||||
|
-out "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
getSAN() {
|
||||||
|
printf "subjectAltName=DNS:localhost,IP:127.0.0.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
local caCertPath="./ca.pem"
|
||||||
|
local caKeyPath="./ca.key"
|
||||||
|
local serverCsrPath="./server.csr"
|
||||||
|
local serverCertPath="./server.pem"
|
||||||
|
local serverKeyPath="./server.key"
|
||||||
|
|
||||||
|
createKey "$caKeyPath"
|
||||||
|
createCaCert "$caCertPath" "$caKeyPath"
|
||||||
|
createKey "$serverKeyPath"
|
||||||
|
createCSR "$serverCsrPath" "$serverKeyPath"
|
||||||
|
signCSR "$serverCertPath" "$serverCsrPath" "$caCertPath" "$caKeyPath"
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
@ -0,0 +1 @@
|
|||||||
|
this is some invalid content
|
@ -0,0 +1,28 @@
|
|||||||
|
-----BEGIN CERTIFICATE REQUEST-----
|
||||||
|
MIIEtTCCAp0CAQAwQzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRMwEQYDVQQK
|
||||||
|
DApBY21lLCBJbmMuMRIwEAYDVQQDDAlsb2NhbGhvc3QwggIiMA0GCSqGSIb3DQEB
|
||||||
|
AQUAA4ICDwAwggIKAoICAQDRtnbdQFkM8IgTx2KU2lyZitrgqhcxRVGaMrw+d+Q0
|
||||||
|
3IZ9y8L4sVFjBqAXUIkCndfQSVyzAnSgrvJqpFk43TIbg7TY/ZpLdN+tHn+PT3qN
|
||||||
|
MYjOIMR+BVpT8Fi23Ds5ghVw26Av4ZfT6a3R2e4ndsdvwM7nf+8YwU2qPwu48cDN
|
||||||
|
OLCGoV9JUZADoHH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zWDEqUPVvVoX4
|
||||||
|
g2MgLVtcb6WcstQpsQ+AY0rKPq8K4T5t420JtRLI9oUt5eQm7yWGFF1p4URWzuYq
|
||||||
|
/TOTPxIrufeFfqBsH8XAOydmuwUGunpefoxvD0tp9SFpRm6NWliYyunFZP82xtOK
|
||||||
|
eP3aW3A1KnPdLgAyi9/iwi9VzGQTu1iWAc9si9xTyqTNOtvgYUzy2wmic2HgWfEs
|
||||||
|
NEv+wW6CNh1qR1Vq7j0zkl327CFrGBvKbR1d5cleNx8EiWZ1QNmickMaCHBiwkql
|
||||||
|
yIbSPtlmzme8y8N73bUaV74DbKExZvu2CnUzdIHOt0Dpax6TkBHc1HI530v58eN/
|
||||||
|
VDP7+tBBVo+c
|
||||||
|
-----END CERTIFICATE REQUEST-----
|
@ -0,0 +1,51 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIJKAIBAAKCAgEA0bZ23UBZDPCIE8dilNpcmYra4KoXMUVRmjK8PnfkNNyGfcvC
|
||||||
|
+LFRYwagF1CJAp3X0ElcswJ0oK7yaqRZON0yG4O02P2aS3TfrR5/j096jTGIziDE
|
||||||
|
fgVaU/BYttw7OYIVcNugL+GX0+mt0dnuJ3bHb8DO53/vGMFNqj8LuPHAzTiwhqFf
|
||||||
|
SVGQA6Bx1UDgvS2X1FrUsVNM4Z5xFsrt9ziJ8wbcE0na8ULotvO7L3CQU15DJUc4
|
||||||
|
+WnQGQSfM4cbDcbOpT0F/wu1d8o0xHUr52ALaBmxT6oeQ+Gh8O1Y62se2YoVAqSC
|
||||||
|
fjX9NVM88apF4ZX9PKnDMQPDCEQ7o8LGNgyrtU6Wap/nwz9J31lHvzye3e4VB5Hb
|
||||||
|
x9PQ/HLD+9kcrvjZoG8dYD4L/rKxhwsFQhWtR4PqKurtlKtnlulbdy3EXPEtcxug
|
||||||
|
o7xbYVOxLq4emtnbA71g0rLdyTZ5DhXki4zqmubQ0jYeUmSG2dewYoog+jCKkQwY
|
||||||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wB64GigTPlB5h2VZUG35W5e6hLQaOJRWEJc/fhty4Yet
|
||||||
|
mjphAoIBAAw9yzWfEkL4dJ+wq96iwTdh6QNw8pBtXdzXyJneS74qFluShYuvzjtu
|
||||||
|
nR0IdrUyf3y+GCvaV+xT4eKEyqMNXexoyKLcts27Ui8NpOyseaxRMqevMGD6LFIB
|
||||||
|
RT6Ap1KB7IVPRRCOTVLzJPrdKMR6Rt/+jF8k3HDQnO1zN7rZ/W98DmWxcSdPPFe6
|
||||||
|
X6Y5F0h/4JJr1Yqk9raZxCFop4pDzqjFtaaYaVf4a2sHGS8826RR29679MUrojpx
|
||||||
|
PUku6KxK0DLWYENJzkH0t2FqSW8rs2lwlT0tSXJFq9UuyDrKW/+n4QtWZ5KS5VZH
|
||||||
|
d7ugCWNzhpXmCtjkeKU8uOBxI4/i0RUCggEBAI0lOMpRLkUIwaJhqyw7RZAjUKBz
|
||||||
|
dCAp4EqwngNS+tCg+S9vgmXhXqgNwnLMGgiHsmA/2oqm8pWpIjMYe0KG1XNrIcVv
|
||||||
|
582Z80eHqbfrx4xmzez1dwAmHNJLc+pQfK7gHQkE7DOkesNNOCIich3x4BktMtkl
|
||||||
|
JPybU39x5h/BsFvG0MlDggXp+Qw4p+JWiYnfVR+oeOQOGdKlnZCBog0ou4SyLSjL
|
||||||
|
zx8zBdL3dlnaDJIO13cW42rd/tlUNfTYH8qjGfZnlDUCGgYktZusUvzRlTJxNFv0
|
||||||
|
Waz7xEnhXsUPqTr2dK+4CUScs4aoDdOBLiS1sFwvgvNku02OmnX1BtPgAws=
|
||||||
|
-----END RSA PRIVATE KEY-----
|
@ -0,0 +1,30 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIFJDCCAwygAwIBAgIJAOcEAbv8NslcMA0GCSqGSIb3DQEBCwUAMEAxCzAJBgNV
|
||||||
|
BAYTAlVTMQswCQYDVQQIDAJDQTETMBEGA1UECgwKQWNtZSwgSW5jLjEPMA0GA1UE
|
||||||
|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EwDQYJKoZIhvcNAQELBQADggIBAJkQELAVTJSS
|
||||||
|
1Rfmn9aRXOd6Uap7+3oE3ZOuUU2XxBJKXClVhKcCJ8nToDHsSV6D7fMcgJvg4fOt
|
||||||
|
pkQldEi845mUx0t8F/uKqwO1fx+Cjnr8meArGpwn2bma+4cpZyLbFgAZH7Cst+er
|
||||||
|
FbewtoPbfnADZlZzK35jcSzGf+oYJU11QJjTyRRXBp9eC73Fa9fM53GrA5GkJiSc
|
||||||
|
u7+mRlAKKEMmNNdnZa48X/cKI7UXp+qHSdkE9zDZ/LrbZPV8OuJY/RpwLT1A59pM
|
||||||
|
wkvC1AaGIa+ysfLw7s+0K2B1xmquAdopzcwGmK5CGJQmoF3YEFc+QN5fkC4UbizM
|
||||||
|
XiXZ3Uu0bbg9qNjR99Z0N/knVce+KpAeJg9cEFSsdTM2oaz/53KsalxOWsDkxvuI
|
||||||
|
HGwjSMPO22JWPs9zs06/1CsiQvn7O/Kx4xjwuSzxjKOJaolynF0lUsNXljOnF6FC
|
||||||
|
cQCBsY3TFdJFAtjYouiUu5UI4tvQ6pFmCDfj2Ioj+XhF0pd5G/bM3Hmb+WL9We4s
|
||||||
|
ajoaB85yAy5YdxBuLW5/TdeRqWZHB3AXbAXY8KoOPaOv9NCRWwwaGsiBSUSPdUzT
|
||||||
|
UkqWjMhcZnmHFeKVDQWpVIy1zrVojR17B8/xY9uypg5yZxGpssUwbfi9m/TnPH/A
|
||||||
|
a6U8cIpiDSFdeNYPGwKm8O06pY67+w1I
|
||||||
|
-----END CERTIFICATE-----
|
@ -121,6 +121,9 @@ type VSphereConfig struct {
|
|||||||
VCenterPort string `gcfg:"port"`
|
VCenterPort string `gcfg:"port"`
|
||||||
// True if vCenter uses self-signed cert.
|
// True if vCenter uses self-signed cert.
|
||||||
InsecureFlag bool `gcfg:"insecure-flag"`
|
InsecureFlag bool `gcfg:"insecure-flag"`
|
||||||
|
// Specifies the path to a CA certificate in PEM format. Optional; if not
|
||||||
|
// configured, the system's CA certificates will be used.
|
||||||
|
CAFile string `gcfg:"ca-file"`
|
||||||
// Datacenter in which VMs are located.
|
// Datacenter in which VMs are located.
|
||||||
// Deprecated. Use "datacenters" instead.
|
// Deprecated. Use "datacenters" instead.
|
||||||
Datacenter string `gcfg:"datacenter"`
|
Datacenter string `gcfg:"datacenter"`
|
||||||
@ -345,7 +348,9 @@ func populateVsphereInstanceMap(cfg *VSphereConfig) (map[string]*VSphereInstance
|
|||||||
Insecure: cfg.Global.InsecureFlag,
|
Insecure: cfg.Global.InsecureFlag,
|
||||||
RoundTripperCount: vcConfig.RoundTripperCount,
|
RoundTripperCount: vcConfig.RoundTripperCount,
|
||||||
Port: vcConfig.VCenterPort,
|
Port: vcConfig.VCenterPort,
|
||||||
|
CACert: cfg.Global.CAFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
vsphereIns := VSphereInstance{
|
vsphereIns := VSphereInstance{
|
||||||
conn: &vSphereConn,
|
conn: &vSphereConn,
|
||||||
cfg: &vcConfig,
|
cfg: &vcConfig,
|
||||||
|
@ -19,6 +19,8 @@ package vsphere
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"crypto/x509"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -89,8 +91,12 @@ func configFromEnv() (cfg VSphereConfig, ok bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// configFromSim starts a vcsim instance and returns config for use against the vcsim instance.
|
|
||||||
func configFromSim() (VSphereConfig, func()) {
|
func configFromSim() (VSphereConfig, func()) {
|
||||||
|
return configFromSimWithTLS(new(tls.Config), true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// configFromSim starts a vcsim instance and returns config for use against the vcsim instance.
|
||||||
|
func configFromSimWithTLS(tlsConfig *tls.Config, insecureAllowed bool) (VSphereConfig, func()) {
|
||||||
var cfg VSphereConfig
|
var cfg VSphereConfig
|
||||||
model := simulator.VPX()
|
model := simulator.VPX()
|
||||||
|
|
||||||
@ -99,7 +105,7 @@ func configFromSim() (VSphereConfig, func()) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
model.Service.TLS = new(tls.Config)
|
model.Service.TLS = tlsConfig
|
||||||
s := model.Service.NewServer()
|
s := model.Service.NewServer()
|
||||||
|
|
||||||
// STS simulator
|
// STS simulator
|
||||||
@ -109,7 +115,8 @@ func configFromSim() (VSphereConfig, func()) {
|
|||||||
// Lookup Service simulator
|
// Lookup Service simulator
|
||||||
model.Service.RegisterSDK(lookup.New())
|
model.Service.RegisterSDK(lookup.New())
|
||||||
|
|
||||||
cfg.Global.InsecureFlag = true
|
cfg.Global.InsecureFlag = insecureAllowed
|
||||||
|
|
||||||
cfg.Global.VCenterIP = s.URL.Hostname()
|
cfg.Global.VCenterIP = s.URL.Hostname()
|
||||||
cfg.Global.VCenterPort = s.URL.Port()
|
cfg.Global.VCenterPort = s.URL.Port()
|
||||||
cfg.Global.User = s.URL.User.Username()
|
cfg.Global.User = s.URL.User.Username()
|
||||||
@ -160,6 +167,7 @@ insecure-flag = true
|
|||||||
datacenter = us-west
|
datacenter = us-west
|
||||||
vm-uuid = 1234
|
vm-uuid = 1234
|
||||||
vm-name = vmname
|
vm-name = vmname
|
||||||
|
ca-file = /some/path/to/a/ca.pem
|
||||||
`))
|
`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Should succeed when a valid config is provided: %s", err)
|
t.Fatalf("Should succeed when a valid config is provided: %s", err)
|
||||||
@ -180,6 +188,10 @@ vm-name = vmname
|
|||||||
if cfg.Global.VMName != "vmname" {
|
if cfg.Global.VMName != "vmname" {
|
||||||
t.Errorf("incorrect vm-name: %s", cfg.Global.VMName)
|
t.Errorf("incorrect vm-name: %s", cfg.Global.VMName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.Global.CAFile != "/some/path/to/a/ca.pem" {
|
||||||
|
t.Errorf("incorrect ca-file: %s", cfg.Global.CAFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewVSphere(t *testing.T) {
|
func TestNewVSphere(t *testing.T) {
|
||||||
@ -250,6 +262,57 @@ func TestVSphereLoginByToken(t *testing.T) {
|
|||||||
vcInstance.conn.Logout(ctx)
|
vcInstance.conn.Logout(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVSphereLoginWithCaCert(t *testing.T) {
|
||||||
|
caCertPath := "./vclib/fixtures/ca.pem"
|
||||||
|
serverCertPath := "./vclib/fixtures/server.pem"
|
||||||
|
serverKeyPath := "./vclib/fixtures/server.key"
|
||||||
|
|
||||||
|
caCertPEM, err := ioutil.ReadFile(caCertPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not read ca cert from file")
|
||||||
|
}
|
||||||
|
|
||||||
|
serverCert, err := tls.LoadX509KeyPair(serverCertPath, serverKeyPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not load server cert and server key from files: %#v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
certPool := x509.NewCertPool()
|
||||||
|
if ok := certPool.AppendCertsFromPEM(caCertPEM); !ok {
|
||||||
|
t.Fatalf("Cannot add CA to CAPool")
|
||||||
|
}
|
||||||
|
|
||||||
|
tlsConfig := tls.Config{
|
||||||
|
Certificates: []tls.Certificate{serverCert},
|
||||||
|
RootCAs: certPool,
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg, cleanup := configFromSimWithTLS(&tlsConfig, false)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
cfg.Global.CAFile = caCertPath
|
||||||
|
|
||||||
|
// Create vSphere configuration object
|
||||||
|
vs, err := newControllerNode(cfg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to construct/authenticate vSphere: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
// Create vSphere client
|
||||||
|
vcInstance, ok := vs.vsphereInstanceMap[cfg.Global.VCenterIP]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("Couldn't get vSphere instance: %s", cfg.Global.VCenterIP)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = vcInstance.conn.Connect(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Failed to connect to vSphere: %s", err)
|
||||||
|
}
|
||||||
|
vcInstance.conn.Logout(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func TestZones(t *testing.T) {
|
func TestZones(t *testing.T) {
|
||||||
cfg := VSphereConfig{}
|
cfg := VSphereConfig{}
|
||||||
cfg.Global.Datacenter = "myDatacenter"
|
cfg.Global.Datacenter = "myDatacenter"
|
||||||
|
Loading…
Reference in New Issue
Block a user