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

bugfix: container can not write cgroup with privileged #2552

Merged
merged 1 commit into from
Dec 13, 2018
Merged

bugfix: container can not write cgroup with privileged #2552

merged 1 commit into from
Dec 13, 2018

Conversation

Ace-Tang
Copy link
Contributor

@Ace-Tang Ace-Tang commented Dec 12, 2018

clear ro in mount option when container get privileged, make cgroup
writable, add test for it.

Signed-off-by: Ace-Tang aceapril@126.com

Ⅰ. Describe what this PR did

Ⅱ. Does this pull request fix one issue?

fixes #2553

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

add test.

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov
Copy link

codecov bot commented Dec 12, 2018

Codecov Report

Merging #2552 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2552      +/-   ##
==========================================
+ Coverage   69.03%   69.13%   +0.09%     
==========================================
  Files         278      278              
  Lines       18581    18582       +1     
==========================================
+ Hits        12828    12847      +19     
+ Misses       4272     4264       -8     
+ Partials     1481     1471      -10
Flag Coverage Δ
#criv1alpha1test 31.23% <100%> (-0.04%) ⬇️
#criv1alpha2test 35.57% <100%> (+0.11%) ⬆️
#integrationtest 40.64% <100%> (+0.07%) ⬆️
#nodee2etest 32.66% <100%> (+0.18%) ⬆️
#unittest 26.79% <0%> (-0.01%) ⬇️
Impacted Files Coverage Δ
daemon/mgr/spec_mount.go 84.4% <100%> (+0.14%) ⬆️
apis/server/utils.go 71.15% <0%> (-3.85%) ⬇️
daemon/logger/jsonfile/utils.go 71.54% <0%> (-1.63%) ⬇️
daemon/mgr/container.go 58.44% <0%> (-0.43%) ⬇️
cri/v1alpha1/cri.go 60.59% <0%> (-0.34%) ⬇️
ctrd/container.go 58.81% <0%> (+0.39%) ⬆️
cri/v1alpha2/cri.go 68.83% <0%> (+1.1%) ⬆️
pkg/streams/utils.go 91.66% <0%> (+2.38%) ⬆️
cri/v1alpha2/cri_wrapper.go 65.59% <0%> (+2.39%) ⬆️
daemon/mgr/snapshot.go 94.2% <0%> (+4.34%) ⬆️
... and 1 more

res := command.PouchRun("run", "--name", name1, busyboxImage, "sh", "-c", "mkdir /sys/fs/cgroup/cpu/test")
defer DelContainerForceMultyTime(c, name1)

if res.ExitCode == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

The if condition is duplicated with c.Assert(util.PartialEqual(res.Combined(), "Read-only file system"), check.IsNil) . I think that we can remove the if condition. 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.

Copy from other test in test/cli_run_with_privileged_test.go, author may think error stdout is not enough to judge error, I agree with he. But I do not mind to remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you do not mind, I will do this in next pr, and fix all tests in test/cli_run_with_privileged_test.go

Copy link
Contributor

Choose a reason for hiding this comment

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

sure

@rudyfly
Copy link
Collaborator

rudyfly commented Dec 12, 2018

I think we must refact the function setupMounts, there are a lot of unuse for loop. As your modify, can we change it like this:
before

	if c.HostConfig.Privileged {
		if !s.Root.Readonly {
			// Clear readonly for /sys.
			for i := range s.Mounts {
				if s.Mounts[i].Destination == "/sys" {
					clearReadonly(&s.Mounts[i])
				}
			}
		}
		// Clear readonly for cgroup
		for i := range s.Mounts {
			if s.Mounts[i].Type == "cgroup" {
				clearReadonly(&s.Mounts[i])
			}
		}
	}

change it:

	if c.HostConfig.Privileged {
		for i := range s.Mounts {
			// Clear readonly for /sys.
			if s.Mounts[i].Destination == "/sys" && !s.Root.Readonly {
				clearReadonly(&s.Mounts[i])
			}

			// Clear readonly for cgroup
			if s.Mounts[i].Type == "cgroup" {
				clearReadonly(&s.Mounts[i])
			}
		}
	}

As the same reason, we also can merge this for loop with above code. Can you refact this function?
@Ace-Tang

Copy link
Collaborator

@rudyfly rudyfly left a comment

Choose a reason for hiding this comment

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

Need to merge unuse for loop.

clear ro in mount option when container get privileged, make cgroup
writable, add test for it.

Signed-off-by: Ace-Tang <aceapril@126.com>
@Ace-Tang
Copy link
Contributor Author

@rudyfly , updated

Copy link
Collaborator

@rudyfly rudyfly left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

@fuweid fuweid merged commit fe8bd4a into AliyunContainerService:master Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This is bug report for project size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cgroup fs in pouch container is mounted and read-only forcely
4 participants