Skip to content

Commit

Permalink
Modify ContainerUser to use strong passwords from membership provider…
Browse files Browse the repository at this point in the history
…. Also ensure warden user has full control on their specific dir, not just child objects.
  • Loading branch information
lukebakken committed Aug 5, 2013
1 parent 82705ce commit 3f22275
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/IronFoundry.Warden/Containers/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ public class Container
private ContainerPort port;
private ContainerState state;

public Container(string handle, ContainerState containerState)
public static Container Restore(string handle, ContainerState containerState)
{
return new Container(handle, containerState);
}

/// <summary>
/// Used for restore.
/// </summary>
private Container(string handle, ContainerState containerState)
{
if (handle.IsNullOrWhiteSpace())
{
Expand Down
2 changes: 1 addition & 1 deletion src/IronFoundry.Warden/Containers/ContainerDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static DirectoryInfo CreateContainerDirectory(ContainerHandle handle, Co

var inheritanceFlags = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
var accessRule = new FileSystemAccessRule(user, FileSystemRights.FullControl, inheritanceFlags,
PropagationFlags.InheritOnly, AccessControlType.Allow);
PropagationFlags.None, AccessControlType.Allow);

DirectoryInfo containerBaseInfo = dirInfo.Item1;
DirectorySecurity security = containerBaseInfo.GetAccessControl();
Expand Down
2 changes: 1 addition & 1 deletion src/IronFoundry.Warden/Containers/ContainerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void RestoreContainers(string containerRoot)
var handle = Path.GetFileName(dirPath);
try
{
var container = new Container(handle, ContainerState.Active);
var container = Container.Restore(handle, ContainerState.Active);
containers.TryAdd(container.Handle, container);
}
catch (Exception ex)
Expand Down
13 changes: 11 additions & 2 deletions src/IronFoundry.Warden/Containers/ContainerUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ public class ContainerUser : IEquatable<ContainerUser>

private readonly string uniqueId;
private readonly string userName;
private readonly string password;

public NetworkCredential GetCredential()
{
return new NetworkCredential(userName, uniqueId);
return new NetworkCredential(userName, password);
}

public ContainerUser(string uniqueId, bool shouldCreate = false)
Expand All @@ -36,10 +37,18 @@ public ContainerUser(string uniqueId, bool shouldCreate = false)
throw new ArgumentException("uniqueId must be 8 or more word characters.");
}

/*
* TODO: this means that we can't retrieve a user's password if restoring a container.
* This should be OK when we move to the "separate process for container" model since the separate
* process will be installed as a service and the password will only need to be known at install
* time.
*/
this.password = System.Web.Security.Membership.GeneratePassword(16, 8);

var principalManager = new LocalPrincipalManager();
if (shouldCreate)
{
principalManager.CreateUser(this.userName, this.uniqueId);
principalManager.CreateUser(this.userName, this.password);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/IronFoundry.Warden/IronFoundry.Warden.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
<Reference Include="System.configuration" />
<Reference Include="System.DirectoryServices" />
<Reference Include="System.DirectoryServices.AccountManagement" />
<Reference Include="System.Web" />
<Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 3f22275

Please sign in to comment.