Skip to content
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

DBUS API required for GNOI Containerz.StartContainer #182

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

hdwhdw
Copy link
Contributor

@hdwhdw hdwhdw commented Nov 7, 2024

DBUS API required for GNOI Containerz.StartContainer. The PR contains the following:

  1. Add a function run to DBUS docker service.
  2. Use the allowed_container list to verify whether an image is allowed to be run.

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@hdwhdw
Copy link
Contributor Author

hdwhdw commented Nov 7, 2024

Not like this

@hdwhdw hdwhdw closed this Nov 7, 2024
@hdwhdw hdwhdw reopened this Nov 7, 2024
Copy link

linux-foundation-easycla bot commented Dec 11, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@hdwhdw
Copy link
Contributor Author

hdwhdw commented Dec 11, 2024

Force push to reset author

@hdwhdw hdwhdw marked this pull request as ready for review December 11, 2024 05:15
@hdwhdw hdwhdw requested a review from Copilot December 11, 2024 05:15

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.

Comments skipped due to low confidence (2)

host_modules/docker_service.py:200

  • The error message should use the 'image' variable instead of 'container'.
return 1, "Failed to run container {}: {}".format(image, str(e))

host_modules/docker_service.py:190

  • The error message should specify that the command must be an empty string.
return errno.EPERM, "Only empty command is allowed to be managed by this service."
@hdwhdw hdwhdw requested a review from Copilot December 11, 2024 05:23

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.

Comments skipped due to low confidence (1)

host_modules/docker_service.py:190

  • [nitpick] The error message could be more descriptive. Consider rephrasing it to: "Only an empty string command is allowed. Non-empty commands are not permitted by this service."
return errno.EPERM, "Only empty string command is allowed to be managed by this service."
@hdwhdw hdwhdw requested a review from Copilot December 11, 2024 05:50

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.

Comments skipped due to low confidence (1)

tests/host_modules/docker_service_test.py:281

  • The command should be an empty string to correctly test the image not allowed scenario.
rc, msg = docker_service.run("wrong_image_name", "command", {})
@hdwhdw hdwhdw requested a review from Copilot December 11, 2024 05:57

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.

bool: True if the image is allowed, False otherwise.
"""
image_name = image.split(":")[0] # Remove tag if present
for allowed_image, _ in ALLOWED_CONTAINERS:
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @hdwhdw for the work! Could you add more description for the PR? Seems we need to maintain the container list, which I have one new container "docker-sonic-bmp" added.

Copy link
Contributor Author

@hdwhdw hdwhdw Dec 12, 2024

Choose a reason for hiding this comment

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

Thanks for the review. Added more description to the PR. There could be better solution to this but currently I just hardcoded a set of all allowed container images. As for solution, I could say put a gnoi.json that contains a white list in /etc/sonic, so we don't need to push an upgrade to allowed one more container image. That will be done in another PR.

Copy link
Contributor

@FengPan-Frank FengPan-Frank Dec 13, 2024

Choose a reason for hiding this comment

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

could you help to contain bmp first? pls refer below
image

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

# The set of allowed images that can be managed by this service.
ALLOWED_IMAGES = {
"docker-syncd-brcm",
"docker-syncd-cisco"
Copy link
Contributor

Choose a reason for hiding this comment

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

"

missing trailing comma?

@xincunli-sonic
Copy link
Contributor

def stop(self, container):

The stop, kill, and restart methods have repetitive code for fetching the container and checking if it is allowed. This could be refactored into a helper function to improve readability and maintainability.


Refers to: host_modules/docker_service.py:85 in 68cf038. [](commit_id = 68cf038, deletion_comment = False)

@xincunli-sonic
Copy link
Contributor

        return 0, "Container {} has been stopped.".format(container.name)

The code uses return statements to indicate success or failure, but it would benefit from logging critical operations (e.g., container stop/restart, errors) at appropriate levels (INFO/WARN/ERROR). This would make debugging and monitoring easier.


Refers to: host_modules/docker_service.py:106 in 68cf038. [](commit_id = 68cf038, deletion_comment = False)

@host_service.method(
host_service.bus_name(MOD_NAME), in_signature="ssa{sv}", out_signature="is"
)
def run(self, image, command, kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

kwargs

This method allows passing kwargs directly to docker.containers.run. This could lead to potential security issues if not properly validated. Consider sanitizing or restricting the kwargs that can be passed to ensure they don't introduce vulnerabilities (e.g., privileged containers or host mounts).

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.

4 participants