Repository navigation
[ML] Reap child IPC dirs and fail closed on degraded seccomp #3217
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
+757
−212
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8e68e98
[ML] Reap per-deployment ml-child-ipc directories when pytorch_infere…
valeriy42 b3a731b
[ML] Fail closed when degraded-route seccomp installation fails
valeriy42 840d665
[ML] Address IPC reaper review after rebase onto main
valeriy42 4392378
[ML] Fix Windows link and macOS test path in IPC reaper PR
valeriy42 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the following additional limitation. Functionality enabled by the | ||
| * files subject to the Elastic License 2.0 may only be used in production when | ||
| * invoked by an Elasticsearch process with a license key installed that permits | ||
| * use of machine learning features. You may not use this file except in | ||
| * compliance with the Elastic License 2.0 and the foregoing additional | ||
| * limitation. | ||
| */ | ||
| #ifndef INCLUDED_ml_sandbox_CChildIpcDirectoryReaper_h | ||
| #define INCLUDED_ml_sandbox_CChildIpcDirectoryReaper_h | ||
|
|
||
| #include <core/CProcess.h> | ||
|
|
||
| #include <map> | ||
| #include <mutex> | ||
| #include <string> | ||
|
|
||
| namespace ml { | ||
| namespace sandbox { | ||
|
|
||
| //! Removes a single per-deployment directory under $TMPDIR/ml-child-ipc/<child-id> | ||
| //! once the controller no longer has a live child bound to it. | ||
| //! | ||
| //! Lifecycle (paired with ensureChildIpcDirectory()): | ||
| //! - ensureChildIpcDirectory() creates $TMPDIR/ml-child-ipc/<child-id> (0700) before | ||
| //! realpath()/policy construction; the intermediate ml-child-ipc directory is kept. | ||
| //! - noteSpawn() records which pid owns that canonical root for a successful launch. | ||
| //! - onChildExited() removes the directory only when the root is still bound to that pid | ||
| //! (a fast restart reusing the same deployment id updates the binding first). | ||
| //! - onSpawnFailed() removes a root that was created but never got a live pid. | ||
| //! Ownership validation and directory removal run under one lock: a concurrent | ||
| //! noteSpawn() for the same deployment root cannot interleave between unbinding | ||
| //! and unlink/rmdir. | ||
| //! | ||
| //! Controller crash can still leave empty directories; there is no startup sweep because | ||
|
valeriy42 marked this conversation as resolved.
|
||
| //! that would race another controller on the same $TMPDIR. | ||
| class CChildIpcDirectoryReaper { | ||
| public: | ||
| void noteSpawn(core::CProcess::TPid pid, const std::string& canonicalChildRoot); | ||
|
|
||
| void onChildExited(core::CProcess::TPid pid); | ||
|
|
||
| void onSpawnFailed(const std::string& canonicalChildRoot); | ||
|
|
||
| private: | ||
| static bool canonicalPerChildIpcRootHasExpectedShape(const std::string& canonicalChildRoot); | ||
|
|
||
| static bool tryRemovePerChildIpcDirectory(const std::string& canonicalChildRoot); | ||
|
|
||
| std::mutex m_Mutex; | ||
| std::map<core::CProcess::TPid, std::string> m_PidToRoot; | ||
| std::map<std::string, core::CProcess::TPid> m_RootToPid; | ||
| }; | ||
|
|
||
| } // namespace sandbox | ||
| } // namespace ml | ||
|
|
||
| #endif // INCLUDED_ml_sandbox_CChildIpcDirectoryReaper_h | ||
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
Oops, something went wrong.
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.