@@ -6,12 +6,14 @@ package authctx
66
77import (
88 "context"
9+ "crypto/tls"
910 "fmt"
1011 "net/http"
1112 "net/url"
1213 "time"
1314
1415 "github.com/pkg/errors"
16+ "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/proxy"
1517 oidcapi "go.pinniped.dev/generated/latest/apis/supervisor/oidc"
1618 "go.pinniped.dev/pkg/oidcclient/pkce"
1719 "go.pinniped.dev/pkg/oidcclient/state"
@@ -35,18 +37,24 @@ const (
3537
3638type smSession struct {
3739 sharedOauthConfig * oauth2.Config
40+ tlsConfig * tls.Config
3841 issuerURL , username , password string
3942 pkceCodePair pkce.Code
4043 stateVal state.State
4144}
4245
4346// 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 ) {
47+ func getSMUserAuthCtx (pinnipedURL , uName , password string , config * proxy. TLSConfig ) (metadata map [string ]string , err error ) {
4548 if pinnipedURL == "" || uName == "" || password == "" {
4649 return nil , errors .New ("Invalid auth configuration for self_managed" )
4750 }
4851
49- session , err := initSession (pinnipedURL , uName , password )
52+ tlsConfig , err := proxy .GetConnectorTLSConfig (config )
53+ if err != nil {
54+ return nil , err
55+ }
56+
57+ session , err := initSession (pinnipedURL , uName , password , tlsConfig )
5058 if err != nil {
5159 return nil , err
5260 }
@@ -111,7 +119,7 @@ func getSMUserAuthCtx(pinnipedURL, uName, password string) (metadata map[string]
111119}
112120
113121// todo: if slowness is experienced, then we can avoid re-initialising same values again.
114- func initSession (pinnipedURL , uName , password string ) (* smSession , error ) {
122+ func initSession (pinnipedURL , uName , password string , config * tls. Config ) (* smSession , error ) {
115123 // TMC Local Pinniped sample endpoint:
116124 // https://pinniped-supervisor.*******.com/provider/pinniped
117125 u := url.URL {
@@ -137,6 +145,7 @@ func initSession(pinnipedURL, uName, password string) (*smSession, error) {
137145
138146 session := & smSession {
139147 sharedOauthConfig : sharedOauthConfig ,
148+ tlsConfig : config ,
140149 issuerURL : issuerURL ,
141150 username : uName ,
142151 password : password ,
@@ -192,6 +201,9 @@ func (s *smSession) initiateAuthorizeRequestUnamePwd() (*url.URL, error) {
192201
193202 redirected := false
194203 httpClient := & http.Client {
204+ Transport : & http.Transport {
205+ TLSClientConfig : s .tlsConfig ,
206+ },
195207 CheckRedirect : func (r * http.Request , via []* http.Request ) error {
196208 redirected = true
197209 return http .ErrUseLastResponse
@@ -230,7 +242,7 @@ func (s *smSession) getAuthCodeURL() string {
230242}
231243
232244func refreshSMUserAuthCtx (config * TanzuContext ) {
233- md , _ := getSMUserAuthCtx (config .VMWCloudEndPoint , config .SMUsername , config .Token )
245+ md , _ := getSMUserAuthCtx (config .VMWCloudEndPoint , config .SMUsername , config .Token , config . TLSConfig )
234246 for key , value := range md {
235247 config .TMCConnection .Headers .Set (key , value )
236248 }
0 commit comments