Skip to content

Commit eb6ee87

Browse files
IndulekhaPrathapanIndulekha Prathapan
andauthored
Allowing tls config to be passed to sm login (#596)
Co-authored-by: Indulekha Prathapan <im020078@broadcom.net>
1 parent 7c3c9f8 commit eb6ee87

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

internal/authctx/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func getUserAuthCtxHeaders(config *TanzuContext) func() (map[string]string, erro
101101
username := config.SMUsername
102102

103103
return func() (map[string]string, error) {
104-
return getSMUserAuthCtx(issuerURL, username, token)
104+
return getSMUserAuthCtx(issuerURL, username, token, proxyConfig)
105105
}
106106
}
107107

internal/authctx/selfmanaged.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package authctx
66

77
import (
88
"context"
9+
"crypto/tls"
910
"fmt"
1011
"net/http"
1112
"net/url"
@@ -16,6 +17,8 @@ import (
1617
"go.pinniped.dev/pkg/oidcclient/pkce"
1718
"go.pinniped.dev/pkg/oidcclient/state"
1819
"golang.org/x/oauth2"
20+
21+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/proxy"
1922
)
2023

2124
const (
@@ -35,18 +38,24 @@ const (
3538

3639
type smSession struct {
3740
sharedOauthConfig *oauth2.Config
41+
tlsConfig *tls.Config
3842
issuerURL, username, password string
3943
pkceCodePair pkce.Code
4044
stateVal state.State
4145
}
4246

4347
// todo: proxy support is not added for the self-managed flow. Add it when there is a requirement.
44-
func getSMUserAuthCtx(pinnipedURL, uName, password string) (metadata map[string]string, err error) {
48+
func getSMUserAuthCtx(pinnipedURL, uName, password string, config *proxy.TLSConfig) (metadata map[string]string, err error) {
4549
if pinnipedURL == "" || uName == "" || password == "" {
4650
return nil, errors.New("Invalid auth configuration for self_managed")
4751
}
4852

49-
session, err := initSession(pinnipedURL, uName, password)
53+
tlsConfig, err := proxy.GetConnectorTLSConfig(config)
54+
if err != nil {
55+
return nil, err
56+
}
57+
58+
session, err := initSession(pinnipedURL, uName, password, tlsConfig)
5059
if err != nil {
5160
return nil, err
5261
}
@@ -111,7 +120,7 @@ func getSMUserAuthCtx(pinnipedURL, uName, password string) (metadata map[string]
111120
}
112121

113122
// todo: if slowness is experienced, then we can avoid re-initialising same values again.
114-
func initSession(pinnipedURL, uName, password string) (*smSession, error) {
123+
func initSession(pinnipedURL, uName, password string, config *tls.Config) (*smSession, error) {
115124
// TMC Local Pinniped sample endpoint:
116125
// https://pinniped-supervisor.*******.com/provider/pinniped
117126
u := url.URL{
@@ -137,6 +146,7 @@ func initSession(pinnipedURL, uName, password string) (*smSession, error) {
137146

138147
session := &smSession{
139148
sharedOauthConfig: sharedOauthConfig,
149+
tlsConfig: config,
140150
issuerURL: issuerURL,
141151
username: uName,
142152
password: password,
@@ -192,6 +202,9 @@ func (s *smSession) initiateAuthorizeRequestUnamePwd() (*url.URL, error) {
192202

193203
redirected := false
194204
httpClient := &http.Client{
205+
Transport: &http.Transport{
206+
TLSClientConfig: s.tlsConfig,
207+
},
195208
CheckRedirect: func(r *http.Request, via []*http.Request) error {
196209
redirected = true
197210
return http.ErrUseLastResponse
@@ -230,7 +243,7 @@ func (s *smSession) getAuthCodeURL() string {
230243
}
231244

232245
func refreshSMUserAuthCtx(config *TanzuContext) {
233-
md, _ := getSMUserAuthCtx(config.VMWCloudEndPoint, config.SMUsername, config.Token)
246+
md, _ := getSMUserAuthCtx(config.VMWCloudEndPoint, config.SMUsername, config.Token, config.TLSConfig)
234247
for key, value := range md {
235248
config.TMCConnection.Headers.Set(key, value)
236249
}

0 commit comments

Comments
 (0)