Skip to content

Commit e042f84

Browse files
committed
Remove mountLabel
Signed-off-by: Ayato Tokubi <[email protected]>
1 parent 52b8192 commit e042f84

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

server/container_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr container.Conta
837837
}
838838
}()
839839

840-
containerVolumes, ociMounts, safeMounts, err := s.addOCIBindMounts(ctx, ctr, mountLabel, maybeRelabel, skipRelabel, cgroup2RW, idMapSupport, rroSupport, s.ContainerServer.Config().Root, containerInfo.RunDir)
840+
containerVolumes, ociMounts, safeMounts, err := s.addOCIBindMounts(ctx, ctr, &containerInfo, maybeRelabel, skipRelabel, cgroup2RW, idMapSupport, rroSupport, s.ContainerServer.Config().Root, containerInfo.RunDir)
841841
if err != nil {
842842
return nil, err
843843
}

server/container_create_linux.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/cri-o/cri-o/internal/log"
2929
"github.com/cri-o/cri-o/internal/oci"
3030
"github.com/cri-o/cri-o/internal/ociartifact"
31+
"github.com/cri-o/cri-o/internal/storage"
3132
crioann "github.com/cri-o/cri-o/pkg/annotations"
3233
)
3334

@@ -146,7 +147,7 @@ func clearReadOnly(m *rspec.Mount) {
146147
m.Options = append(m.Options, "rw")
147148
}
148149

