mirror of https://github.com/portainer/portainer
fix(crypto): replace fips140 calls with fips calls BE-11979 (#1033)
parent
129b9d5db9
commit
10b129a02e
|
@ -1,18 +1,17 @@
|
||||||
package crypto
|
package crypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/fips140"
|
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
|
"github.com/portainer/portainer/pkg/fips"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateTLSConfiguration creates a basic tls.Config with recommended TLS settings
|
// CreateTLSConfiguration creates a basic tls.Config with recommended TLS settings
|
||||||
func CreateTLSConfiguration(insecureSkipVerify bool) *tls.Config { //nolint:forbidigo
|
func CreateTLSConfiguration(insecureSkipVerify bool) *tls.Config { //nolint:forbidigo
|
||||||
// TODO: use fips.FIPSMode() instead
|
return createTLSConfiguration(fips.FIPSMode(), insecureSkipVerify)
|
||||||
return createTLSConfiguration(fips140.Enabled(), insecureSkipVerify)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTLSConfiguration(fipsEnabled bool, insecureSkipVerify bool) *tls.Config { //nolint:forbidigo
|
func createTLSConfiguration(fipsEnabled bool, insecureSkipVerify bool) *tls.Config { //nolint:forbidigo
|
||||||
|
@ -58,8 +57,7 @@ func createTLSConfiguration(fipsEnabled bool, insecureSkipVerify bool) *tls.Conf
|
||||||
// CreateTLSConfigurationFromBytes initializes a tls.Config using a CA certificate, a certificate and a key
|
// CreateTLSConfigurationFromBytes initializes a tls.Config using a CA certificate, a certificate and a key
|
||||||
// loaded from memory.
|
// loaded from memory.
|
||||||
func CreateTLSConfigurationFromBytes(useTLS bool, caCert, cert, key []byte, skipClientVerification, skipServerVerification bool) (*tls.Config, error) { //nolint:forbidigo
|
func CreateTLSConfigurationFromBytes(useTLS bool, caCert, cert, key []byte, skipClientVerification, skipServerVerification bool) (*tls.Config, error) { //nolint:forbidigo
|
||||||
// TODO: use fips.FIPSMode() instead
|
return createTLSConfigurationFromBytes(fips.FIPSMode(), useTLS, caCert, cert, key, skipClientVerification, skipServerVerification)
|
||||||
return createTLSConfigurationFromBytes(fips140.Enabled(), useTLS, caCert, cert, key, skipClientVerification, skipServerVerification)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTLSConfigurationFromBytes(fipsEnabled, useTLS bool, caCert, cert, key []byte, skipClientVerification, skipServerVerification bool) (*tls.Config, error) { //nolint:forbidigo
|
func createTLSConfigurationFromBytes(fipsEnabled, useTLS bool, caCert, cert, key []byte, skipClientVerification, skipServerVerification bool) (*tls.Config, error) { //nolint:forbidigo
|
||||||
|
@ -90,8 +88,7 @@ func createTLSConfigurationFromBytes(fipsEnabled, useTLS bool, caCert, cert, key
|
||||||
// CreateTLSConfigurationFromDisk initializes a tls.Config using a CA certificate, a certificate and a key
|
// CreateTLSConfigurationFromDisk initializes a tls.Config using a CA certificate, a certificate and a key
|
||||||
// loaded from disk.
|
// loaded from disk.
|
||||||
func CreateTLSConfigurationFromDisk(config portainer.TLSConfiguration) (*tls.Config, error) { //nolint:forbidigo
|
func CreateTLSConfigurationFromDisk(config portainer.TLSConfiguration) (*tls.Config, error) { //nolint:forbidigo
|
||||||
// TODO: use fips.FIPSMode() instead
|
return createTLSConfigurationFromDisk(fips.FIPSMode(), config)
|
||||||
return createTLSConfigurationFromDisk(fips140.Enabled(), config)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTLSConfigurationFromDisk(fipsEnabled bool, config portainer.TLSConfiguration) (*tls.Config, error) { //nolint:forbidigo
|
func createTLSConfigurationFromDisk(fipsEnabled bool, config portainer.TLSConfiguration) (*tls.Config, error) { //nolint:forbidigo
|
||||||
|
|
|
@ -4,10 +4,14 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
|
"github.com/portainer/portainer/pkg/fips"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHttpClient(t *testing.T) {
|
func TestHttpClient(t *testing.T) {
|
||||||
|
fips.InitFIPS(false)
|
||||||
|
|
||||||
// Valid TLS configuration
|
// Valid TLS configuration
|
||||||
endpoint := &portainer.Endpoint{}
|
endpoint := &portainer.Endpoint{}
|
||||||
endpoint.TLSConfig = portainer.TLSConfiguration{TLS: true}
|
endpoint.TLSConfig = portainer.TLSConfiguration{TLS: true}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
gittypes "github.com/portainer/portainer/api/git/types"
|
gittypes "github.com/portainer/portainer/api/git/types"
|
||||||
|
"github.com/portainer/portainer/pkg/fips"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -234,6 +235,8 @@ func Test_isAzureUrl(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_azureDownloader_downloadZipFromAzureDevOps(t *testing.T) {
|
func Test_azureDownloader_downloadZipFromAzureDevOps(t *testing.T) {
|
||||||
|
fips.InitFIPS(false)
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
options baseOption
|
options baseOption
|
||||||
}
|
}
|
||||||
|
@ -308,6 +311,8 @@ func Test_azureDownloader_downloadZipFromAzureDevOps(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_azureDownloader_latestCommitID(t *testing.T) {
|
func Test_azureDownloader_latestCommitID(t *testing.T) {
|
||||||
|
fips.InitFIPS(false)
|
||||||
|
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
response := `{
|
response := `{
|
||||||
"count": 1,
|
"count": 1,
|
||||||
|
|
|
@ -4,10 +4,14 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/portainer/portainer/pkg/fips"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewService(t *testing.T) {
|
func TestNewService(t *testing.T) {
|
||||||
|
fips.InitFIPS(false)
|
||||||
|
|
||||||
service := NewService(true)
|
service := NewService(true)
|
||||||
require.NotNil(t, service)
|
require.NotNil(t, service)
|
||||||
require.True(t, service.httpsClient.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify) //nolint:forbidigo
|
require.True(t, service.httpsClient.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify) //nolint:forbidigo
|
||||||
|
|
|
@ -6,11 +6,14 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
|
"github.com/portainer/portainer/pkg/fips"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExecutePingOperationFailure(t *testing.T) {
|
func TestExecutePingOperationFailure(t *testing.T) {
|
||||||
|
fips.InitFIPS(false)
|
||||||
|
|
||||||
host := "http://localhost:1"
|
host := "http://localhost:1"
|
||||||
config := portainer.TLSConfiguration{
|
config := portainer.TLSConfiguration{
|
||||||
TLS: true,
|
TLS: true,
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/portainer/portainer/api/internal/testhelpers"
|
"github.com/portainer/portainer/api/internal/testhelpers"
|
||||||
"github.com/portainer/portainer/pkg/libhelm/test"
|
"github.com/portainer/portainer/pkg/libhelm/test"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,14 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
|
"github.com/portainer/portainer/pkg/fips"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInitDial(t *testing.T) {
|
func TestInitDial(t *testing.T) {
|
||||||
|
fips.InitFIPS(false)
|
||||||
|
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,14 @@ package kubernetes
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/portainer/portainer/pkg/fips"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewLocalTransport(t *testing.T) {
|
func TestNewLocalTransport(t *testing.T) {
|
||||||
|
fips.InitFIPS(false)
|
||||||
|
|
||||||
transport, err := NewLocalTransport(nil, nil, nil, nil, nil)
|
transport, err := NewLocalTransport(nil, nil, nil, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, transport.httpTransport.TLSClientConfig.InsecureSkipVerify) //nolint:forbidigo
|
require.True(t, transport.httpTransport.TLSClientConfig.InsecureSkipVerify) //nolint:forbidigo
|
||||||
|
|
|
@ -7,11 +7,14 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
|
"github.com/portainer/portainer/pkg/fips"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateConnectionForURL(t *testing.T) {
|
func TestCreateConnectionForURL(t *testing.T) {
|
||||||
|
fips.InitFIPS(false)
|
||||||
|
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/portainer/portainer/api/datastore"
|
"github.com/portainer/portainer/api/datastore"
|
||||||
gittypes "github.com/portainer/portainer/api/git/types"
|
gittypes "github.com/portainer/portainer/api/git/types"
|
||||||
"github.com/portainer/portainer/api/internal/testhelpers"
|
"github.com/portainer/portainer/api/internal/testhelpers"
|
||||||
|
"github.com/portainer/portainer/pkg/fips"
|
||||||
"github.com/portainer/portainer/pkg/libhttp/response"
|
"github.com/portainer/portainer/pkg/libhttp/response"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -203,6 +204,8 @@ func Test_redeployWhenChanged_DoesNothingWhenNoGitChanges(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_redeployWhenChanged_FailsWhenCannotClone(t *testing.T) {
|
func Test_redeployWhenChanged_FailsWhenCannotClone(t *testing.T) {
|
||||||
|
fips.InitFIPS(false)
|
||||||
|
|
||||||
cloneErr := errors.New("failed to clone")
|
cloneErr := errors.New("failed to clone")
|
||||||
_, store := datastore.MustNewTestStore(t, true, true)
|
_, store := datastore.MustNewTestStore(t, true, true)
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/portainer/portainer/pkg/fips"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Response structs for each function
|
// Response structs for each function
|
||||||
|
@ -110,6 +112,8 @@ func TestProbeTelnetConnection(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDetectProxy(t *testing.T) {
|
func TestDetectProxy(t *testing.T) {
|
||||||
|
fips.InitFIPS(false)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
url string
|
url string
|
||||||
|
|
Loading…
Reference in New Issue