Skip to content

Commit

Permalink
[CECO-180] Add FIPS support (#1063)
Browse files Browse the repository at this point in the history
* Add FIPS support

* Review suggestions

* Review suggestions

* Add crd changes from merging main

* Review suggestions
  • Loading branch information
khewonc authored Feb 23, 2024
1 parent 3bfd043 commit 4ba13a6
Show file tree
Hide file tree
Showing 24 changed files with 1,500 additions and 22 deletions.
5 changes: 5 additions & 0 deletions apis/datadoghq/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ const (
ClusterAgentCustomConfigVolumeSubPath = "datadog-cluster.yaml"

HelmCheckConfigVolumeName = "helm-check-config"

FIPSProxyCustomConfigVolumeName = "fips-proxy-cfg"
FIPSProxyCustomConfigFileName = "datadog-fips-proxy.cfg"
FIPSProxyCustomConfigMapName = "%s-fips-config"
FIPSProxyCustomConfigMountPath = "/etc/datadog-fips-proxy/datadog-fips-proxy.cfg"
)

const (
Expand Down
4 changes: 4 additions & 0 deletions apis/datadoghq/common/envvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ const (
DDExternalMetricsProviderWPAController = "DD_EXTERNAL_METRICS_PROVIDER_WPA_CONTROLLER"
DDExtraConfigProviders = "DD_EXTRA_CONFIG_PROVIDERS"
DDExtraListeners = "DD_EXTRA_LISTENERS"
DDFIPSEnabled = "DD_FIPS_ENABLED"
DDFIPSPortRangeStart = "DD_FIPS_PORT_RANGE_START"
DDFIPSUseHTTPS = "DD_FIPS_HTTPS"
DDFIPSLocalAddress = "DD_FIPS_LOCAL_ADDRESS"
DDHealthPort = "DD_HEALTH_PORT"
DDHostname = "DD_HOSTNAME"
DDHostRootEnvVar = "HOST_ROOT"
Expand Down
3 changes: 3 additions & 0 deletions apis/datadoghq/common/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,7 @@ const (

// ClusterChecksRunnersContainerName is the name of the Agent container in Cluster Checks Runners
ClusterChecksRunnersContainerName AgentContainerName = "agent"

// FIPSProxyContainerName is the name of the FIPS Proxy container
FIPSProxyContainerName AgentContainerName = "fips-proxy"
)
31 changes: 31 additions & 0 deletions apis/datadoghq/v2alpha1/datadogagent_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ package v2alpha1

import (
apicommon "github.com/DataDog/datadog-operator/apis/datadoghq/common"
commonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
"github.com/DataDog/datadog-operator/pkg/defaulting"
)

// Default configuration values. These are the recommended settings for monitoring with Datadog in Kubernetes.
Expand Down Expand Up @@ -96,6 +98,14 @@ const (

defaultHelmCheckEnabled bool = false
defaultHelmCheckCollectEvents bool = false

defaultFIPSEnabled bool = false
defaultFIPSImageName string = "fips-proxy"
defaultFIPSImageTag string = defaulting.FIPSProxyLatestVersion
defaultFIPSLocalAddress string = "127.0.0.1"
defaultFIPSPort int32 = 9803
defaultFIPSPortRange int32 = 15
defaultFIPSUseHTTPS bool = false
)

// DefaultDatadogAgent defaults the DatadogAgentSpec GlobalConfig and Features.
Expand Down Expand Up @@ -136,6 +146,27 @@ func defaultGlobalConfig(ddaSpec *DatadogAgentSpec) {
dcs := defaultContainerStrategy
ddaSpec.Global.ContainerStrategy = &dcs
}

if ddaSpec.Global.FIPS == nil {
ddaSpec.Global.FIPS = &FIPSConfig{}
}
apiutils.DefaultBooleanIfUnset(&ddaSpec.Global.FIPS.Enabled, defaultFIPSEnabled)

if *ddaSpec.Global.FIPS.Enabled {
if ddaSpec.Global.FIPS.Image == nil {
ddaSpec.Global.FIPS.Image = &commonv1.AgentImageConfig{}
}
if ddaSpec.Global.FIPS.Image.Name == "" {
ddaSpec.Global.FIPS.Image.Name = defaultFIPSImageName
}
if ddaSpec.Global.FIPS.Image.Tag == "" {
ddaSpec.Global.FIPS.Image.Tag = defaultFIPSImageTag
}
apiutils.DefaultStringIfUnset(&ddaSpec.Global.FIPS.LocalAddress, defaultFIPSLocalAddress)
apiutils.DefaultInt32IfUnset(&ddaSpec.Global.FIPS.Port, defaultFIPSPort)
apiutils.DefaultInt32IfUnset(&ddaSpec.Global.FIPS.PortRange, defaultFIPSPortRange)
apiutils.DefaultBooleanIfUnset(&ddaSpec.Global.FIPS.UseHTTPS, defaultFIPSUseHTTPS)
}
}

// defaultFeaturesConfig sets default values in DatadogAgentSpec.Features.
Expand Down
51 changes: 48 additions & 3 deletions apis/datadoghq/v2alpha1/datadogagent_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ package v2alpha1
import (
"testing"

"github.com/google/go-cmp/cmp"
assert "github.com/stretchr/testify/require"

apicommon "github.com/DataDog/datadog-operator/apis/datadoghq/common"
"github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
apiutils "github.com/DataDog/datadog-operator/apis/utils"

"github.com/google/go-cmp/cmp"
assert "github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -84,6 +85,50 @@ func Test_defaultGlobal(t *testing.T) {
},
},
},
{
name: "test FIPS defaulting - disabled",
ddaSpec: &DatadogAgentSpec{
Global: &GlobalConfig{},
},
want: &DatadogAgentSpec{
Global: &GlobalConfig{
FIPS: &FIPSConfig{
Enabled: apiutils.NewBoolPointer(defaultFIPSEnabled),
},
Site: apiutils.NewStringPointer(defaultSite),
Registry: apiutils.NewStringPointer(apicommon.DefaultImageRegistry),
LogLevel: apiutils.NewStringPointer(defaultLogLevel),
},
},
},
{
name: "test FIPS defaulting - enabled",
ddaSpec: &DatadogAgentSpec{
Global: &GlobalConfig{
FIPS: &FIPSConfig{
Enabled: apiutils.NewBoolPointer(true),
},
},
},
want: &DatadogAgentSpec{
Global: &GlobalConfig{
FIPS: &FIPSConfig{
Enabled: apiutils.NewBoolPointer(true),
Image: &common.AgentImageConfig{
Name: defaultFIPSImageName,
Tag: defaultFIPSImageTag,
},
LocalAddress: apiutils.NewStringPointer(defaultFIPSLocalAddress),
Port: apiutils.NewInt32Pointer(defaultFIPSPort),
PortRange: apiutils.NewInt32Pointer(defaultFIPSPortRange),
UseHTTPS: apiutils.NewBoolPointer(defaultFIPSUseHTTPS),
},
Site: apiutils.NewStringPointer(defaultSite),
Registry: apiutils.NewStringPointer(apicommon.DefaultImageRegistry),
LogLevel: apiutils.NewStringPointer(defaultLogLevel),
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
39 changes: 39 additions & 0 deletions apis/datadoghq/v2alpha1/datadogagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,9 @@ type GlobalConfig struct {
// Default: 'optimized'
// +optional
ContainerStrategy *ContainerStrategyType `json:"containerStrategy,omitempty"`

// FIPS contains configuration used to customize the FIPS proxy sidecar.
FIPS *FIPSConfig `json:"fips,omitempty"`
}

// DatadogCredentials is a generic structure that holds credentials to access Datadog.
Expand Down Expand Up @@ -1127,6 +1130,42 @@ type DatadogAgentStatus struct {
ClusterChecksRunner *commonv1.DeploymentStatus `json:"clusterChecksRunner,omitempty"`
}

// FIPSConfig contains the FIPS configuration.
// +k8s:openapi-gen=true
type FIPSConfig struct {
// Enable FIPS sidecar.
// +optional
Enabled *bool `json:"enabled,omitempty"`
// The container image of the FIPS sidecar.
// +optional
Image *commonv1.AgentImageConfig `json:"image,omitempty"`
// Set the local IP address.
// Default: `127.0.0.1`
// +optional
LocalAddress *string `json:"localAddress,omitempty"`
// Port specifies which port is used by the containers to communicate to the FIPS sidecar.
// Default: 9803
// +optional
Port *int32 `json:"port,omitempty"`
// PortRange specifies the number of ports used.
// Default: 15
// +optional
PortRange *int32 `json:"portRange,omitempty"`
// Resources is the requests and limits for the FIPS sidecar container.
// +optional
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
// UseHTTPS enables HTTPS.
// Default: false
// +optional
UseHTTPS *bool `json:"useHTTPS,omitempty"`
// CustomFIPSConfig configures a custom configMap to provide the FIPS configuration.
// Specify custom contents for the FIPS proxy sidecar container config
// (/etc/datadog-fips-proxy/datadog-fips-proxy.cfg). If empty, the default FIPS
// proxy sidecar container config is used.
// +optional
CustomFIPSConfig *CustomConfig `json:"customFIPSConfig,omitempty"`
}

// DatadogAgent Deployment with the Datadog Operator.
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
Expand Down
11 changes: 11 additions & 0 deletions apis/datadoghq/v2alpha1/test/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,14 @@ func (builder *DatadogAgentBuilder) WithComponentOverride(componentName v2alpha1
builder.datadogAgent.Spec.Override[componentName] = &override
return builder
}

// FIPS

func (builder *DatadogAgentBuilder) WithFIPS(fipsConfig v2alpha1.FIPSConfig) *DatadogAgentBuilder {
if builder.datadogAgent.Spec.Global == nil {
builder.datadogAgent.Spec.Global = &v2alpha1.GlobalConfig{}
}

builder.datadogAgent.Spec.Global.FIPS = &fipsConfig
return builder
}
60 changes: 60 additions & 0 deletions apis/datadoghq/v2alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions apis/datadoghq/v2alpha1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4ba13a6

Please sign in to comment.