149-
func (s *Server) addOCIBindMounts(ctx context.Context, ctr ctrfactory.Container, mountLabel string, maybeRelabel, skipRelabel, cgroup2RW, idMapSupport, rroSupport bool, storageRoot, runDir string) ([]oci.ContainerVolume, []rspec.Mount, []*safeMountInfo, error) {
150+
func (s *Server) addOCIBindMounts(ctx context.Context, ctr ctrfactory.Container, ctrInfo *storage.ContainerInfo, maybeRelabel, skipRelabel, cgroup2RW, idMapSupport, rroSupport bool, storageRoot, runDir string) ([]oci.ContainerVolume, []rspec.Mount, []*safeMountInfo, error) {
150151
ctx, span := log.StartSpan(ctx)
151152
defer span.End()
152153

@@ -212,7 +213,7 @@ func (s *Server) addOCIBindMounts(ctx context.Context, ctr ctrfactory.Container,
212213
if m.GetImage().GetImage() != "" {
213214
if s.config.OCIArtifactMountSupport {
214215
// Try mountArtifact first, and fall back to mountImage if it fails with ErrNotFound
215-
artifactVolumes, err := s.mountArtifact(ctx, specgen, m, mountLabel, skipRelabel, maybeRelabel)
216+
artifactVolumes, err := s.mountArtifact(ctx, specgen, m, ctrInfo.MountLabel, skipRelabel, maybeRelabel)
216217
if err == nil {
217218
volumes = append(volumes, artifactVolumes...)
218219

@@ -355,7 +356,7 @@ func (s *Server) addOCIBindMounts(ctx context.Context, ctr ctrfactory.Container,
355356
if m.SelinuxRelabel {
356357
if skipRelabel {
357358
log.Debugf(ctx, "Skipping relabel for %s because of super privileged container (type: spc_t)", src)
358-
} else if err := securityLabel(src, mountLabel, false, maybeRelabel); err != nil {
359+
} else if err := securityLabel(src, ctrInfo.MountLabel, false, maybeRelabel); err != nil {
359360
return nil, nil, nil, err
360361
}
361362
} else {

server/container_create_linux_test.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package server
22

33
import (
4+
"github.com/cri-o/cri-o/internal/storage"
45
"testing"
56

67
types "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -33,8 +34,11 @@ func TestAddOCIBindsForDev(t *testing.T) {
3334
}
3435

3536
sut := &Server{}
37+
ctrInfo := &storage.ContainerInfo{
38+
MountLabel: "",
39+
}
3640

37-
_, binds, _, err := sut.addOCIBindMounts(t.Context(), ctr, "", false, false, false, false, false, "", "")
41+
_, binds, _, err := sut.addOCIBindMounts(t.Context(), ctr, ctrInfo, false, false, false, false, false, "", "")
3842
if err != nil {
3943
t.Error(err)
4044
}
@@ -85,8 +89,11 @@ func TestAddOCIBindsForSys(t *testing.T) {
8589
}
8690

8791
sut := &Server{}
92+
ctrInfo := &storage.ContainerInfo{
93+
MountLabel: "",
94+
}
8895

89-
_, binds, _, err := sut.addOCIBindMounts(t.Context(), ctr, "", false, false, false, false, false, "", "")
96+
_, binds, _, err := sut.addOCIBindMounts(t.Context(), ctr, ctrInfo, false, false, false, false, false, "", "")
9097
if err != nil {
9198
t.Error(err)
9299
}
@@ -139,8 +146,11 @@ func TestAddOCIBindsRROMounts(t *testing.T) {
139146
ctx := t.Context()
140147

141148
sut := &Server{}
149+
ctrInfo := &storage.ContainerInfo{
150+
MountLabel: "",
151+
}
142152

143-
_, binds, _, err := sut.addOCIBindMounts(ctx, ctr, "", false, false, false, false, true, "", "")
153+
_, binds, _, err := sut.addOCIBindMounts(ctx, ctr, ctrInfo, false, false, false, false, true, "", "")
144154
if err != nil {
145155
t.Errorf("Should not fail to create RRO mount, got: %v", err)
146156
}
@@ -237,8 +247,11 @@ func TestAddOCIBindsRROMountsError(t *testing.T) {
237247
}
238248

239249
sut := &Server{}
250+
ctrInfo := &storage.ContainerInfo{
251+
MountLabel: "",
252+
}
240253

241-
_, _, _, err = sut.addOCIBindMounts(ctx, ctr, "", false, false, false, false, tc.rroSupport, "", "")
254+
_, _, _, err = sut.addOCIBindMounts(ctx, ctr, ctrInfo, false, false, false, false, tc.rroSupport, "", "")
242255
if err == nil {
243256
t.Error("Should fail to add an RRO mount with a specific error")
244257
}
@@ -269,9 +282,12 @@ func TestAddOCIBindsCGroupRW(t *testing.T) {
269282
}
270283

271284
sut := &Server{}
285+
ctrInfo := &storage.ContainerInfo{
286+
MountLabel: "",
287+
}
272288

273289
//nolint: dogsled
274-
_, _, _, err = sut.addOCIBindMounts(t.Context(), ctr, "", false, false, true, false, false, "", "")
290+
_, _, _, err = sut.addOCIBindMounts(t.Context(), ctr, ctrInfo, false, false, true, false, false, "", "")
275291
if err != nil {
276292
t.Error(err)
277293
}
@@ -312,7 +328,7 @@ func TestAddOCIBindsCGroupRW(t *testing.T) {
312328
var hasCgroupRO bool
313329

314330
//nolint: dogsled
315-
_, _, _, err = sut.addOCIBindMounts(t.Context(), ctr, "", false, false, false, false, false, "", "")
331+
_, _, _, err = sut.addOCIBindMounts(t.Context(), ctr, ctrInfo, false, false, false, false, false, "", "")
316332
if err != nil {
317333
t.Error(err)
318334
}
@@ -364,15 +380,18 @@ func TestAddOCIBindsErrorWithoutIDMap(t *testing.T) {
364380
}
365381

366382
sut := &Server{}
383+
ctrInfo := &storage.ContainerInfo{
384+
MountLabel: "",
385+
}
367386

368387
//nolint: dogsled
369-
_, _, _, err = sut.addOCIBindMounts(t.Context(), ctr, "", false, false, false, false, false, "", "")
388+
_, _, _, err = sut.addOCIBindMounts(t.Context(), ctr, ctrInfo, false, false, false, false, false, "", "")
370389
if err == nil {
371390
t.Errorf("Should have failed to create id mapped mount with no id map support")
372391
}
373392

374393
//nolint: dogsled
375-
_, _, _, err = sut.addOCIBindMounts(t.Context(), ctr, "", false, false, false, true, false, "", "")
394+
_, _, _, err = sut.addOCIBindMounts(t.Context(), ctr, ctrInfo, false, false, false, true, false, "", "")
376395
if err != nil {
377396
t.Errorf("%v", err)
378397
}

0 commit comments

Comments
 (0)