Skip to content

Commit

Permalink
Remove all references to types.UnixUserID and types.UnixGroupID
Browse files Browse the repository at this point in the history
  • Loading branch information
mbohlool committed Jun 21, 2017
1 parent 9139666 commit c91a12d
Show file tree
Hide file tree
Showing 80 changed files with 247 additions and 315 deletions.
8 changes: 4 additions & 4 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,7 @@ type PodSecurityContext struct {
// PodSecurityContext, the value specified in SecurityContext takes precedence
// for that container.
// +optional
RunAsUser *types.UnixUserID
RunAsUser *int64
// Indicates that the container must run as a non-root user.
// If true, the Kubelet will validate the image at runtime to ensure that it
// does not run as UID 0 (root) and fail to start the container if it does.
Expand All @@ -2276,7 +2276,7 @@ type PodSecurityContext struct {
// to the container's primary GID. If unspecified, no groups will be added to
// any container.
// +optional
SupplementalGroups []types.UnixGroupID
SupplementalGroups []int64
// A special supplemental group that applies to all containers in a pod.
// Some volume types allow the Kubelet to change the ownership of that volume
// to be owned by the pod:
Expand All @@ -2287,7 +2287,7 @@ type PodSecurityContext struct {
//
// If unset, the Kubelet will not modify the ownership and permissions of any volume.
// +optional
FSGroup *types.UnixGroupID
FSGroup *int64
}

// PodQOSClass defines the supported qos classes of Pods.
Expand Down Expand Up @@ -3924,7 +3924,7 @@ type SecurityContext struct {
// May also be set in PodSecurityContext. If set in both SecurityContext and
// PodSecurityContext, the value specified in SecurityContext takes precedence.
// +optional
RunAsUser *types.UnixUserID
RunAsUser *int64
// Indicates that the container must run as a non-root user.
// If true, the Kubelet will validate the image at runtime to ensure that it
// does not run as UID 0 (root) and fail to start the container if it does.
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,7 @@ type PodSecurityContext struct {
// PodSecurityContext, the value specified in SecurityContext takes precedence
// for that container.
// +optional
RunAsUser *types.UnixUserID `json:"runAsUser,omitempty" protobuf:"varint,2,opt,name=runAsUser,casttype=k8s.io/apimachinery/pkg/types.UnixUserID"`
RunAsUser *int64 `json:"runAsUser,omitempty" protobuf:"varint,2,opt,name=runAsUser"`
// Indicates that the container must run as a non-root user.
// If true, the Kubelet will validate the image at runtime to ensure that it
// does not run as UID 0 (root) and fail to start the container if it does.
Expand All @@ -2561,7 +2561,7 @@ type PodSecurityContext struct {
// to the container's primary GID. If unspecified, no groups will be added to
// any container.
// +optional
SupplementalGroups []types.UnixGroupID `json:"supplementalGroups,omitempty" protobuf:"varint,4,rep,name=supplementalGroups,casttype=k8s.io/apimachinery/pkg/types.UnixGroupID"`
SupplementalGroups []int64 `json:"supplementalGroups,omitempty" protobuf:"varint,4,rep,name=supplementalGroups"`
// A special supplemental group that applies to all containers in a pod.
// Some volume types allow the Kubelet to change the ownership of that volume
// to be owned by the pod:
Expand All @@ -2572,7 +2572,7 @@ type PodSecurityContext struct {
//
// If unset, the Kubelet will not modify the ownership and permissions of any volume.
// +optional
FSGroup *types.UnixGroupID `json:"fsGroup,omitempty" protobuf:"varint,5,opt,name=fsGroup,casttype=k8s.io/apimachinery/pkg/types.UnixGroupID"`
FSGroup *int64 `json:"fsGroup,omitempty" protobuf:"varint,5,opt,name=fsGroup"`
}

// PodQOSClass defines the supported qos classes of Pods.
Expand Down Expand Up @@ -4511,7 +4511,7 @@ type SecurityContext struct {
// May also be set in PodSecurityContext. If set in both SecurityContext and
// PodSecurityContext, the value specified in SecurityContext takes precedence.
// +optional
RunAsUser *types.UnixUserID `json:"runAsUser,omitempty" protobuf:"varint,4,opt,name=runAsUser,casttype=k8s.io/apimachinery/pkg/types.UnixUserID"`
RunAsUser *int64 `json:"runAsUser,omitempty" protobuf:"varint,4,opt,name=runAsUser"`
// Indicates that the container must run as a non-root user.
// If true, the Kubelet will validate the image at runtime to ensure that it
// does not run as UID 0 (root) and fail to start the container if it does.
Expand Down
29 changes: 14 additions & 15 deletions pkg/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field"
Expand Down Expand Up @@ -3612,10 +3611,10 @@ func TestValidatePodSpec(t *testing.T) {
activeDeadlineSeconds := int64(30)
activeDeadlineSecondsMax := int64(math.MaxInt32)

minUserID := types.UnixUserID(0)
maxUserID := types.UnixUserID(2147483647)
minGroupID := types.UnixGroupID(0)
maxGroupID := types.UnixGroupID(2147483647)
minUserID := int64(0)
maxUserID := int64(2147483647)
minGroupID := int64(0)
maxGroupID := int64(2147483647)

successCases := []api.PodSpec{
{ // Populate basic fields, leave defaults for most.
Expand Down Expand Up @@ -3670,7 +3669,7 @@ func TestValidatePodSpec(t *testing.T) {
{ // Populate RunAsUser SupplementalGroups FSGroup with minID 0
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}},
SecurityContext: &api.PodSecurityContext{
SupplementalGroups: []types.UnixGroupID{minGroupID},
SupplementalGroups: []int64{minGroupID},
RunAsUser: &minUserID,
FSGroup: &minGroupID,
},
Expand All @@ -3680,7 +3679,7 @@ func TestValidatePodSpec(t *testing.T) {
{ // Populate RunAsUser SupplementalGroups FSGroup with maxID 2147483647
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}},
SecurityContext: &api.PodSecurityContext{
SupplementalGroups: []types.UnixGroupID{maxGroupID},
SupplementalGroups: []int64{maxGroupID},
RunAsUser: &maxUserID,
FSGroup: &maxGroupID,
},
Expand Down Expand Up @@ -3735,10 +3734,10 @@ func TestValidatePodSpec(t *testing.T) {
activeDeadlineSeconds = int64(0)
activeDeadlineSecondsTooLarge := int64(math.MaxInt32 + 1)

minUserID = types.UnixUserID(-1)
maxUserID = types.UnixUserID(2147483648)
minGroupID = types.UnixGroupID(-1)
maxGroupID = types.UnixGroupID(2147483648)
minUserID = int64(-1)
maxUserID = int64(2147483648)
minGroupID = int64(-1)
maxGroupID = int64(2147483648)

failureCases := map[string]api.PodSpec{
"bad volume": {
Expand Down Expand Up @@ -3812,7 +3811,7 @@ func TestValidatePodSpec(t *testing.T) {
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}},
SecurityContext: &api.PodSecurityContext{
HostNetwork: false,
SupplementalGroups: []types.UnixGroupID{maxGroupID, 1234},
SupplementalGroups: []int64{maxGroupID, 1234},
},
RestartPolicy: api.RestartPolicyAlways,
DNSPolicy: api.DNSClusterFirst,
Expand All @@ -3821,7 +3820,7 @@ func TestValidatePodSpec(t *testing.T) {
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}},
SecurityContext: &api.PodSecurityContext{
HostNetwork: false,
SupplementalGroups: []types.UnixGroupID{minGroupID, 1234},
SupplementalGroups: []int64{minGroupID, 1234},
},
RestartPolicy: api.RestartPolicyAlways,
DNSPolicy: api.DNSClusterFirst,
Expand Down Expand Up @@ -9582,7 +9581,7 @@ func TestValidateTLSSecret(t *testing.T) {

func TestValidateSecurityContext(t *testing.T) {
priv := false
runAsUser := types.UnixUserID(1)
runAsUser := int64(1)
fullValidSC := func() *api.SecurityContext {
return &api.SecurityContext{
Privileged: &priv,
Expand Down Expand Up @@ -9634,7 +9633,7 @@ func TestValidateSecurityContext(t *testing.T) {
privRequestWithGlobalDeny.Privileged = &requestPrivileged

negativeRunAsUser := fullValidSC()
negativeUser := types.UnixUserID(-1)
negativeUser := int64(-1)
negativeRunAsUser.RunAsUser = &negativeUser

errorCases := map[string]struct {
Expand Down
9 changes: 4 additions & 5 deletions pkg/apis/extensions/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ package extensions
import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/kubernetes/pkg/api"
)
Expand Down Expand Up @@ -980,17 +979,17 @@ type RunAsUserStrategyOptions struct {
// UserIDRange provides a min/max of an allowed range of UserIDs.
type UserIDRange struct {
// Min is the start of the range, inclusive.
Min types.UnixUserID
Min int64
// Max is the end of the range, inclusive.
Max types.UnixUserID
Max int64
}

// GroupIDRange provides a min/max of an allowed range of GroupIDs.
type GroupIDRange struct {
// Min is the start of the range, inclusive.
Min types.UnixGroupID
Min int64
// Max is the end of the range, inclusive.
Max types.UnixGroupID
Max int64
}

// RunAsUserStrategy denotes strategy types for generating RunAsUser values for a
Expand Down
11 changes: 5 additions & 6 deletions pkg/kubelet/dockershim/securitycontext/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ import (
"testing"

dockercontainer "github.com/docker/engine-api/types/container"
"k8s.io/apimachinery/pkg/types"
apitesting "k8s.io/kubernetes/pkg/api/testing"
"k8s.io/kubernetes/pkg/api/v1"
)

func TestModifyContainerConfig(t *testing.T) {
userID := types.UnixUserID(123)
overrideUserID := types.UnixUserID(321)
userID := int64(123)
overrideUserID := int64(321)

cases := []struct {
name string
Expand Down Expand Up @@ -177,7 +176,7 @@ func TestModifyHostConfig(t *testing.T) {

func TestModifyHostConfigPodSecurityContext(t *testing.T) {
supplementalGroupsSC := &v1.PodSecurityContext{}
supplementalGroupsSC.SupplementalGroups = []types.UnixGroupID{2222}
supplementalGroupsSC.SupplementalGroups = []int64{2222}
supplementalGroupHC := fullValidHostConfig()
supplementalGroupHC.GroupAdd = []string{"2222"}
fsGroupHC := fullValidHostConfig()
Expand All @@ -186,7 +185,7 @@ func TestModifyHostConfigPodSecurityContext(t *testing.T) {
extraSupplementalGroupHC.GroupAdd = []string{"1234"}
bothHC := fullValidHostConfig()
bothHC.GroupAdd = []string{"2222", "1234"}
fsGroup := types.UnixGroupID(1234)
fsGroup := int64(1234)
extraSupplementalGroup := []int64{1234}

testCases := map[string]struct {
Expand All @@ -211,7 +210,7 @@ func TestModifyHostConfigPodSecurityContext(t *testing.T) {
},
"FSGroup + SupplementalGroups": {
securityContext: &v1.PodSecurityContext{
SupplementalGroups: []types.UnixGroupID{2222},
SupplementalGroups: []int64{2222},
FSGroup: &fsGroup,
},
expected: bothHC,
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/kubelet_volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,10 @@ func (f *stubVolume) CanMount() error {
return nil
}

func (f *stubVolume) SetUp(fsGroup *types.UnixGroupID) error {
func (f *stubVolume) SetUp(fsGroup *int64) error {
return nil
}

func (f *stubVolume) SetUpAt(dir string, fsGroup *types.UnixGroupID) error {
func (f *stubVolume) SetUpAt(dir string, fsGroup *int64) error {
return nil
}
3 changes: 1 addition & 2 deletions pkg/kubelet/kuberuntime/kuberuntime_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/api/v1"
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
Expand Down Expand Up @@ -227,7 +226,7 @@ func TestGenerateContainerConfig(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, expectedConfig, containerConfig, "generate container config for kubelet runtime v1.")

runAsUser := types.UnixUserID(0)
runAsUser := int64(0)
runAsNonRootTrue := true
podWithContainerSecurityContext := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubelet/kuberuntime/security_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package kuberuntime

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/api/v1"

"github.com/stretchr/testify/assert"
Expand All @@ -45,7 +44,7 @@ func TestVerifyRunAsNonRoot(t *testing.T) {
},
}

rootUser := types.UnixUserID(0)
rootUser := int64(0)
runAsNonRootTrue := true
runAsNonRootFalse := false
imageRootUser := int64(0)
Expand Down
18 changes: 9 additions & 9 deletions pkg/kubelet/rkt/rkt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,10 +983,10 @@ func TestSetApp(t *testing.T) {
}
defer os.RemoveAll(tmpDir)

rootUser := kubetypes.UnixUserID(0)
nonRootUser := kubetypes.UnixUserID(42)
rootUser := int64(0)
nonRootUser := int64(42)
runAsNonRootTrue := true
fsgid := kubetypes.UnixGroupID(3)
fsgid := int64(3)

tests := []struct {
container *v1.Container
Expand Down Expand Up @@ -1092,9 +1092,9 @@ func TestSetApp(t *testing.T) {
RunAsNonRoot: &runAsNonRootTrue,
},
podCtx: &v1.PodSecurityContext{
SupplementalGroups: []kubetypes.UnixGroupID{
kubetypes.UnixGroupID(1),
kubetypes.UnixGroupID(2),
SupplementalGroups: []int64{
int64(1),
int64(2),
},
FSGroup: &fsgid,
},
Expand Down Expand Up @@ -1157,9 +1157,9 @@ func TestSetApp(t *testing.T) {
RunAsNonRoot: &runAsNonRootTrue,
},
podCtx: &v1.PodSecurityContext{
SupplementalGroups: []kubetypes.UnixGroupID{
kubetypes.UnixGroupID(1),
kubetypes.UnixGroupID(2),
SupplementalGroups: []int64{
int64(1),
int64(2),
},
FSGroup: &fsgid,
},
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubelet/volumemanager/volume_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubetypes "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/record"
utiltesting "k8s.io/client-go/util/testing"
Expand Down Expand Up @@ -239,7 +238,7 @@ func createObjects() (*v1.Node, *v1.Pod, *v1.PersistentVolume, *v1.PersistentVol
},
},
SecurityContext: &v1.PodSecurityContext{
SupplementalGroups: []kubetypes.UnixGroupID{555},
SupplementalGroups: []int64{555},
},
},
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/security/podsecuritypolicy/group/mustrunas.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package group
import (
"fmt"

"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/extensions"
Expand Down Expand Up @@ -47,22 +46,22 @@ func NewMustRunAs(ranges []extensions.GroupIDRange, field string) (GroupStrategy

// Generate creates the group based on policy rules. By default this returns the first group of the
// first range (min val).
func (s *mustRunAs) Generate(pod *api.Pod) ([]types.UnixGroupID, error) {
return []types.UnixGroupID{s.ranges[0].Min}, nil
func (s *mustRunAs) Generate(pod *api.Pod) ([]int64, error) {
return []int64{s.ranges[0].Min}, nil
}

// Generate a single value to be applied. This is used for FSGroup. This strategy will return
// the first group of the first range (min val).
func (s *mustRunAs) GenerateSingle(pod *api.Pod) (*types.UnixGroupID, error) {
single := new(types.UnixGroupID)
func (s *mustRunAs) GenerateSingle(pod *api.Pod) (*int64, error) {
single := new(int64)
*single = s.ranges[0].Min
return single, nil
}

// Validate ensures that the specified values fall within the range of the strategy.
// Groups are passed in here to allow this strategy to support multiple group fields (fsgroup and
// supplemental groups).
func (s *mustRunAs) Validate(pod *api.Pod, groups []types.UnixGroupID) field.ErrorList {
func (s *mustRunAs) Validate(pod *api.Pod, groups []int64) field.ErrorList {
allErrs := field.ErrorList{}

if pod.Spec.SecurityContext == nil {
Expand All @@ -84,7 +83,7 @@ func (s *mustRunAs) Validate(pod *api.Pod, groups []types.UnixGroupID) field.Err
return allErrs
}

func (s *mustRunAs) isGroupValid(group types.UnixGroupID) bool {
func (s *mustRunAs) isGroupValid(group int64) bool {
for _, rng := range s.ranges {
if psputil.GroupFallsInRange(group, rng) {
return true
Expand Down
Loading

0 comments on commit c91a12d

Please sign in to comment.