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

feat: add cap_add and cap_drop support #726

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nicmr
Copy link
Contributor

@nicmr nicmr commented Aug 30, 2024

Hi 👋 This PR implements #578 and adds tests for the added functionality.
Specifically, this PR adds support for adding and dropping capabilities for containers.
Have a nice weekend!

Copy link

netlify bot commented Aug 30, 2024

Deploy Preview for testcontainers-rust ready!

Name Link
🔨 Latest commit 7c85132
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-rust/deploys/66d221bf5654c80008047d6e
😎 Deploy Preview https://deploy-preview-726--testcontainers-rust.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@DDtKey DDtKey changed the title feat: add cap_add and cap_drop to ContainerRequest, ImageExt feat: add cap_add and cap_drop support Aug 30, 2024
Copy link
Collaborator

@DDtKey DDtKey left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! 🙏

Comment on lines +215 to +223
fn with_cap_add(self, capabilities: impl IntoIterator<Item = String>) -> ContainerRequest<I> {
let mut container_req = self.into();
container_req
.cap_add
.get_or_insert_with(Vec::new)
.extend(capabilities);

container_req
}
Copy link
Collaborator

@DDtKey DDtKey Aug 30, 2024

Choose a reason for hiding this comment

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

In general, I'm not sure we need the "extend" semantic. We don't use it for other methods and it might be less expected.
I think it's acceptable to replace if method called again (and perhaps more obvious)

It's possible to get current capabilities, extend and override If users will need to "add" them 🤔

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point. With some with_ functions we do have the additive semantic of extend though, e.g. mounts and environment variables (with the difference that the newly added functions currently support adding multiple values at once instead of one by one, hence the extend instead of push/insert).
Intuitively, I would say it could be the least surprising to the user if it maps to how the docker CLI handles it, since most users are likely to be familiar with it.

  • Is it possible to specify the flag multiple times to combine the permissions additively? If yes, extend, if not, replace.
  • Is it possible to add/drop multiple permissions with a single instance of the flag? If yes, take impl IntoIter<Item = String>, if not, take String.
    What do you think of that approach?
    Of course I can also add documentation for this behaviour to the functions, regardless of the implementation we go with

Copy link
Collaborator

@DDtKey DDtKey Aug 31, 2024

Choose a reason for hiding this comment

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

Yeah, that’s all good points.
Only with_cmd actually overwrites the list (and it generally makes sense, I wanted it to be aligned with docker api - additive cmd would be weird, the list is a single value in that case).

AFAIR docker accepts 1 value per flag for cap-add/drop, but they are additive for sure.

So we can go with the way how we expose ENV variables and mounts 🤔 Also, I guess it’s common case when only 1 capability is needed. And we can extend it on demand in general

Correct me if I’m wrong

Copy link
Collaborator

@DDtKey DDtKey Sep 14, 2024

Choose a reason for hiding this comment

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

Hi @nicmr 👋

Let me know if you can’t (or don’t want to) finalize this last thing, please 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I was on vacation, I'm going to finalize it this week. Thank you for your patience!

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.

2 participants