Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick: Reject dynakubes that use public image and not read only oneAgent #4346 #4386

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/api/validation/dynakube/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestImageFieldHasTenantImage(t *testing.T) {
Spec: dynakube.DynaKubeSpec{
APIURL: testTenantUrl + "/api",
OneAgent: oneagent.Spec{
ClassicFullStack: &oneagent.HostInjectSpec{
HostMonitoring: &oneagent.HostInjectSpec{
Image: testRegistryUrl + "/linux/oneagent:latest",
},
},
Expand All @@ -72,7 +72,7 @@ func TestImageFieldHasTenantImage(t *testing.T) {
Spec: dynakube.DynaKubeSpec{
APIURL: testTenantUrl + "/api",
OneAgent: oneagent.Spec{
ClassicFullStack: &oneagent.HostInjectSpec{
HostMonitoring: &oneagent.HostInjectSpec{
Image: testRegistryUrl + "/linux/oneagent:latest",
},
},
Expand All @@ -88,7 +88,7 @@ func TestImageFieldHasTenantImage(t *testing.T) {
Spec: dynakube.DynaKubeSpec{
APIURL: testTenantUrl + "/api",
OneAgent: oneagent.Spec{
ClassicFullStack: &oneagent.HostInjectSpec{
HostMonitoring: &oneagent.HostInjectSpec{
Image: "127.0.0.1:5000/test:tag",
},
},
Expand Down
10 changes: 10 additions & 0 deletions pkg/api/validation/dynakube/oneagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Use a nodeSelector to avoid this conflict. Conflicting DynaKubes: %s`

errorVolumeStorageReadOnlyModeConflict = `The DynaKube specification specifies a read-only host file system while OneAgent has volume storage enabled.`

errorPublicImageWithWrongConfig = `Custom OneAgent image is only supported when CSI Driver is used.`

warningOneAgentInstallerEnvVars = `The environment variables ONEAGENT_INSTALLER_SCRIPT_URL and ONEAGENT_INSTALLER_TOKEN are only relevant for an unsupported image type. Please ensure you are using a supported image.`

warningHostGroupConflict = `The DynaKube specification sets the host group using the --set-host-group parameter. Instead, specify the new spec.oneagent.hostGroup field. If both settings are used, the new field takes precedence over the parameter.`
Expand Down Expand Up @@ -125,6 +127,14 @@ func mapKeysToString(m map[string]bool, sep string) string {
return strings.Join(keys, sep)
}

func publicImageSetWithoutReadOnlyMode(_ context.Context, v *Validator, dk *dynakube.DynaKube) string {
if !dk.OneAgent().IsReadOnlyOneAgentsMode() && dk.OneAgent().GetCustomImage() != "" {
return errorPublicImageWithWrongConfig
}

return ""
}

func imageFieldSetWithoutCSIFlag(_ context.Context, v *Validator, dk *dynakube.DynaKube) string {
if dk.OneAgent().IsApplicationMonitoringMode() {
if len(dk.Spec.OneAgent.ApplicationMonitoring.CodeModulesImage) > 0 && !v.modules.CSIDriver {
Expand Down
44 changes: 44 additions & 0 deletions pkg/api/validation/dynakube/oneagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,50 @@ func TestIsOneAgentVersionValid(t *testing.T) {
}
}

func TestPublicImageSetWithReadOnlyMode(t *testing.T) {
t.Run("reject dk with hostMon without csi and custom image", func(t *testing.T) {
setupDisabledCSIEnv(t)
assertDenied(t, []string{errorPublicImageWithWrongConfig},
&dynakube.DynaKube{
ObjectMeta: defaultDynakubeObjectMeta,
Spec: dynakube.DynaKubeSpec{
APIURL: testApiUrl,
OneAgent: oneagent.Spec{
HostMonitoring: &oneagent.HostInjectSpec{
Image: "test/image/test-image:some-tag",
},
},
},
})
})
t.Run("allow dk with hostMon without csi and no custom image", func(t *testing.T) {
setupDisabledCSIEnv(t)
assertAllowed(t,
&dynakube.DynaKube{
ObjectMeta: defaultDynakubeObjectMeta,
Spec: dynakube.DynaKubeSpec{
APIURL: testApiUrl,
OneAgent: oneagent.Spec{
HostMonitoring: &oneagent.HostInjectSpec{},
},
},
})
})
t.Run("allow dk with hostMon with csi and custom image", func(t *testing.T) {
assertAllowed(t, &dynakube.DynaKube{
ObjectMeta: defaultDynakubeObjectMeta,
Spec: dynakube.DynaKubeSpec{
APIURL: testApiUrl,
OneAgent: oneagent.Spec{
HostMonitoring: &oneagent.HostInjectSpec{
Image: "test/image/test-image:some-tag",
},
},
},
})
})
}

func TestOneAgentArguments(t *testing.T) {
type oneAgentArgumentTest struct {
testName string
Expand Down
1 change: 1 addition & 0 deletions pkg/api/validation/dynakube/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (
duplicatedTelemetryServiceProtocols,
invalidTelemetryServiceName,
extensionsWithoutK8SMonitoring,
publicImageSetWithoutReadOnlyMode,
}
validatorWarningFuncs = []validatorFunc{
missingActiveGateMemoryLimit,
Expand Down
Loading