Skip to content

Ensure /run/containerd gets created with correct perms#10516

Merged
estesp merged 1 commit intocontainerd:mainfrom
etungsten:ensure-state-dir-perms
Jul 31, 2024
Merged

Ensure /run/containerd gets created with correct perms#10516
estesp merged 1 commit intocontainerd:mainfrom
etungsten:ensure-state-dir-perms

Conversation

@etungsten
Copy link
Contributor

@etungsten etungsten commented Jul 29, 2024

Issue: #10502 (specifically this comment about fixing the default state dir creation with expected perms 0711)

There are a couple directories that get created under the default
state directory ("/run/containerd") even when containerd is configured
to use a different location for its state directory. Create the default
state directory even if containerd is configured to use a different
state directory location. This ensure pkg/shim and pkg/fifo won't create
the default state directory with incorrect permissions when calling
os.MkdirAll for their respective subdirectories.

@k8s-ci-robot
Copy link

Hi @etungsten. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@samuelkarp
Copy link
Member

/ok-to-test

@etungsten
Copy link
Contributor Author

/retest

@estesp
Copy link
Member

estesp commented Jul 29, 2024

/test pull-containerd-node-e2e

@etungsten
Copy link
Contributor Author

Hmm, I'm having a hard time understanding how these changes would cause these test timeouts.

@etungsten etungsten force-pushed the ensure-state-dir-perms branch from 1f839f9 to 5a01677 Compare July 29, 2024 16:59
@etungsten
Copy link
Contributor Author

/retest

@etungsten etungsten requested a review from thaJeztah July 30, 2024 17:21
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

Looking at these changes in context though, I'm a bit on the fence if these locations are the right location for creating these directories; specifically the one in pkg/cio feels very out of place, but I'm a bit concerned about the general design to sprinkle some MkdirAll calls through the code; more so after looking that the CreateTopLevelDirectories is present to setup required paths as early as possible. Having such mechanisms centralised so that they're created, as early as possible, and that there's a canonical location on their permissions may be a good thing.

Looking at the linked ticket; #10502 the request

I am running multiple instances of the containerd daemon on my machine and each containerd instance has their own state directories. e.g. /run/containerd-foo and /run/containerd-bar, /run/containerd

Those locations (per above) should already be created when each of those instances starts up.

containerd-shim however creates the shim socket under the default state directory which is set to /run/containerd

This is the part that (IIUC) causes issues for you, because starting a containerd instance with /run/containerd-foo as state-dir, will still attempt to create sockets in /run/containerd. Also from that linked discussion it looks like that's currently not configurable (hence this PR). I'm slightly concerned though that we're tapering over the underlying issue (those paths not configurable and/or not tied to the actual state directory in use (/run/containerd-foo)).

I'm also interested to learn about this part of your request; i.e., is there a specific reason you must have the additional instances running before the "main" (for better words) instance?

This is an issue because I want some containerd daemon instances to start earlier than the regular containerd daemon

Given that (from all things above) it looks like "multiple instances" is still a partial implementation, but the code changes in this PR will affect standard setups, I'm wondering if (while the "custom path" implementation is not complete / fully fledged out), a different workaround would be more appropriate. Which could be (e.g.) a systemd unit / script to create the directories ahead of time (before any of the containerd instances is started).

An alternative could be to;

  • have CreateTopLevelDirectories unconditionally create /run/containerd regardless of the actually configured state directory
  • or have CreateTopLevelDirectories create /run/containerd if the configured State is non-standard

The latter one could be something like;

if config.State != defaults.DefaultStateDir {
	// FIXME: socket-paths in pkg/shim are hard-coded to the default location, so make sure this location is created.
	if err := sys.MkdirAllWithACL(config.State, 0o711); err != nil {
		return err
	}
}

It looks like taking that approach also makes sure that these directories are created with the same permissions and options as the default.

@etungsten
Copy link
Contributor Author

etungsten commented Jul 30, 2024

Having such mechanisms centralised so that they're created, as early as possible, and that there's a canonical location on their permissions may be a good thing.

I agree. I neglected to look at CreateTopLevelDirectories. I think moving it there makes sense.

I'm also interested to learn about this part of your request; i.e., is there a specific reason you must have the additional instances running before the "main" (for better words) instance?

I have some containers that I would like to run with different containerd plugins/configurations that's separate from the "main" containerd instance serving K8s workloads.

or have CreateTopLevelDirectories create /run/containerd if the configured State is non-standard

I'll update my changes with this approach. Thanks for the thoughtful review.

@etungsten etungsten force-pushed the ensure-state-dir-perms branch from 5a01677 to ed5d5e8 Compare July 30, 2024 21:22
@etungsten etungsten requested a review from thaJeztah July 30, 2024 21:24
@etungsten etungsten force-pushed the ensure-state-dir-perms branch from ed5d5e8 to 688b05f Compare July 30, 2024 22:33
There are a couple directories that get created under the default
state directory ("/run/containerd") even when containerd is configured
to use a different location for its state directory. Create the default
state directory even if containerd is configured to use a different
state directory location. This ensure pkg/shim and pkg/fifo won't create
the default state directory with incorrect permissions when calling
os.MkdirAll for their respective subdirectories.

Signed-off-by: Erikson Tung <[email protected]>
@etungsten etungsten force-pushed the ensure-state-dir-perms branch from 688b05f to 551ac06 Compare July 31, 2024 00:55
return err
}
if config.State != defaults.DefaultStateDir {
// XXX: socketRoot in pkg/shim is hard-coded to the default state directory.
Copy link
Member

Choose a reason for hiding this comment

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

I've never seen XXX before, but apparently it's an old Java convention.

(no action required here)

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@estesp estesp added this pull request to the merge queue Jul 31, 2024
@estesp estesp added cherry-pick/1.6.x cherry-pick/1.7.x Change to be cherry picked to release/1.7 branch labels Jul 31, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 31, 2024
@estesp estesp added this pull request to the merge queue Jul 31, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 31, 2024
@estesp estesp added this pull request to the merge queue Jul 31, 2024
Merged via the queue into containerd:main with commit 7a80448 Jul 31, 2024
@etungsten etungsten deleted the ensure-state-dir-perms branch July 31, 2024 16:04
@samuelkarp
Copy link
Member

/cherrypick release/1.7

@k8s-infra-cherrypick-robot

@samuelkarp: new pull request created: #10534

Details

In response to this:

/cherrypick release/1.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@samuelkarp
Copy link
Member

/cherrypick release/1.6

@k8s-infra-cherrypick-robot

@samuelkarp: new pull request created: #10535

Details

In response to this:

/cherrypick release/1.6

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@samuelkarp samuelkarp added cherry-picked/1.6.x PR commits are cherry-picked into release/1.6 branch cherry-picked/1.7.x PR commits are cherry-picked into release/1.7 branch and removed cherry-pick/1.6.x cherry-pick/1.7.x Change to be cherry picked to release/1.7 branch labels Jul 31, 2024
@samuelkarp samuelkarp changed the title Ensure /run/containerd gets created with correct perms Ensure /run/containerd gets created with correct perms Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/runtime Runtime cherry-picked/1.6.x PR commits are cherry-picked into release/1.6 branch cherry-picked/1.7.x PR commits are cherry-picked into release/1.7 branch kind/bug ok-to-test size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants