Skip to content

Commit

Permalink
add secret test in ProgramData
Browse files Browse the repository at this point in the history
  • Loading branch information
jack0x2 committed Dec 20, 2024
1 parent 8b85951 commit 5dd2bc4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package secret

import (
"strings"
"testing"
"time"

Expand All @@ -32,18 +33,22 @@ func TestWindowsRuntimeSecretSuite(t *testing.T) {
)))
}

func (v *windowsRuntimeSecretSuite) TestSecretRuntimeHostname() {
config := `secret_backend_command: C:\TestFolder\wrapper.bat
func (v *windowsRuntimeSecretSuite) testSecretRuntimeHostname(wrapperDirectory string) {
config := `secret_backend_command: ` + wrapperDirectory + `\wrapper.bat
secret_backend_arguments:
- 'C:\TestFolder'
- '` + wrapperDirectory + `'
hostname: ENC[hostname]`

agentParams := []func(*agentparams.Params) error{
agentparams.WithAgentConfig(config),
}
agentParams = append(agentParams, secrets.WithWindowsSecretSetupScript("C:/TestFolder/wrapper.bat", false)...)
if strings.Contains(wrapperDirectory, "ProgramData") {
agentParams = append(agentParams, secrets.WithWindowsSecretSetupScriptNoPerms(wrapperDirectory+"/wrapper.bat")...)
} else {
agentParams = append(agentParams, secrets.WithWindowsSecretSetupScript(wrapperDirectory+"/wrapper.bat", false)...)
}

secretClient := secrets.NewSecretClient(v.T(), v.Env().RemoteHost, "C:/TestFolder")
secretClient := secrets.NewSecretClient(v.T(), v.Env().RemoteHost, wrapperDirectory)
secretClient.SetSecret("hostname", "e2e.test")

v.UpdateEnv(
Expand All @@ -61,3 +66,11 @@ hostname: ENC[hostname]`
}
}, 30*time.Second, 2*time.Second)
}

func (v *windowsRuntimeSecretSuite) TestSecretRuntimeHostname() {
v.testSecretRuntimeHostname(`C:/TestFolder`)
}

func (v *windowsRuntimeSecretSuite) TestSecretRuntimeHostnameProgramData() {
v.testSecretRuntimeHostname(`C:/ProgramData/DataDog/Test`)
}
13 changes: 13 additions & 0 deletions test/new-e2e/tests/agent-shared-components/secretsutils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ func WithWindowsSecretSetupScript(wrapperPath string, allowGroupExec bool) []fun
}
}

func WithWindowsSecretSetupScriptNoPerms(wrapperPath string) []func(*agentparams.Params) error {
wrapperPath = strings.ReplaceAll(wrapperPath, `\`, `/`)

dir, _ := filepath.Split(wrapperPath)
pythonScriptPath := filepath.Join(dir, "secret.py")
secretWrapperContent := fillSecretWrapperTemplate(strings.ReplaceAll(pythonScriptPath, "/", "\\"))

return []func(*agentparams.Params) error{
agentparams.WithFile(wrapperPath, secretWrapperContent, true),
agentparams.WithFile(pythonScriptPath, secretResolverScript, true),
}
}

// WithWindowsSecretPermissions returns a WindowsPermissions object containing correct permissions for a secret backend script.
func WithWindowsSecretPermissions(allowGroupExec bool) optional.Option[perms.FilePermissions] {
icaclsCmd := `/grant "ddagentuser:(RX)"`
Expand Down

0 comments on commit 5dd2bc4

Please sign in to comment.