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

Update ProgramFile Directory permissions #32117

Draft
wants to merge 5 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
38 changes: 32 additions & 6 deletions test/new-e2e/tests/windows/install-test/installtester.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,23 +466,28 @@ func (t *Tester) testInstalledFilePermissions(tt *testing.T, ddAgentUserIdentity
path string
expectedSecurity func(t *testing.T) windows.ObjectSecurity
}{
//ConfigRoot is only owned by SYSTEM and Administrators
{
name: "ConfigRoot",
path: t.expectedConfigRoot,
expectedSecurity: func(tt *testing.T) windows.ObjectSecurity {
expected, err := getBaseConfigRootSecurity()
require.NoError(tt, err)
if windows.IsIdentityLocalSystem(ddAgentUserIdentity) {
return expected
}
expected.Access = append(expected.Access,
windows.NewExplicitAccessRuleWithFlags(
ddAgentUserIdentity,
windows.FileFullControl,
windows.FileReadAndExecute|windows.SYNCHRONIZE,
windows.AccessControlTypeAllow,
windows.InheritanceFlagsContainer|windows.InheritanceFlagsObject,
windows.PropagationFlagsNone,
),
windows.NewExplicitAccessRuleWithFlags(
ddAgentUserIdentity,
windows.FileWrite,
windows.AccessControlTypeAllow,
windows.InheritanceFlagsContainer,
windows.PropagationFlagsNone,
),
)
return expected
},
Expand All @@ -497,11 +502,17 @@ func (t *Tester) testInstalledFilePermissions(tt *testing.T, ddAgentUserIdentity
return expected
}
expected.Access = append(expected.Access,
windows.NewInheritedAccessRule(
windows.NewExplicitAccessRule(
ddAgentUserIdentity,
windows.FileFullControl,
windows.AccessControlTypeAllow,
),
// extra inherited rule for ddagentuser
windows.NewInheritedAccessRule(
ddAgentUserIdentity,
windows.FileReadAndExecute|windows.SYNCHRONIZE,
windows.AccessControlTypeAllow,
),
)
return expected
},
Expand All @@ -516,13 +527,28 @@ func (t *Tester) testInstalledFilePermissions(tt *testing.T, ddAgentUserIdentity
return expected
}
expected.Access = append(expected.Access,
windows.NewInheritedAccessRuleWithFlags(
windows.NewExplicitAccessRuleWithFlags(
ddAgentUserIdentity,
windows.FileFullControl,
windows.AccessControlTypeAllow,
windows.InheritanceFlagsContainer|windows.InheritanceFlagsObject,
windows.PropagationFlagsNone,
),
// extra inherited rule for ddagentuser
windows.NewInheritedAccessRuleWithFlags(
ddAgentUserIdentity,
windows.FileReadAndExecute|windows.SYNCHRONIZE,
windows.AccessControlTypeAllow,
windows.InheritanceFlagsContainer|windows.InheritanceFlagsObject,
windows.PropagationFlagsNone,
),
windows.NewInheritedAccessRuleWithFlags(
ddAgentUserIdentity,
windows.FileWrite,
windows.AccessControlTypeAllow,
windows.InheritanceFlagsContainer,
windows.PropagationFlagsNone,
),
)
return expected
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,47 @@ private void GrantAgentAccessPermissions()
}
}

private void AddDatadogUserToDataFolder()
{
var dataDirectory = _session.Property("APPLICATIONDATADIRECTORY");

FileSystemSecurity fileSystemSecurity;
try
{
fileSystemSecurity = _fileSystemServices.GetAccessControl(dataDirectory, AccessControlSections.All);
}
catch (Exception e)
{
_session.Log($"Failed to get ACLs on {dataDirectory}: {e}");
throw;
}
// ddagentuser Read and execute permissions, enable child inheritance of this ACE
fileSystemSecurity.AddAccessRule(new FileSystemAccessRule(
_ddAgentUserSID,
FileSystemRights.ReadAndExecute | FileSystemRights.Synchronize,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow));

// datadog write on this folder
fileSystemSecurity.AddAccessRule(new FileSystemAccessRule(
_ddAgentUserSID,
FileSystemRights.Write,
InheritanceFlags.ContainerInherit,
PropagationFlags.None,
AccessControlType.Allow));
try
{
UpdateAndLogAccessControl(dataDirectory, fileSystemSecurity);
}
catch (Exception e)
{
_session.Log($"Failed to set ACLs on {dataDirectory}: {e}");
throw;
}

}

private void ConfigureFilePermissions()
{
try
Expand All @@ -471,6 +512,7 @@ private void ConfigureFilePermissions()

if (_ddAgentUserSID != new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null))
{
AddDatadogUserToDataFolder();
GrantAgentAccessPermissions();
}
}
Expand Down Expand Up @@ -579,17 +621,20 @@ public static ActionResult ConfigureUserRollback(Session session)

private List<string> PathsWithAgentAccess()
{
return new List<string>
{
// agent needs to be able to write logs/
// agent GUI needs to be able to edit config
// agent needs to be able to write to run/
// agent needs to be able to create auth_token
_session.Property("APPLICATIONDATADIRECTORY"),
// allow agent to write __pycache__
var configRoot = _session.Property("APPLICATIONDATADIRECTORY");

return new List<string> {
Path.Combine(configRoot, "conf.d"),
Path.Combine(configRoot, "checks.d"),
Path.Combine(configRoot, "run"),
Path.Combine(configRoot, "logs"),
Path.Combine(configRoot, "datadog.yaml"),
Path.Combine(configRoot, "system-probe.yaml"),
Path.Combine(configRoot, "auth_token"),
Path.Combine(configRoot, "install_info"),
Path.Combine(_session.Property("PROJECTLOCATION"), "embedded2"),
Path.Combine(_session.Property("PROJECTLOCATION"), "embedded3"),
};
}; ;
}

/// <summary>
Expand Down
Loading