Repository navigation
Stop deriving Linux Tentacle's config encryption key from /etc/machine-id #1348
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
Merged
Merged
Changes from all commits
Commits
Show all changes
129 commits
Select commit
Hold shift + click to select a range
21f349c
Stop deriving Linux Tentacle's config encryption key from /etc/machin…
LukeButters d8b0dfc
Clean up the Linux config encryption key change (#1352)
LukeButters da6126c
Tell the user how to recover when the configuration encryption key is…
LukeButters ba4b996
Tell the user to keep the machine's name when re-registering after lo…
LukeButters 2b4e1ca
Add replace-certificate to recover a Tentacle whose certificate or ke…
LukeButters cf74368
Create the configuration encryption key before creating the instance
LukeButters ac98d5f
Fix the net48 build of the unit tests
LukeButters 7abe373
Don't point users at the test-only keys directory override
LukeButters 5f818a8
Point the legacy decrypt failure at replace-certificate
LukeButters 727f7ff
Make shared key directories traversable under a hardened umask
LukeButters 47c0e6d
Refuse to start when only the configuration file is persisted
LukeButters d69cd1b
Use the nobody user in the hardened umask test so it runs on Alpine
LukeButters 8b14d76
Create a real user in the hardened umask test, with adduser on Alpine
LukeButters eeeacfb
Store Linux machine-key values as AES256-GCM$nonce$ciphertext
LukeButters fa7f5cb
Store tag in its own field: AESGCM-V1$nonce$tag$ciphertext
LukeButters 7a9e934
Keep the configuration encryption key under each instance's data dire…
LukeButters 6793c4c
Test that a lost key leaves migrated values untouched; run upgrade fi…
LukeButters 3e06c12
Pass the test encryptor to the configuration builder's store
LukeButters 8f6b238
Mark the user-only atomic file create as unsupported on Windows
LukeButters 804a0f5
Replace the config encryption shell test with Docker integration tests
LukeButters ce2e851
Mark UnixFile as unsupported on Windows
LukeButters b58bba2
Inline paths in the config encryption Docker tests
LukeButters 3ed61fe
Start re-created and refusing Tentacles through the container builder
LukeButters a2e8ffc
Mark arrange, act and assert in the config encryption Docker tests
LukeButters 36d03cc
Test config encryption separately from container re-creation
LukeButters fe27a9a
Rename WithRunTentacleEnvironmentVariable to WithEnvironmentVariable
LukeButters 2481066
Make key tests self-contained instead of inheriting fixture setup
LukeButters d982363
Tell the user to run as root when the configuration encryption key ca…
LukeButters c12e27d
Revert "Tell the user to run as root when the configuration encryptio…
LukeButters e5509b7
Pass legacy generated key path in rather than reading env var; inline…
LukeButters c7a1dbe
Remove create-instance test covered by ApplicationInstanceManagerFixture
LukeButters ca12d6b
Pass key file contents to CreateEncryptor instead of presence flags
LukeButters f5d302b
Inline encryptor setup in legacy ciphertext tests
LukeButters 2bb4853
Remove LinuxConfigurationFileSecurityFixture
LukeButters 76759de
Rename LinuxMachineKeyEncryptorFixture to Tests and inline setup
LukeButters e68809d
Convert fixtures added in this PR to Tests classes without shared setup
LukeButters 104afbd
Test on each distro that a non-root create-instance is told the comma…
LukeButters eaeabd3
Revert "Test on each distro that a non-root create-instance is told t…
LukeButters f93926c
Test config encryption key failures through agent start and create-in…
LukeButters 9c1a243
Test create-instance key failure through real instance store; drop in…
LukeButters 8c796d9
Restore Linux key file permission, concurrency and umask tests
LukeButters 47a1bda
Cover create-instance key failure with a single real-executable test
LukeButters c236169
Delete test we don't need
LukeButters cf0bef7
Test --config key selection through the installed package instead of …
LukeButters 5e39b51
Remove test-linux-package.sh
LukeButters f238cdb
Restore registered-instance key selection test
LukeButters a314dc2
Revert "Remove test-linux-package.sh"
LukeButters 72c862d
Remove test asserting unregistered configurations stay on legacy keys
LukeButters 77a2c4e
Remove in-process upgrade tests now covered by old-to-new Tentacle tests
LukeButters 4b62340
Test upgrading a version 14 configuration from the machine-id key to …
LukeButters accc06f
Name the version 14 Tentacle helper for what it returns
LukeButters 42d657e
Name the certificate helper for the encrypted value it reads
LukeButters 8b1965a
Name the redirected Tentacle directories for what they are
LukeButters 518f25e
Make the version 14 upgrade tests read as a story
LukeButters 13f4e07
Add a builder for a Tentacle instance that is not running, and use it…
LukeButters 9e489b9
Read the stored certificate from the Tentacle instance
LukeButters 31980e6
Let a Tentacle instance own its Tentacle version and switch to the la…
LukeButters 8501b8c
Build the Tentacle instance with its Tentacle and upgrade it to the l…
LukeButters 3c2d66a
Build the Tentacle instance with its Tentacle and switch to the curre…
LukeButters 598b3ca
Test that an unnamed version 14 instance is told to create a named in…
LukeButters 1132beb
Name the configuration encryption upgrade tests When_And_Then
LukeButters 6c6409e
Move the lost key test to the real executable and drop the mocked upg…
LukeButters f4486d8
Build running Tentacles from a TentacleInstance, and test the upgrade…
LukeButters d324aba
Test the upgrade by restarting a running version 14 Tentacle as the c…
LukeButters f082eec
Rename RestartWithCurrentTentacle to StopAndStartWithCurrentVersionOf…
LukeButters e194806
Assert encryption key failures are about the missing key
LukeButters 4aab95f
Align the Docker test setup with #1363
LukeButters b993f0f
Retry Tentacle commands that fail while another test registers an ins…
LukeButters d860c16
Download each old Tentacle into its own temporary directory
LukeButters 78bc03b
Import certificates into unnamed instances through their configuratio…
LukeButters ed8ba4b
Reject running a caller-built instance as a service
LukeButters e0946ce
Keep the name and certificate a caller chose when running an instance
LukeButters 88c7f07
Pass cancellation tokens to Tentacle instance commands instead of sto…
LukeButters 34268d3
Keep one multi-block unicode legacy ciphertext case per key
LukeButters 651f473
Test that Tentacle still starts on legacy keys when the new key canno…
LukeButters 3764b2f
Drop show-thumbprint checks from the package test; dotnet tests cover…
LukeButters e85a52e
Say why the package test exercises the configuration encryption key
LukeButters cda8340
Run a script on the Tentacle that started on legacy keys
LukeButters 4ee0107
Use TemporaryDirectory in the non-root create-instance test
LukeButters 0d71712
Remove re-encryption typed-read test; re-encryption only moves strings
LukeButters 9a17bcf
Merge origin/main
LukeButters 2871f8c
Move FakeOctopusServer to Tests.Integration.Common and test replace-c…
LukeButters b5fac5f
Merge remote-tracking branch 'origin/main' into luke/lev-1171-config-…
LukeButters 2bde0c8
Name the replace-certificate test after the Linux encryption upgrade …
LukeButters bc5b0e6
Inline the single legacy ciphertext case in each test
LukeButters 84def5b
Replace the key file fixture with self-contained tests
LukeButters 42a1a86
Use LinuxOrMacTest rather than an inline platform check
LukeButters 4dc4d54
Write instance index files atomically so concurrent listings never re…
LukeButters 65fecf9
Revert "Write instance index files atomically so concurrent listings …
LukeButters e139953
Decrypt protected settings outside the parse catch so their recovery …
LukeButters 1bc0bfd
Shorten the hierarchical store's encryption guard comment
LukeButters bd84f3e
Say the hierarchical store is only for display
LukeButters 6e57e5d
Drop the unused encryption guard from the display-only configuration …
LukeButters 247cd31
Skip encrypted values in show-configuration output
LukeButters aa20e5f
Merge remote-tracking branch 'origin/main' into luke/lev-1171-config-…
LukeButters eb5f992
Rename TentacleConfigurationUpgrade to ConfigurationEncryptionUpgrade
LukeButters 564a175
Mark the Linux unit test Docker script as local only
LukeButters ab5d1c6
Move the local-only Linux unit test script into testing/local
LukeButters 3dc4590
Move the local Linux unit test script to its own PR
LukeButters a44008e
Rename configurationUpgrade to configurationEncryptionUpgrade
LukeButters 90bb003
Explain why calling the runtime's stat shim is safe
LukeButters 8a05a4d
Note the test that guards the stat shim layout
LukeButters eb1f0da
Stop telling users to regenerate the legacy machine key
LukeButters cf582a9
Explain why the upgrade loads the key first
LukeButters 1230ad2
Merge remote-tracking branch 'origin/main' into luke/lev-1171-config-…
LukeButters c9539be
Throw ControlledFailureException when the configuration key is missin…
LukeButters 54c796b
Make keyFilePath a required ApplicationInstanceConfiguration parameter
LukeButters 0f60588
Fix stale comment wording and add missing braces
LukeButters d6a31c9
+semver: major
LukeButters 68948fe
Report an unreadable key directory instead of treating the key as mis…
LukeButters d6cac4d
Test an unreadable key by running Tentacle as another user, and clean…
LukeButters 290283e
Create the configuration encryption key without hard links on filesys…
LukeButters 16d2564
Report configuration encryption key failures as themselves rather tha…
LukeButters 816a763
Add reset-configuration-encryption to recover from a lost key, and st…
LukeButters 3217c5a
Move the configuration encryption key into place with File.Move inste…
LukeButters 4c1332d
Test recovering a Tentacle from a lost key end to end, through to run…
LukeButters 956310a
.
LukeButters 79c6dc1
.
LukeButters b683c34
Delete the unused LegacySchemeEncryptor test helper
LukeButters e820790
Delete the concurrent key creation test; each instance has its own key
LukeButters 0ea3061
Test a hardened umask by running the real Tentacle as root, rather th…
LukeButters 458d333
Add known-answer test for AESGCM-V1 format
LukeButters 8cfd0a9
Make the suggested key directory fix work under a hardened umask
LukeButters abae66c
Revert "Make the suggested key directory fix work under a hardened um…
LukeButters e2fbe91
Merge remote-tracking branch 'origin/main' into luke/lev-1171-config-…
LukeButters 0ab33cc
Test that installing the service for another user leaves the key read…
LukeButters 76f4d13
Run the service install test as plain root rather than with a umask
LukeButters 7c31c0e
Run Linux integration tests with systemd in the local Docker helper
LukeButters 00cf7c0
.
LukeButters File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| #if !NETFRAMEWORK | ||
| using System.IO; | ||
| using System.Runtime.InteropServices; | ||
| using System.Runtime.Versioning; | ||
| using Microsoft.Win32.SafeHandles; | ||
|
|
||
| namespace Octopus.Tentacle.Core.Util | ||
| { | ||
| [UnsupportedOSPlatform("windows")] | ||
| public static class UnixFile | ||
| { | ||
| const uint UnchangedGroup = uint.MaxValue; | ||
|
|
||
| public static uint OwnerOf(string path) | ||
| { | ||
| return SystemNative_Stat(path, out var status) == 0 | ||
| ? status.Uid | ||
| : throw new IOException($"Unable to find the owner of `{path}`: {Marshal.GetLastPInvokeErrorMessage()}"); | ||
| } | ||
|
|
||
| public static void SetOwnerIfRunningAsRoot(uint owner, string path) | ||
| { | ||
| if (geteuid() != 0 || OwnerOf(path) == owner) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (lchown(path, owner, UnchangedGroup) != 0) | ||
| { | ||
| throw new IOException($"Unable to change the owner of `{path}`: {Marshal.GetLastPInvokeErrorMessage()}"); | ||
| } | ||
| } | ||
|
|
||
| public static void GiveTo(SafeFileHandle file, uint owner) | ||
| { | ||
| if (fchown(file, owner, UnchangedGroup) != 0) | ||
| { | ||
| throw new IOException(Marshal.GetLastPInvokeErrorMessage()); | ||
| } | ||
| } | ||
|
|
||
| [DllImport("libc")] | ||
| static extern uint geteuid(); | ||
|
|
||
| [DllImport("libc", SetLastError = true)] | ||
| static extern int lchown(string path, uint owner, uint group); | ||
|
|
||
| [DllImport("libc", SetLastError = true)] | ||
| static extern int fchown(SafeFileHandle fd, uint owner, uint group); | ||
|
|
||
| // This is an internal shim that could change in the future, although it hasn't changed for years. | ||
| // This would only break when we update .net, which we do by commiting to this repo. Thus tests will catch the | ||
| // issue which would allow us to fix it. | ||
| [DllImport("libSystem.Native", SetLastError = true)] | ||
| static extern int SystemNative_Stat(string path, out FileStatus output); | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| struct FileStatus | ||
| { | ||
| public int Flags; | ||
| public int Mode; | ||
| public uint Uid; | ||
| public uint Gid; | ||
| public long Size; | ||
| public long ATime; | ||
| public long ATimeNsec; | ||
| public long MTime; | ||
| public long MTimeNsec; | ||
| public long CTime; | ||
| public long CTimeNsec; | ||
| public long BirthTime; | ||
| public long BirthTimeNsec; | ||
| public long Dev; | ||
| public long RDev; | ||
| public long Ino; | ||
| public uint UserFlags; | ||
| } | ||
| } | ||
| } | ||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
This looks like a regression. Were the test failures this was causing not a scenario we care about?
File.Moveis not guaranteed to be atomic.Maybe it is in the cases where we use it in this PR, but this is a more general class, so it could cause confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the added code complexity is worth it for the edge case of race conditions specific to Linux-only tentacles that are running on a non-hard-linking FS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method name says
TryAtomic..... It should be renamed if it is not doing it atomically.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to leave it as atomic since its what we want and practically speaking its atomic.
It's not atomic when we have fat/exfat (who is running that?), or samba e.g. for azure shares. Azure shares provide no guarantee for atomic operations of complete files, even if we went back to the complex code we had before.