As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 43ee15ca authored by Vasilii Iakliushin's avatar Vasilii Iakliushin
Browse files

Remove `self_signed_cert` option

parent c0953bdb
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -59,7 +59,7 @@ func TestClients(t *testing.T) {
secret := "sssh, it's a secret"
httpClient, err := NewHTTPClientWithOpts(url, tc.relativeURLRoot, tc.caFile, "", false, 1, nil)
httpClient, err := NewHTTPClientWithOpts(url, tc.relativeURLRoot, tc.caFile, "", 1, nil)
require.NoError(t, err)
client, err := NewGitlabNetClient("", "", secret, httpClient)
Loading
Loading
Loading
Loading
@@ -71,8 +71,8 @@ func validateCaFile(filename string) error {
}
// Deprecated: use NewHTTPClientWithOpts - https://gitlab.com/gitlab-org/gitlab-shell/-/issues/484
func NewHTTPClient(gitlabURL, gitlabRelativeURLRoot, caFile, caPath string, selfSignedCert bool, readTimeoutSeconds uint64) *HttpClient {
c, err := NewHTTPClientWithOpts(gitlabURL, gitlabRelativeURLRoot, caFile, caPath, selfSignedCert, readTimeoutSeconds, nil)
func NewHTTPClient(gitlabURL, gitlabRelativeURLRoot, caFile, caPath string, readTimeoutSeconds uint64) *HttpClient {
c, err := NewHTTPClientWithOpts(gitlabURL, gitlabRelativeURLRoot, caFile, caPath, readTimeoutSeconds, nil)
if err != nil {
log.WithError(err).Error("new http client with opts")
}
Loading
Loading
@@ -80,7 +80,7 @@ func NewHTTPClient(gitlabURL, gitlabRelativeURLRoot, caFile, caPath string, self
}
// NewHTTPClientWithOpts builds an HTTP client using the provided options
func NewHTTPClientWithOpts(gitlabURL, gitlabRelativeURLRoot, caFile, caPath string, selfSignedCert bool, readTimeoutSeconds uint64, opts []HTTPClientOpt) (*HttpClient, error) {
func NewHTTPClientWithOpts(gitlabURL, gitlabRelativeURLRoot, caFile, caPath string, readTimeoutSeconds uint64, opts []HTTPClientOpt) (*HttpClient, error) {
var transport *http.Transport
var host string
var err error
Loading
Loading
@@ -103,7 +103,7 @@ func NewHTTPClientWithOpts(gitlabURL, gitlabRelativeURLRoot, caFile, caPath stri
opt(hcc)
}
transport, host, err = buildHttpsTransport(*hcc, selfSignedCert, gitlabURL)
transport, host, err = buildHttpsTransport(*hcc, gitlabURL)
if err != nil {
return nil, err
}
Loading
Loading
@@ -140,7 +140,7 @@ func buildSocketTransport(gitlabURL, gitlabRelativeURLRoot string) (*http.Transp
return transport, host
}
func buildHttpsTransport(hcc httpClientCfg, selfSignedCert bool, gitlabURL string) (*http.Transport, string, error) {
func buildHttpsTransport(hcc httpClientCfg, gitlabURL string) (*http.Transport, string, error) {
certPool, err := x509.SystemCertPool()
if err != nil {
Loading
Loading
@@ -162,12 +162,8 @@ func buildHttpsTransport(hcc httpClientCfg, selfSignedCert bool, gitlabURL strin
}
}
tlsConfig := &tls.Config{
RootCAs: certPool,
// The self_signed_cert config setting is deprecated
// The field and its usage is going to be removed in
// https://gitlab.com/gitlab-org/gitlab-shell/-/issues/541
InsecureSkipVerify: selfSignedCert,
MinVersion: tls.VersionTLS12,
RootCAs: certPool,
MinVersion: tls.VersionTLS12,
}
if hcc.HaveCertAndKey() {
Loading
Loading
Loading
Loading
@@ -17,7 +17,7 @@ import (
func TestReadTimeout(t *testing.T) {
expectedSeconds := uint64(300)
client, err := NewHTTPClientWithOpts("http://localhost:3000", "", "", "", false, expectedSeconds, nil)
client, err := NewHTTPClientWithOpts("http://localhost:3000", "", "", "", expectedSeconds, nil)
require.NoError(t, err)
require.NotNil(t, client)
Loading
Loading
@@ -123,7 +123,7 @@ func TestRequestWithUserAgent(t *testing.T) {
func setup(t *testing.T, username, password string, requests []testserver.TestRequestHandler) *GitlabNetClient {
url := testserver.StartHttpServer(t, requests)
httpClient, err := NewHTTPClientWithOpts(url, "", "", "", false, 1, nil)
httpClient, err := NewHTTPClientWithOpts(url, "", "", "", 1, nil)
require.NoError(t, err)
client, err := NewGitlabNetClient(username, password, "", httpClient)
Loading
Loading
Loading
Loading
@@ -18,7 +18,6 @@ func TestSuccessfulRequests(t *testing.T) {
testCases := []struct {
desc string
caFile, caPath string
selfSigned bool
clientCAPath, clientCertPath, clientKeyPath string // used for TLS client certs
}{
{
Loading
Loading
@@ -31,9 +30,8 @@ func TestSuccessfulRequests(t *testing.T) {
caFile: path.Join(testhelper.TestRoot, "certs/valid/server.crt"),
},
{
desc: "Invalid cert with self signed cert option enabled",
caFile: path.Join(testhelper.TestRoot, "certs/valid/server.crt"),
selfSigned: true,
desc: "Invalid cert with self signed cert option enabled",
caFile: path.Join(testhelper.TestRoot, "certs/valid/server.crt"),
},
{
desc: "Client certs with CA",
Loading
Loading
@@ -48,7 +46,7 @@ func TestSuccessfulRequests(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
client, err := setupWithRequests(t, tc.caFile, tc.caPath, tc.clientCAPath, tc.clientCertPath, tc.clientKeyPath, tc.selfSigned)
client, err := setupWithRequests(t, tc.caFile, tc.caPath, tc.clientCAPath, tc.clientCertPath, tc.clientKeyPath)
require.NoError(t, err)
response, err := client.Get(context.Background(), "/hello")
Loading
Loading
@@ -95,7 +93,7 @@ func TestFailedRequests(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
client, err := setupWithRequests(t, tc.caFile, tc.caPath, "", "", "", false)
client, err := setupWithRequests(t, tc.caFile, tc.caPath, "", "", "")
if tc.expectedCaFileNotFound {
require.Error(t, err)
require.ErrorIs(t, err, ErrCafileNotFound)
Loading
Loading
@@ -109,7 +107,7 @@ func TestFailedRequests(t *testing.T) {
}
}
func setupWithRequests(t *testing.T, caFile, caPath, clientCAPath, clientCertPath, clientKeyPath string, selfSigned bool) (*GitlabNetClient, error) {
func setupWithRequests(t *testing.T, caFile, caPath, clientCAPath, clientCertPath, clientKeyPath string) (*GitlabNetClient, error) {
testhelper.PrepareTestRootDir(t)
requests := []testserver.TestRequestHandler{
Loading
Loading
@@ -130,7 +128,7 @@ func setupWithRequests(t *testing.T, caFile, caPath, clientCAPath, clientCertPat
opts = append(opts, WithClientCert(clientCertPath, clientKeyPath))
}
httpClient, err := NewHTTPClientWithOpts(url, "", caFile, caPath, selfSigned, 1, opts)
httpClient, err := NewHTTPClientWithOpts(url, "", caFile, caPath, 1, opts)
if err != nil {
return nil, err
}
Loading
Loading
Loading
Loading
@@ -27,11 +27,6 @@ http_settings:
# ca_file: /etc/ssl/cert.pem
# ca_path: /etc/pki/tls/certs
#
# The self_signed_cert option is deprecated
# When it's set to true, any certificate is accepted, which may make machine-in-the-middle attack possible
# Certificates specified in ca_file and ca_path are trusted anyway even if they are self-signed
# Issue: https://gitlab.com/gitlab-org/gitlab-shell/-/issues/120
self_signed_cert: false
# File used as authorized_keys for gitlab user
auth_file: "/home/git/.ssh/authorized_keys"
Loading
Loading
Loading
Loading
@@ -39,7 +39,6 @@ type HttpSettingsConfig struct {
ReadTimeoutSeconds uint64 `yaml:"read_timeout"`
CaFile string `yaml:"ca_file"`
CaPath string `yaml:"ca_path"`
SelfSignedCert bool `yaml:"self_signed_cert"`
}
type Config struct {
Loading
Loading
@@ -112,7 +111,6 @@ func (c *Config) HttpClient() (*client.HttpClient, error) {
c.GitlabRelativeURLRoot,
c.HttpSettings.CaFile,
c.HttpSettings.CaPath,
c.HttpSettings.SelfSignedCert,
c.HttpSettings.ReadTimeoutSeconds,
nil,
)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment