Skip to content

Commit ef60f42

Browse files
committed
fix initial logic, update template to support -jmx tag, improve unit-test and documentation wording
1 parent 03421f3 commit ef60f42

File tree

4 files changed

+91
-55
lines changed

4 files changed

+91
-55
lines changed

charts/datadog/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -906,17 +906,17 @@ helm install <RELEASE_NAME> \
906906
| existingClusterAgent.serviceName | string | `nil` | Existing service name to use for reaching the external Cluster Agent |
907907
| existingClusterAgent.tokenSecretName | string | `nil` | Existing secret name to use for external Cluster Agent token |
908908
| fips.customFipsConfig | object | `{}` | Configure 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. |
909-
| fips.enabled | bool | `false` | |
909+
| fips.enabled | bool | `false` | Enable fips proxy sidecar. The fips-proxy method is being progressively phased out in favor of FIPS-compliant images (refer to the `useFIPSAgent` setting). |
910910
| fips.image.digest | string | `""` | Define the FIPS sidecar image digest to use, takes precedence over `fips.image.tag` if specified. |
911911
| fips.image.name | string | `"fips-proxy"` | |
912912
| fips.image.pullPolicy | string | `"IfNotPresent"` | Datadog the FIPS sidecar image pull policy |
913913
| fips.image.repository | string | `nil` | Override default registry + image.name for the FIPS sidecar container. |
914914
| fips.image.tag | string | `"1.1.9"` | Define the FIPS sidecar container version to use. |
915-
| fips.local_address | string | `"127.0.0.1"` | Set local IP address This setting is only used for the fips-proxy sidecar. |
915+
| fips.local_address | string | `"127.0.0.1"` | Set local IP address. This setting is only used for the fips-proxy sidecar. |
916916
| fips.port | int | `9803` | Specifies which port is used by the containers to communicate to the FIPS sidecar. This setting is only used for the fips-proxy sidecar. |
917-
| fips.portRange | int | `15` | Specifies the number of ports used, defaults to 13 https://github.com/DataDog/datadog-agent/blob/7.44.x/pkg/config/config.go#L1564-L1577 This setting is only used for the fips-proxy sidecar. |
917+
| fips.portRange | int | `15` | Specifies the number of ports used, defaults to 13 https://github.com/DataDog/datadog-agent/blob/7.44.x/pkg/config/config.go#L1564-L1577. This setting is only used for the fips-proxy sidecar. |
918918
| fips.resources | object | `{}` | Resource requests and limits for the FIPS sidecar container. This setting is only used for the fips-proxy sidecar. |
919-
| fips.use_https | bool | `false` | Option to enable https This setting is only used for the fips-proxy sidecar. |
919+
| fips.use_https | bool | `false` | Option to enable https. This setting is only used for the fips-proxy sidecar. |
920920
| fullnameOverride | string | `nil` | Override the full qualified app name |
921921
| kube-state-metrics.image.repository | string | `"registry.k8s.io/kube-state-metrics/kube-state-metrics"` | Default kube-state-metrics image repository. |
922922
| kube-state-metrics.nodeSelector | object | `{"kubernetes.io/os":"linux"}` | Node selector for KSM. KSM only supports Linux. |
@@ -934,7 +934,7 @@ helm install <RELEASE_NAME> \
934934
| registry | string | `nil` | Registry to use for all Agent images (default to [gcr.io | eu.gcr.io | asia.gcr.io | datadoghq.azurecr.io | public.ecr.aws/datadog] depending on datadog.site value) |
935935
| remoteConfiguration.enabled | bool | `true` | Set to true to enable remote configuration on the Cluster Agent (if set) and the node agent. Can be overridden if `datadog.remoteConfiguration.enabled` Preferred way to enable Remote Configuration. |
936936
| targetSystem | string | `"linux"` | Target OS for this deployment (possible values: linux, windows) |
937-
| useFIPSAgent | bool | `false` | |
937+
| useFIPSAgent | bool | `false` | Setting useFIPSAgent to true makes the helm chart use Agent images that are FIPS-compliant for use in GOVCLOUD environments Setting this to true disables the fips-proxy sidecar. This is the recommended method for enabling FIPS compliance. |
938938

939939
## Configuration options for Windows deployments
940940
<a name="windows-config"></a>

charts/datadog/templates/_helpers.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ Return a remote image path based on `.Values` (passed as root) and `.` (any `.im
363363
{{- $tagSuffix = printf "-%s" "fips" -}}
364364
{{- end -}}
365365
{{- if .image.tagSuffix -}}
366-
{{- $tagSuffix = printf "-%s" .image.tagSuffix -}}
366+
{{- $tagSuffix = printf "%s-%s" $tagSuffix .image.tagSuffix -}}
367367
{{- end -}}
368368
{{- if .image.repository -}}
369369
{{- .image.repository -}}:{{ .image.tag }}{{ $tagSuffix }}
@@ -426,7 +426,7 @@ false
426426
Return true if the fips side car container should be created.
427427
*/}}
428428
{{- define "should-enable-fips-proxy" -}}
429-
{{- if and (not (or (eq (include "use-fips-images" $) "true") (or .Values.providers.gke.autopilot .Values.providers.gke.gdc ))) (eq .Values.targetSystem "linux") .Values.fips.enabled -}}
429+
{{- if and (not (or (eq (include "use-fips-images" .Values) "true") (or .Values.providers.gke.autopilot .Values.providers.gke.gdc ))) (eq .Values.targetSystem "linux") .Values.fips.enabled -}}
430430
true
431431
{{- else -}}
432432
false

charts/datadog/values.yaml

+9-13
Original file line numberDiff line numberDiff line change
@@ -1575,17 +1575,15 @@ existingClusterAgent:
15751575
# existingClusterAgent.clusterchecksEnabled -- set this to false if you don’t want the agents to run the cluster checks of the joined external cluster agent
15761576
clusterchecksEnabled: true
15771577

1578-
## useFIPSAgent -- Setting useFIPSAgent: true makes the helm chart install FIPS compliant image tags for use in GOVCLOUD environments
1579-
## NOTE:
1580-
## - setting this to true disables the fips-proxy sidecar
1581-
## - this is the recommended method for enabling FIPS compliance
1578+
# useFIPSAgent -- Setting useFIPSAgent to true makes the helm chart use Agent images that are FIPS-compliant for use in GOVCLOUD environments
1579+
# Setting this to true disables the fips-proxy sidecar.
1580+
# This is the recommended method for enabling FIPS compliance.
15821581
useFIPSAgent: false
15831582

1584-
## fips is used to enable and configure the FIPS compliant mode for the Datadog Agent.
1585-
## The current method uses the fips-proxy sidecar to enable FIPS compliance.
1586-
## The fips-proxy will be progressively deprecated in the future in favor of the use of FIPS compliant images (please refer to useFIPSAgent setting)
1583+
## fips is used to enable and configure the fips-proxy sidecar.
15871584
fips:
1588-
## fips.enabled -- Enable fips proxy sidecar
1585+
# fips.enabled -- Enable fips proxy sidecar.
1586+
# The fips-proxy method is being progressively phased out in favor of FIPS-compliant images (refer to the `useFIPSAgent` setting).
15891587
enabled: false
15901588

15911589
# TODO: Option to override config of the FIPS side car: /etc/datadog-fips-proxy/datadog-fips-proxy.cfg
@@ -1595,11 +1593,11 @@ fips:
15951593
# This setting is only used for the fips-proxy sidecar.
15961594
port: 9803
15971595

1598-
# fips.portRange -- Specifies the number of ports used, defaults to 13 https://github.com/DataDog/datadog-agent/blob/7.44.x/pkg/config/config.go#L1564-L1577
1596+
# fips.portRange -- Specifies the number of ports used, defaults to 13 https://github.com/DataDog/datadog-agent/blob/7.44.x/pkg/config/config.go#L1564-L1577.
15991597
# This setting is only used for the fips-proxy sidecar.
16001598
portRange: 15
16011599

1602-
# fips.use_https -- Option to enable https
1600+
# fips.use_https -- Option to enable https.
16031601
# This setting is only used for the fips-proxy sidecar.
16041602
use_https: false
16051603

@@ -1613,12 +1611,11 @@ fips:
16131611
# cpu: 20m
16141612
# memory: 64Mi
16151613

1616-
# fips.local_address -- Set local IP address
1614+
# fips.local_address -- Set local IP address.
16171615
# This setting is only used for the fips-proxy sidecar.
16181616
local_address: "127.0.0.1"
16191617

16201618
## Define the Datadog image to work with
1621-
# This setting is only used for the fips-proxy sidecar.
16221619
image:
16231620
## fips.image.name -- Define the FIPS sidecar container image name.
16241621
name: fips-proxy
@@ -1639,7 +1636,6 @@ fips:
16391636

16401637
## Note: Use `|` to declare multi-line configuration.
16411638
## ref: https://docs.datadoghq.com/agent/guide/agent-fips-proxy
1642-
# This setting is only used for the fips-proxy sidecar.
16431639
customFipsConfig: {} # |
16441640
# foobar
16451641
# foo bar baz

test/datadog/fips_mode_test.go

+75-35
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,73 @@ import (
55
"strings"
66
"testing"
77

8+
"strconv"
9+
810
"github.com/DataDog/helm-charts/test/common"
911
"github.com/stretchr/testify/assert"
1012
"github.com/stretchr/testify/require"
1113
appsv1 "k8s.io/api/apps/v1"
1214
corev1 "k8s.io/api/core/v1"
13-
"strconv"
1415
)
1516

1617
func TestFIPSModeConditions(t *testing.T) {
1718
tests := []struct {
18-
name string
19-
setFipsEnabledSetting bool
20-
setUseFipsImageSetting bool
21-
expectFipsProxy bool
22-
expectFipsImageSuffix bool
19+
name string
20+
enableFIPSProxy bool
21+
enableFIPSAgent bool
22+
expectFIPSProxy bool
23+
expectFIPSAgent bool
24+
enableJMX bool
2325
}{
2426
{
25-
name: "fips.useFipsImages true should not use fips-proxy and use fips image",
26-
setFipsEnabledSetting: true,
27-
setUseFipsImageSetting: true,
28-
expectFipsProxy: false,
29-
expectFipsImageSuffix: true,
27+
name: "without any fips configuration",
28+
enableFIPSProxy: false,
29+
enableFIPSAgent: false,
30+
expectFIPSProxy: false,
31+
expectFIPSAgent: false,
32+
},
33+
{
34+
name: "fips proxy only",
35+
enableFIPSProxy: true,
36+
enableFIPSAgent: false,
37+
expectFIPSProxy: true,
38+
expectFIPSAgent: false,
3039
},
3140
{
32-
name: "fips.useFipsImages false and fips.enabled true should use fips-proxy and not use fips image",
33-
setFipsEnabledSetting: true,
34-
setUseFipsImageSetting: false,
35-
expectFipsProxy: true,
36-
expectFipsImageSuffix: false,
41+
name: "fips image only",
42+
enableFIPSProxy: false,
43+
enableFIPSAgent: true,
44+
expectFIPSProxy: false,
45+
expectFIPSAgent: true,
3746
},
3847
{
39-
name: "fips.useFipsImages false and fips.enabled false should not use fips-proxy or fips image",
40-
setFipsEnabledSetting: false,
41-
setUseFipsImageSetting: true,
42-
expectFipsProxy: false,
43-
expectFipsImageSuffix: false,
48+
name: "fips proxy and fips image",
49+
enableFIPSProxy: true,
50+
enableFIPSAgent: true,
51+
expectFIPSProxy: false, // fips proxy should be disabled when fips agent is enabled
52+
expectFIPSAgent: true,
4453
},
4554
{
46-
name: "fips.useFipsImages false and fips.enabled false should not use fips-proxy or fips image",
47-
setFipsEnabledSetting: false,
48-
setUseFipsImageSetting: true,
49-
expectFipsProxy: false,
50-
expectFipsImageSuffix: false,
55+
name: "fips image with JMX enabled",
56+
enableFIPSProxy: false,
57+
enableFIPSAgent: true,
58+
expectFIPSProxy: false,
59+
expectFIPSAgent: true,
60+
enableJMX: true,
5161
},
5262
}
5363

5464
for _, tt := range tests {
5565
t.Run(tt.name, func(t *testing.T) {
5666
values := map[string]string{
57-
"fips.useFipsImages": strconv.FormatBool(tt.setUseFipsImageSetting),
58-
"fips.enabled": strconv.FormatBool(tt.setFipsEnabledSetting),
67+
"useFIPSAgent": strconv.FormatBool(tt.enableFIPSAgent),
68+
"fips.enabled": strconv.FormatBool(tt.enableFIPSProxy),
5969
"datadog.apiKeyExistingSecret": "datadog-secret",
60-
"datadog.appKeyExistingSecret": "datadog-secret",
70+
"datadog.appKeyExistingSecret": "datadog-secret",
71+
}
72+
73+
if tt.enableJMX {
74+
values["agents.image.tagSuffix"] = "jmx"
6175
}
6276

6377
manifest, err := common.RenderChart(t, common.HelmCommand{
@@ -81,15 +95,41 @@ func TestFIPSModeConditions(t *testing.T) {
8195
// Check FIPS proxy setting
8296
if value, ok := configMap.Data["should-enable-fips-proxy"]; ok {
8397
fmt.Printf("should-enable-fips-proxy: %s\n", value)
84-
assert.Equal(t, tt.expectFipsProxy, value == "true", "should-enable-fips-proxy value is incorrect")
98+
assert.Equal(t, tt.expectFIPSProxy, value == "true", "should-enable-fips-proxy value is incorrect")
8599
}
86100

87-
// Check FIPS image suffix
88-
for _, container := range daemonSet.Spec.Template.Spec.Containers {
89-
fmt.Printf("container.Image: %s\n", container.Image)
90-
assert.Equal(t, tt.expectFipsImageSuffix, strings.Contains(container.Image, "-fips"), "fips image suffix is incorrect")
91-
}
101+
// Checking that daemonSet contains or not fips-proxy container based on the fips proxy configuration
102+
checkFIPSProxy(t, daemonSet.Spec.Template.Spec.Containers, tt.expectFIPSProxy)
92103

104+
// Checking that all containers have the fips image suffix if fips agent is enabled
105+
checkFIPSImage(t, daemonSet.Spec.Template.Spec.Containers, tt.expectFIPSAgent)
93106
})
94107
}
95108
}
109+
110+
func checkFIPSProxy(t *testing.T, containers []corev1.Container, expectFIPSProxy bool) {
111+
hasFIPSProxy := false
112+
for _, container := range containers {
113+
if strings.Contains(container.Image, "fips-proxy") {
114+
hasFIPSProxy = true
115+
break
116+
}
117+
}
118+
if expectFIPSProxy {
119+
require.True(t, hasFIPSProxy, "fips proxy container should be present")
120+
} else {
121+
require.False(t, hasFIPSProxy, "fips proxy container should not be present")
122+
}
123+
}
124+
125+
func checkFIPSImage(t *testing.T, containers []corev1.Container, expectFIPSImage bool) {
126+
if expectFIPSImage {
127+
for _, container := range containers {
128+
require.Contains(t, container.Image, "-fips", fmt.Sprintf("fips container %s should have the fips image suffix: %s", container.Name, container.Image))
129+
}
130+
} else {
131+
for _, container := range containers {
132+
require.NotContains(t, container.Image, "-fips", fmt.Sprintf("fips container %s should not have the fips image suffix: %s", container.Name, container.Image))
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)