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

Add Secrets test in ProgramData #32438

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
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`)
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ func WithWindowsSecretSetupScript(wrapperPath string, allowGroupExec bool) []fun
}
}

// WithWindowsSecretSetupScriptNoPerms returns a list of agent params that setups a secret resolver script with no permissions.
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
Loading