Skip to content

Commit bc65c31

Browse files
authored
Honour endpoint's ssl config when cloning private git repos (#4852)
* Fix helm chart note for ClusterIP * CF Push: Ensure git credentials are not stored in env var - use a specific var for clone url instead of obj that becomes env var - tidy up logic * Fix issue where path was unescaped, causing proxy fetch of gitlab projects containing %2f to 404 * Update clone failed text, repo does not now have to be public * Apply nginx uri substituion fix to nginx.dev.conf as well - think this is only used by docker compose, which isn't supported anymore * Honour endpoint's ssl config when cloning private git repos
1 parent 39b4bd9 commit bc65c31

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/jetstream/plugins/cfapppush/deploy.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ func (cfAppPush *CFAppPush) getGitSCMSource(clientWebSocket *websocket.Conn, tem
390390

391391
loggerURL := info.URL
392392
cloneURL := info.URL
393+
skipSLL := false
393394

394395
// Apply credentials associated with the endpoint
395396
if len(info.EndpointGUID) != 0 {
@@ -398,6 +399,13 @@ func (cfAppPush *CFAppPush) getGitSCMSource(clientWebSocket *websocket.Conn, tem
398399
return StratosProject{}, tempDir, errors.New("Failed to parse SCM URL")
399400
}
400401

402+
cnsiRecord, err := cfAppPush.portalProxy.GetCNSIRecord(info.EndpointGUID)
403+
if err != nil {
404+
return StratosProject{}, tempDir, errors.New("Failed to find endpoint with guid " + info.EndpointGUID)
405+
}
406+
407+
skipSLL = cnsiRecord.SkipSSLValidation
408+
401409
tokenRecord, isTokenFound := cfAppPush.portalProxy.GetCNSITokenRecord(info.EndpointGUID, userGUID)
402410
if isTokenFound {
403411
authTokenDecodedBytes, err := base64.StdEncoding.DecodeString(tokenRecord.AuthToken)
@@ -443,6 +451,7 @@ func (cfAppPush *CFAppPush) getGitSCMSource(clientWebSocket *websocket.Conn, tem
443451
LoggerUrl: loggerURL,
444452
Branch: info.Branch,
445453
Commit: info.CommitHash,
454+
SkipSSL: skipSLL,
446455
}
447456
info.CommitHash, err = cloneRepository(cloneDetails, clientWebSocket, tempDir)
448457
if err != nil {
@@ -601,7 +610,7 @@ func cloneRepository(cloneDetails CloneDetails, clientWebSocket *websocket.Conn,
601610

602611
vcsGit := GetVCS()
603612

604-
err := vcsGit.Create(tempDir, cloneDetails.Url, cloneDetails.Branch)
613+
err := vcsGit.Create(cloneDetails.SkipSSL, tempDir, cloneDetails.Url, cloneDetails.Branch)
605614
if err != nil {
606615
log.Infof("Failed to clone repo %s due to %+v", cloneDetails.LoggerUrl, err)
607616
sendErrorMessage(clientWebSocket, err, CLOSE_FAILED_CLONE)

src/jetstream/plugins/cfapppush/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,5 @@ type CloneDetails struct {
121121
LoggerUrl string
122122
Branch string
123123
Commit string
124+
SkipSSL bool
124125
}

src/jetstream/plugins/cfapppush/vcs.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"bytes"
77
"os"
88
"os/exec"
9+
"strconv"
910
"strings"
1011

1112
log "github.com/sirupsen/logrus"
@@ -14,7 +15,7 @@ import (
1415
var vcsGit = &vcsCmd{
1516
name: "Git",
1617
cmd: "git",
17-
createCmd: []string{"clone -b {branch} {repo} {dir}"},
18+
createCmd: []string{"clone -c http.sslVerify={sslVerify} -b {branch} {repo} {dir} "},
1819
resetToCommitCmd: []string{"reset --hard {commit}"},
1920
checkoutCmd: []string{"checkout refs/remotes/origin/{branch}"},
2021
headCmd: []string{"rev-parse HEAD"},
@@ -35,9 +36,9 @@ type vcsCmd struct {
3536
resetToCommitCmd []string // reset branch to commit
3637
}
3738

38-
func (vcs *vcsCmd) Create(dir string, repo string, branch string) error {
39+
func (vcs *vcsCmd) Create(skipSSL bool, dir string, repo string, branch string) error {
3940
for _, cmd := range vcs.createCmd {
40-
if err := vcs.run(".", cmd, "dir", dir, "repo", repo, "branch", branch); err != nil {
41+
if err := vcs.run(".", cmd, "sslVerify", strconv.FormatBool(!skipSSL), "dir", dir, "repo", repo, "branch", branch); err != nil {
4142
return err
4243
}
4344
}

0 commit comments

Comments
 (0)