Skip to content

Restrict Tentacle config file permissions on Windows - #1374

Merged
sburmanoctopus merged 4 commits into
mainfrom
levi/restrict-windows-config-acl
Nov 26, 2026
Merged

sburmanoctopus merged 4 commits into
mainfrom
levi/restrict-windows-config-acl

Conversation

@sburmanoctopus

@sburmanoctopus sburmanoctopus commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes: #1375
Fixes: LEV-2268

This is the Windows half of #1349. On Windows, Tentacle.config inherits its folder's ACL. Under the default C:\Octopus that gives Authenticated Users: Modify, and the certificate and proxy password in it use DPAPI LocalMachine, so any local user can read and decrypt them.

This is a major version bump (+semver: major): users other than SYSTEM, Administrators and the service account can no longer read the config.

Changes

  • On creation: create-instance creates the config with an ACL that doesn't inherit from the folder: SYSTEM, Administrators and the creating user get full control. The ACL is set when the file is created, so the file never has the folder's ACL.
  • On agent start: if the config still inherits its folder's ACL, the agent stops the inheritance, keeps the file's own entries, and grants SYSTEM, Administrators and the account it runs as full control. This fixes existing installs, including the default LocalSystem service, on their next restart. An ACL that already doesn't inherit is left alone. If the agent can't change it, it logs a warning and carries on.
  • On install: service --install/--reconfigure --username X applies the same restriction and grants X Modify. If X can't be resolved, nothing is changed and a warning is logged. Without --username, the file is left alone, because the service may keep an existing account that relies on the inherited ACL.
  • ServiceCommand now restricts the config before configuring the service, so --install --username X --start doesn't start the service before X can read the file. This also moves the Linux chown earlier.

Known gaps

  • If an administrator runs Tentacle.exe agent by hand while the service is set to a non-admin account that relies on the inherited ACL, that account loses access. Linux has the same trade-off.
  • Protected settings are still encrypted with DPAPI LocalMachine. CurrentUser would stop administrators running Tentacle.exe commands against the config.
  • The new [WindowsTest] tests only run on Windows CI.

🤖 Generated with Claude Code

New configs are created readable only by SYSTEM, Administrators and the
creating user. The agent stops existing configs inheriting their folder's
permissions on start, and service --install/--reconfigure --username grants
the service account Modify before the service is configured.

+semver: major

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sburmanoctopus
sburmanoctopus marked this pull request as ready for review November 24, 2026 22:54
@sburmanoctopus
sburmanoctopus requested a review from a team as a code owner November 24, 2026 22:54

namespace Octopus.Tentacle.Tests.Configuration
{
[TestFixture]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Say no to fixtures.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed


string directory = null!;

[SetUp]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builders or nothing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, and added WindowsConfigurationFileBuilder

}

[Test]
public void WhenAnEmptyConfigIsCreatedThenOnlySystemAdministratorsAndTheCurrentUserCanAccessIt()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a TentacleInstanceBuilder() can you test at that level?

Also if you test at that level you could run commands as a different user which might make it easier to test non admin users.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

I've moved the "config is created restricted" test up to the TentacleInstanceBuilder level in the new WindowsConfigurationFilePermissionsTests (that runs the real "create-instance").

Comment on lines 26 to 37
@@ -35,40 +36,58 @@
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to pull this method out here in this PR, its either make a new empty file one way or another.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we want to call an interface?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have turned this into an interface with a Linux and Windows implementation

Comment on lines 26 to 37
@@ -35,40 +36,58 @@
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we want to call an interface?

Comment on lines 56 to 68
try
{
var previousMode = File.GetUnixFileMode(configurationPath);
if (previousMode != OwnerOnly)
{
File.SetUnixFileMode(configurationPath, OwnerOnly);
log.Info($"Restricted `{configurationPath}` from {Convert.ToString((int)previousMode, 8).PadLeft(4, '0')} to 0600");
}
}
catch (Exception ex) when (ex is UnauthorizedAccessException or IOException)
{
log.Warn($"Unable to restrict `{configurationPath}` to its owner, so other users may be able to read it: {ex.Message}");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think pull this out like you did with windows.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull out? Like, centralize the warning? or logic? Was this part of the interface split?


#if NET
[UnsupportedOSPlatform("windows")]
static string? TryRestrictToServiceUser(string configurationPath, string userName)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be pulled out similar to how windows pulls it out.

I think overall making the linux/windows paths mirror each other makes sense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the split, they mirror each other.

static readonly SecurityIdentifier LocalSystem = new(WellKnownSidType.LocalSystemSid, null);
static readonly SecurityIdentifier Administrators = new(WellKnownSidType.BuiltinAdministratorsSid, null);

public static void CreateEmpty(string configurationPath, string contents)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name needs to describe what it is doing here, what is the important thing it is doing here that could be done with a one liner File.Create(path, contents)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename to CreateRestrictedToCurrentUser


// Runs as the account Tentacle runs as, so it can't lock that account out. An ACL that no longer inherits from
// its folder has already been restricted, by Tentacle or by an administrator, so it is left alone.
public static void RestrictToOwner(string configurationPath, ISystemLog log)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know the service account that runs this tentacle, should we ensure it still has access to this file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The agent runs as the service account, so "current user" is the service account and keeps FullControl.

Explicit entries such as the one "service --install --username" adds are also kept, since only inherited entries are dropped.

To help, we renamed to RestrictToCurrentUser and added a comment.

@sburmanoctopus
sburmanoctopus enabled auto-merge (squash) November 26, 2026 01:30
@sburmanoctopus
sburmanoctopus merged commit 938e90f into main Nov 26, 2026
47 checks passed
@sburmanoctopus
sburmanoctopus deleted the levi/restrict-windows-config-acl branch November 26, 2026 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tentacle config file is readable by other local users on Windows

2 participants