diff --git a/go.mod b/go.mod index 91835940e1..b037ef06e9 100644 --- a/go.mod +++ b/go.mod @@ -17,11 +17,12 @@ require ( github.com/casbin/casbin v1.9.1 github.com/casbin/casbin/v2 v2.97.0 github.com/casbin/xorm-adapter v1.0.1-0.20190716004226-a317737a1007 + github.com/casbin/xorm-adapter/v2 v2.5.1 github.com/coreos/go-oidc v2.2.1+incompatible github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 - github.com/devtron-labs/common-lib v0.0.21-0.20240628105542-603b4f777e00 + github.com/devtron-labs/common-lib v0.0.22-0.20240704103133-ff5ff14e86de github.com/devtron-labs/go-bitbucket v0.9.60-beta github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 github.com/evanphx/json-patch v5.7.0+incompatible @@ -130,7 +131,6 @@ require ( github.com/bombsimon/logrusr/v2 v2.0.1 // indirect github.com/bradleyfalzon/ghinstallation/v2 v2.5.0 // indirect github.com/casbin/govaluate v1.1.0 // indirect - github.com/casbin/xorm-adapter/v2 v2.5.1 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chai2010/gettext-go v1.0.2 // indirect diff --git a/go.sum b/go.sum index d6f609c200..830b427dde 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,7 @@ cloud.google.com/go/storage v1.30.1 h1:uOdMxAs8HExqBlnLtnQyP0YkvbiDpdGShGKtx6U/o cloud.google.com/go/storage v1.30.1/go.mod h1:NfxhC0UJE1aXSx7CIIbCf7y9HKT7BiccwkR7+P7gN8E= dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU= github.com/Azure/azure-pipeline-go v0.2.3 h1:7U9HBg1JFK3jHl5qmo4CTZKFTVgMwdFHMVtCdfBE21U= github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k= @@ -191,13 +192,13 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= -github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADGYw5LqMnHqSkyIELsHCGF6PkrmM31V8rF7o= github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM= +github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzqk8QCaRC4os14xoKDdbHqqlJtJA0oc1ZAjg= github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 h1:qdkpTAo2Kr0ZicZIVXfNwsGSshpc9OB9j9RzmKYdIwY= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1/go.mod h1:IkKPPEfgLCMR29he5yv2OCC6iM2R7K5/0AA3k8b9XNc= -github.com/devtron-labs/common-lib v0.0.21-0.20240628105542-603b4f777e00 h1:xSZulEz0PaTA7tL4Es/uNFUmgjD6oAv8gxJV49GPWHk= -github.com/devtron-labs/common-lib v0.0.21-0.20240628105542-603b4f777e00/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= +github.com/devtron-labs/common-lib v0.0.22-0.20240704103133-ff5ff14e86de h1:Hjbuht9oQXWApl5OQABrbtmmDhA3Gw9uy3ToTNWNffA= +github.com/devtron-labs/common-lib v0.0.22-0.20240704103133-ff5ff14e86de/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 h1:R6qVeFaayqstBSu4w+ipWQqJyMKDqBVV3a11qoA2IaM= @@ -317,7 +318,6 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= -github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:9wScpmSP5A3Bk8V3XHWUcJmYTh+ZnlHVyc+A4oZYS3Y= github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:56xuuqnHyryaerycW3BfssRdxQstACi0Epw/yC5E2xM= github.com/go-xorm/xorm v0.7.9 h1:LZze6n1UvRmM5gpL9/U9Gucwqo6aWlFVlfcHKH10qA0= github.com/go-xorm/xorm v0.7.9/go.mod h1:XiVxrMMIhFkwSkh96BW7PACl7UhLtx2iJIHMdmjh5sQ= @@ -331,6 +331,7 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69 github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= @@ -593,8 +594,8 @@ github.com/mattn/go-ieproxy v0.0.1 h1:qiyop7gCflfhwCzGyeT0gro3sF9AIg9HU98JORTkqf github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/gNWuh88E= github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o= github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA= github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= @@ -1303,7 +1304,6 @@ sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= upper.io/db.v3 v3.8.0+incompatible h1:XNeEO2vQRVqq70M98ghzq6M30F5Bzo+99ess5v+eVYw= upper.io/db.v3 v3.8.0+incompatible/go.mod h1:FgTdD24eBjJAbPKsQSiHUNgXjOR4Lub3u1UMHSIh82Y= -xorm.io/builder v0.3.6 h1:ha28mQ2M+TFx96Hxo+iq6tQgnkC9IZkM6D8w9sKHHF8= xorm.io/builder v0.3.6/go.mod h1:LEFAPISnRzG+zxaxj2vPicRwz67BdhFreKg8yv8/TgU= xorm.io/builder v0.3.7 h1:2pETdKRK+2QG4mLX4oODHEhn5Z8j1m8sXa7jfu+/SZI= xorm.io/builder v0.3.7/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE= diff --git a/pkg/terminal/terminalSesion.go b/pkg/terminal/terminalSesion.go index 5785efaab0..2a76933853 100644 --- a/pkg/terminal/terminalSesion.go +++ b/pkg/terminal/terminalSesion.go @@ -308,6 +308,7 @@ func startProcess(ctx context.Context, k8sClient kubernetes.Interface, cfg *rest exec, err := getExecutor(k8sClient, cfg, podName, namespace, containerName, cmd, true, true) if err != nil { + log.Println("error in getting terminal executor ", "err: ", err) return err } @@ -323,6 +324,7 @@ func startProcess(ctx context.Context, k8sClient kubernetes.Interface, cfg *rest terminalSessions.SetTerminalSessionStartTime(sessionRequest.SessionId) err = execWithStreamOptions(ctx, exec, streamOptions) if err != nil { + log.Println("error in terminal exec with stream opts: ", "err: ", err) return err } return nil @@ -506,7 +508,7 @@ func (impl *TerminalSessionHandlerImpl) GetTerminalSession(req *TerminalSessionR namespace: req.Namespace, clusterId: strconv.Itoa(req.ClusterId), }) - config, client, err := impl.getClientConfig(req) + config, client, err := impl.getClientSetAndRestConfigForTerminalConn(req) go func() { err := impl.saveEphemeralContainerTerminalAccessAudit(req) @@ -523,7 +525,7 @@ func (impl *TerminalSessionHandlerImpl) GetTerminalSession(req *TerminalSessionR return http.StatusOK, &TerminalMessage{SessionID: sessionID}, nil } -func (impl *TerminalSessionHandlerImpl) getClientConfig(req *TerminalSessionRequest) (*rest.Config, *kubernetes.Clientset, error) { +func (impl *TerminalSessionHandlerImpl) getClientSetAndRestConfigForTerminalConn(req *TerminalSessionRequest) (*rest.Config, *kubernetes.Clientset, error) { var clusterBean *cluster.ClusterBean var clusterConfig *k8s.ClusterConfig var restConfig *rest.Config @@ -534,6 +536,13 @@ func (impl *TerminalSessionHandlerImpl) getClientConfig(req *TerminalSessionRequ impl.logger.Errorw("error in getting rest config", "err", err, "clusterId", req.ClusterId, "externalArgoApplicationName", req.ExternalArgoApplicationName) return nil, nil, err } + + _, clientSet, err := impl.k8sUtil.GetK8sConfigAndClientsByRestConfig(restConfig) + if err != nil { + impl.logger.Errorw("error in clientSet", "err", err) + return nil, nil, err + } + return restConfig, clientSet, nil } else { if req.ClusterId != 0 { clusterBean, err = impl.clusterService.FindById(req.ClusterId) @@ -561,14 +570,22 @@ func (impl *TerminalSessionHandlerImpl) getClientConfig(req *TerminalSessionRequ impl.logger.Errorw("error in getting rest config by cluster", "err", err, "clusterName", clusterConfig.ClusterName) return nil, nil, err } + + _, clientSet, err := impl.k8sUtil.GetK8sConfigAndClientsByRestConfig(restConfig) + if err != nil { + impl.logger.Errorw("error in clientSet", "err", err) + return nil, nil, err + } + + // we have to get the clientSet before setting the custom transport to nil + // we need re populate the tls config in the restConfig. + // rest config with custom transport will break spdy client + clusterConfig.PopulateTlsConfigurationsInto(restConfig) + restConfig.Transport = nil + return restConfig, clientSet, nil } - _, clientSet, err := impl.k8sUtil.GetK8sConfigAndClientsByRestConfig(restConfig) - if err != nil { - impl.logger.Errorw("error in clientSet", "err", err) - return nil, nil, err - } - return restConfig, clientSet, nil } + func (impl *TerminalSessionHandlerImpl) AutoSelectShell(req *TerminalSessionRequest) (string, error) { var err1 error for _, testShell := range validShells { @@ -614,7 +631,7 @@ func getErrorMsg(err string) error { } func (impl *TerminalSessionHandlerImpl) RunCmdInRemotePod(req *TerminalSessionRequest, cmds []string) (*bytes.Buffer, *bytes.Buffer, error) { - config, client, err := impl.getClientConfig(req) + config, client, err := impl.getClientSetAndRestConfigForTerminalConn(req) if err != nil { impl.logger.Errorw("error in fetching config", "err", err) return nil, nil, err diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go index 6568a957b3..4d51abf076 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go @@ -165,13 +165,8 @@ func (impl K8sServiceImpl) GetRestConfigByCluster(clusterConfig *ClusterConfig) return nil, err } } else { - restConfig = &rest.Config{Host: clusterConfig.Host, BearerToken: bearerToken, TLSClientConfig: rest.TLSClientConfig{Insecure: clusterConfig.InsecureSkipTLSVerify}} - if clusterConfig.InsecureSkipTLSVerify == false { - restConfig.TLSClientConfig.ServerName = restConfig.ServerName - restConfig.TLSClientConfig.KeyData = []byte(clusterConfig.KeyData) - restConfig.TLSClientConfig.CertData = []byte(clusterConfig.CertData) - restConfig.TLSClientConfig.CAData = []byte(clusterConfig.CAData) - } + restConfig = &rest.Config{Host: clusterConfig.Host, BearerToken: bearerToken} + clusterConfig.PopulateTlsConfigurationsInto(restConfig) } restConfig, err = impl.httpClientConfig.OverrideConfigWithCustomTransport(restConfig) if err != nil { diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go index 85043c9cc1..a12555f9f8 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go @@ -63,6 +63,16 @@ type ClusterConfig struct { RemoteConnectionConfig *bean.RemoteConnectionConfigBean } +func (clusterConfig *ClusterConfig) PopulateTlsConfigurationsInto(restConfig *rest.Config) { + restConfig.TLSClientConfig = rest.TLSClientConfig{Insecure: clusterConfig.InsecureSkipTLSVerify} + if clusterConfig.InsecureSkipTLSVerify == false { + restConfig.TLSClientConfig.ServerName = restConfig.ServerName + restConfig.TLSClientConfig.KeyData = []byte(clusterConfig.KeyData) + restConfig.TLSClientConfig.CertData = []byte(clusterConfig.CertData) + restConfig.TLSClientConfig.CAData = []byte(clusterConfig.CAData) + } +} + type ClusterResourceListMap struct { Headers []string `json:"headers"` Data []map[string]interface{} `json:"data"` diff --git a/vendor/modules.txt b/vendor/modules.txt index caa4a434af..4710a45551 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -402,7 +402,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.21-0.20240628105542-603b4f777e00 +# github.com/devtron-labs/common-lib v0.0.22-0.20240704103133-ff5ff14e86de ## explicit; go 1.21 github.com/devtron-labs/common-lib/blob-storage github.com/devtron-labs/common-lib/cloud-provider-identifier