mayrunas.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package group
  14. import (
  15. "fmt"
  16. policy "k8s.io/api/policy/v1beta1"
  17. "k8s.io/apimachinery/pkg/util/validation/field"
  18. api "k8s.io/kubernetes/pkg/apis/core"
  19. )
  20. // mayRunAs implements the GroupStrategy interface.
  21. type mayRunAs struct {
  22. ranges []policy.IDRange
  23. }
  24. var _ GroupStrategy = &mayRunAs{}
  25. // NewMayRunAs provides a new MayRunAs strategy.
  26. func NewMayRunAs(ranges []policy.IDRange) (GroupStrategy, error) {
  27. if len(ranges) == 0 {
  28. return nil, fmt.Errorf("ranges must be supplied for MayRunAs")
  29. }
  30. return &mayRunAs{
  31. ranges: ranges,
  32. }, nil
  33. }
  34. // Generate creates the group based on policy rules. This strategy returns an empty slice.
  35. func (s *mayRunAs) Generate(_ *api.Pod) ([]int64, error) {
  36. return nil, nil
  37. }
  38. // Generate a single value to be applied. This is used for FSGroup. This strategy returns nil.
  39. func (s *mayRunAs) GenerateSingle(_ *api.Pod) (*int64, error) {
  40. return nil, nil
  41. }
  42. // Validate ensures that the specified values fall within the range of the strategy.
  43. // Groups are passed in here to allow this strategy to support multiple group fields (fsgroup and
  44. // supplemental groups).
  45. func (s *mayRunAs) Validate(fldPath *field.Path, _ *api.Pod, groups []int64) field.ErrorList {
  46. return ValidateGroupsInRanges(fldPath, s.ranges, groups)
  47. }