Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Add RunAsGroup support.
Browse files Browse the repository at this point in the history
Signed-off-by: Lantao Liu <[email protected]>
  • Loading branch information
Random-Liu committed Mar 30, 2018
1 parent f99f0be commit ae0ed2f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/server/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package server

import (
gocontext "context"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -225,6 +226,18 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
if username := securityContext.GetRunAsUsername(); username != "" {
specOpts = append(specOpts, oci.WithUsername(username))
}
if gid := securityContext.GetRunAsGroup(); gid != nil {
if securityContext.GetRunAsUser() == nil || securityContext.GetRunAsUsername() == "" {
return nil, errors.New("user group is specified without user")
}
// TODO(random-liu): Add WithGroupID in containerd client.
specOpts = append(specOpts,
func(_ gocontext.Context, _ oci.Client, _ *containers.Container, s *runtimespec.Spec) error {
s.Process.User.GID = uint32(gid.GetValue())
return nil
},
)
}

apparmorSpecOpts, err := generateApparmorSpecOpts(
securityContext.GetApparmorProfile(),
Expand Down
14 changes: 14 additions & 0 deletions pkg/server/sandbox_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ limitations under the License.
package server

import (
gocontext "context"
"fmt"
"os"
"strings"

"github.com/containerd/containerd"
containerdio "github.com/containerd/containerd/cio"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/linux/runctypes"
"github.com/containerd/containerd/oci"
Expand Down Expand Up @@ -148,6 +150,18 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
if uid := securityContext.GetRunAsUser(); uid != nil {
specOpts = append(specOpts, oci.WithUserID(uint32(uid.GetValue())))
}
if gid := securityContext.GetRunAsGroup(); gid != nil {
if securityContext.GetRunAsUser() == nil {
return nil, errors.New("user group is specified without user")
}
// TODO(random-liu): Add WithGroupID in containerd client.
specOpts = append(specOpts,
func(_ gocontext.Context, _ oci.Client, _ *containers.Container, s *runtimespec.Spec) error {
s.Process.User.GID = uint32(gid.GetValue())
return nil
},
)
}

seccompSpecOpts, err := generateSeccompSpecOpts(
securityContext.GetSeccompProfilePath(),
Expand Down

0 comments on commit ae0ed2f

Please sign in to comment.