Skip to content
Open
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
8 changes: 7 additions & 1 deletion src/Common/Miscellaneous/ValidationConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ public enum NotificationValues
/// </summary>
public const string Email = "email";

/// <summary>
/// Key for the podman task type.
/// </summary>
public const string PodmanTaskType = "podman";

public static readonly string[] AcceptableTasksToReview = { ArgoTaskType, ExternalAppTaskType };

/// <summary>
Expand All @@ -147,7 +152,8 @@ public enum NotificationValues
DockerTaskType,
Email,
ExternalAppTaskType,
HL7ExportTask
HL7ExportTask,
PodmanTaskType
};
}
}
14 changes: 14 additions & 0 deletions src/Monai.Deploy.WorkflowManager.sln
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monai.Deploy.WorkflowManage
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monai.Deploy.WorkflowManager.TaskManager.Docker.Tests", "..\tests\UnitTests\TaskManager.Docker.Tests\Monai.Deploy.WorkflowManager.TaskManager.Docker.Tests.csproj", "{BF6569A1-1A5A-4358-9C02-1A6A5F0FBFD9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monai.Deploy.WorkflowManager.TaskManager.Podman", "TaskManager\Plug-ins\Podman\Monai.Deploy.WorkflowManager.TaskManager.Podman.csproj", "{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monai.Deploy.WorkflowManager.TaskManager.Podman.Tests", "..\tests\UnitTests\TaskManager.Podman.Tests\Monai.Deploy.WorkflowManager.TaskManager.Podman.Tests.csproj", "{B2C3D4E5-F6A7-8901-BCDE-F12345678901}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monai.Deploy.WorkflowManager.Shared.Tests", "..\tests\UnitTests\Monai.Deploy.WorkflowManager.Shared.Tests\Monai.Deploy.WorkflowManager.Shared.Tests.csproj", "{C853A9E3-C53D-4B1A-BFDA-228689A8C94C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monai.Deploy.WorkflowManager.Common.Tests", "..\tests\UnitTests\Common.Tests\Monai.Deploy.WorkflowManager.Common.Tests.csproj", "{75A4AEDA-0386-4B2D-9DBA-BC9AE733660E}"
Expand Down Expand Up @@ -224,6 +228,14 @@ Global
{BF6569A1-1A5A-4358-9C02-1A6A5F0FBFD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF6569A1-1A5A-4358-9C02-1A6A5F0FBFD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF6569A1-1A5A-4358-9C02-1A6A5F0FBFD9}.Release|Any CPU.Build.0 = Release|Any CPU
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.Build.0 = Release|Any CPU
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Release|Any CPU.Build.0 = Release|Any CPU
{C853A9E3-C53D-4B1A-BFDA-228689A8C94C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C853A9E3-C53D-4B1A-BFDA-228689A8C94C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C853A9E3-C53D-4B1A-BFDA-228689A8C94C}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -290,6 +302,8 @@ Global
{EFECF826-B036-4689-B223-D791CD2C0F10} = {71DDEE7B-E213-4E39-A7F4-4646783A27F7}
{47C31FB9-C862-4770-83B6-E2DDF260CC67} = {541C5347-5D7D-44B7-95D3-B6FB3D9EB955}
{BF6569A1-1A5A-4358-9C02-1A6A5F0FBFD9} = {71DDEE7B-E213-4E39-A7F4-4646783A27F7}
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890} = {541C5347-5D7D-44B7-95D3-B6FB3D9EB955}
{B2C3D4E5-F6A7-8901-BCDE-F12345678901} = {71DDEE7B-E213-4E39-A7F4-4646783A27F7}
{C853A9E3-C53D-4B1A-BFDA-228689A8C94C} = {71DDEE7B-E213-4E39-A7F4-4646783A27F7}
{75A4AEDA-0386-4B2D-9DBA-BC9AE733660E} = {71DDEE7B-E213-4E39-A7F4-4646783A27F7}
{0D40F7D6-3747-4280-8EB3-9F3A18AC1125} = {71DDEE7B-E213-4E39-A7F4-4646783A27F7}
Expand Down
12 changes: 12 additions & 0 deletions src/TaskManager/Plug-ins/Docker/DockerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,18 @@ private CreateContainerParameters BuildContainerSpecification(IList<ContainerVol
},
};

if (Event.TaskPluginArguments.ContainsKey(Keys.ShmSize))
{
if (long.TryParse(Event.TaskPluginArguments[Keys.ShmSize], out var shmsize))
{
parameters.HostConfig.ShmSize = shmsize;
}
else
{
_logger.InvalidShmSize(Event.TaskPluginArguments[Keys.ShmSize]);
}
Comment on lines +370 to +379

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Enforce positive shm_size bounds, not just numeric parsing.

At Line 372, long.TryParse accepts 0 and negative values, but your own log contract says valid range starts at 1. This currently allows invalid values to be forwarded into HostConfig.ShmSize instead of being rejected/logged.

Suggested fix
-            if (Event.TaskPluginArguments.ContainsKey(Keys.ShmSize))
-            {
-                if (long.TryParse(Event.TaskPluginArguments[Keys.ShmSize], out var shmsize))
-                {
-                    parameters.HostConfig.ShmSize = shmsize;
-                }
-                else
-                {
-                    _logger.InvalidShmSize(Event.TaskPluginArguments[Keys.ShmSize]);
-                }
-            }
+            if (Event.TaskPluginArguments.ContainsKey(Keys.ShmSize))
+            {
+                if (long.TryParse(Event.TaskPluginArguments[Keys.ShmSize], out var shmsize) && shmsize > 0)
+                {
+                    parameters.HostConfig.ShmSize = shmsize;
+                }
+                else
+                {
+                    _logger.InvalidShmSize(Event.TaskPluginArguments[Keys.ShmSize]);
+                }
+            }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (Event.TaskPluginArguments.ContainsKey(Keys.ShmSize))
{
if (long.TryParse(Event.TaskPluginArguments[Keys.ShmSize], out var shmsize))
{
parameters.HostConfig.ShmSize = shmsize;
}
else
{
_logger.InvalidShmSize(Event.TaskPluginArguments[Keys.ShmSize]);
}
if (Event.TaskPluginArguments.ContainsKey(Keys.ShmSize))
{
if (long.TryParse(Event.TaskPluginArguments[Keys.ShmSize], out var shmsize) && shmsize > 0)
{
parameters.HostConfig.ShmSize = shmsize;
}
else
{
_logger.InvalidShmSize(Event.TaskPluginArguments[Keys.ShmSize]);
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/TaskManager/Plug-ins/Docker/DockerPlugin.cs` around lines 370 - 379, The
code at the `long.TryParse` check in the ShmSize handling block accepts zero and
negative values without validation. Add an additional check after successful
parsing to ensure the parsed shmsize value is greater than 0 before assigning it
to parameters.HostConfig.ShmSize. If the parsed value is not positive (less than
or equal to 0), log the error using _logger.InvalidShmSize with the invalid
value and skip the assignment, ensuring only valid positive sizes are accepted.

}

if (Event.TaskPluginArguments.ContainsKey(Keys.User))
{
parameters.User = Event.TaskPluginArguments[Keys.User];
Expand Down
5 changes: 5 additions & 0 deletions src/TaskManager/Plug-ins/Docker/Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ internal static class Keys
/// </summary>
public static readonly string TemporaryStorageContainerPath = "temp_storage_container_path";

/// <summary>
/// Key for setting the shm size.
/// </summary>
public static readonly string ShmSize = "shm_size";

/// <summary>
/// Prefix for envrionment variables.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/TaskManager/Plug-ins/Docker/Logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,8 @@ public static partial class Log

[LoggerMessage(EventId = 1031, Level = LogLevel.Error, Message = "Error setting directory {path} with permission {user}.")]
public static partial void ErrorSettingDirectoryPermission(this ILogger logger, string path, string user);

[LoggerMessage(EventId = 1032, Level = LogLevel.Error, Message = "Invalid size specified for /dev/shm: {size}. Please use value between 1 and 9223372036854775807.")]
public static partial void InvalidShmSize(this ILogger logger, string size);
}
}
19 changes: 19 additions & 0 deletions src/TaskManager/Plug-ins/Podman/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2022 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Monai.Deploy.WorkflowManager.TaskManager.Podman.Tests")]
33 changes: 33 additions & 0 deletions src/TaskManager/Plug-ins/Podman/ContainerMonitorException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2022 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Monai.Deploy.WorkflowManager.TaskManager.Podman
{
internal class ContainerMonitorException : Exception
{
public ContainerMonitorException()
{
}

public ContainerMonitorException(string? message) : base(message)
{
}

public ContainerMonitorException(string? message, Exception? innerException) : base(message, innerException)
{
}
}
}
Loading
Loading