|
| 1 | +package v1 |
| 2 | + |
| 3 | +import ( |
| 4 | + "k8s.io/kubernetes/pkg/api/unversioned" |
| 5 | + "k8s.io/kubernetes/pkg/api/v1" |
| 6 | +) |
| 7 | + |
| 8 | +// ImagePolicyConfig is the configuration for control of images running on the platform. |
| 9 | +type ImagePolicyConfig struct { |
| 10 | + unversioned.TypeMeta `json:",inline"` |
| 11 | + |
| 12 | + // ExecutionRules determine whether the use of an image is allowed in an object with a pod spec. |
| 13 | + // By default, these rules only apply to pods, but may be extended to other resource types. |
| 14 | + ExecutionRules []ImageExecutionPolicyRule `json:"executionRules"` |
| 15 | + // ConsumptionRules are applied when creating resources with pod specs. |
| 16 | + ConsumptionRules []ImageConsumptionPolicyRule `json:"consumptionRules"` |
| 17 | + // PlacementRules are applied when creating resources with pod specs. |
| 18 | + PlacementRules []ImagePlacementPolicyRule `json:"placementRules"` |
| 19 | + |
| 20 | + // Everyone except cluster admins or platform infra must use an image from the registry |
| 21 | + // Content in this namespace must use an image from the registry |
| 22 | + // Images with a certain annotation/label must be run on these nodes |
| 23 | + // Using this image consumes a certain amount of resource |
| 24 | + // Images cannot be run or imported unless they come from these registries (unless the user is an admin) |
| 25 | + // Images with/without these annotations/labels cannot be run (except in certain namespaces) |
| 26 | + // Image cannot be tagged with/without these labels |
| 27 | + // Images that are not signed by the listed authorities cannot be run (cert not expired) |
| 28 | + // Unsigned images may not be run on the following nodes |
| 29 | + |
| 30 | + // Enforce/Relax by namespace, labels, user permission |
| 31 | + // Actions: Create pod, Tag image, Import image (ISM), Mutate pod (node selector, resources) |
| 32 | + // Add a resource to pod / container (for the image, this is not resource auto-sizing) |
| 33 | + // Add a node selector constraint |
| 34 | + // Require a permission check on the service account / current user to tag / create an image |
| 35 | + |
| 36 | + // Pods with this annotation / label should consume one resource increment (per container / per pod) |
| 37 | + // |
| 38 | +} |
| 39 | + |
| 40 | +// ImagePlacementPolicyRule, when matching an image, applies the provided tolerations or taints. |
| 41 | +type ImagePlacementPolicyRule struct { |
| 42 | + ImageSourceRule `json:",inline"` |
| 43 | + |
| 44 | + Constrain []ConstrainPodNodeSelectorEffect `json:"constrain"` |
| 45 | + Tolerate []TolerateNodeSelectorEffect `json:"tolerate"` |
| 46 | +} |
| 47 | + |
| 48 | +type ConstrainPodNodeSelectorEffect struct { |
| 49 | + Add map[string]string `json:"add"` |
| 50 | +} |
| 51 | + |
| 52 | +type TolerateNodeSelectorEffect struct { |
| 53 | + Add v1.Toleration `json:"add"` |
| 54 | +} |
| 55 | + |
| 56 | +// ImageConsumptionPolicyRule, when matching an image, adds a counted resource to the object. |
| 57 | +type ImageConsumptionPolicyRule struct { |
| 58 | + ImageSourceRule `json:",inline"` |
| 59 | + |
| 60 | + Add []ConsumeResourceEffect `json:"add"` |
| 61 | +} |
| 62 | + |
| 63 | +type ConsumeResourceEffect struct { |
| 64 | + // Name is the name of a quantity to set on each matching container. |
| 65 | + // May not be specified if NameFromImageAnnotation or NameFromDockerImageLabel is set. |
| 66 | + Name string `json:"name"` |
| 67 | + // NameFromImageAnnotation is the name of an image annotation to use to set the name of the resource |
| 68 | + // quantity on each matching container. |
| 69 | + // May not be specified if Name or NameFromDockerImageLabel is set. |
| 70 | + NameFromImageAnnotation string `json:"nameFromImageAnnotation"` |
| 71 | + // NameFromDockerImageLabel is the name of a docker image label to use to set the name of the resource |
| 72 | + // quantity on each matching container. |
| 73 | + // May not be specified if Name or NameFromImageAnnotation is set. |
| 74 | + NameFromDockerImageLabel string `json:"nameFromDockerImageLabel"` |
| 75 | + |
| 76 | + // Quantity is the amount of quantity to set |
| 77 | + Quantity string `json:"quantity"` |
| 78 | + // QuantityFromImageAnnotation is the key on an image annotation to use for the value of this resource. |
| 79 | + // If this value is specified and no annotation is found, the value of Quantity is used instead. |
| 80 | + QuantityFromImageAnnotation string `json:"quantityFromImageAnnotation"` |
| 81 | + // QuantityFromDockerImageLabel is the key on a docker image label to use for the value of this resource. |
| 82 | + // If this value is specified and no annotation is found, the value of Quantity is used instead. |
| 83 | + QuantityFromDockerImageLabel string `json:"quantityFromDockerImageLabel"` |
| 84 | +} |
| 85 | + |
| 86 | +type ImageExecutionPolicyRule struct { |
| 87 | + ImageSourceRule `json:",inline"` |
| 88 | + |
| 89 | + // Deny indicates this rule is inverted and a match results in a rejection |
| 90 | + Deny bool `json:"deny"` |
| 91 | + |
| 92 | + // Resolve indicates that images referenced by this resource must be resolved |
| 93 | + Resolve bool `json:"resolve"` |
| 94 | +} |
| 95 | + |
| 96 | +// ImageSourceRule defines the conditions for matching a particular image source. The conditions below |
| 97 | +// are all required (logical AND) |
| 98 | +type ImageSourceRule struct { |
| 99 | + // Name is the name of this policy rule for reference. It must be unique across all rules. |
| 100 | + Name string `json:"name"` |
| 101 | + // OnResources determines which resources this applies to. Defaults to 'pods' for RuntimeSourceRules. |
| 102 | + OnResources []string `json:"onResources"` |
| 103 | + // IgnoreNamespaceOverride prevents this rule from being overriden when the |
| 104 | + // `alpha.image.policy.openshift.io/ignore-rules` is set on a namespace and contains this rule name. |
| 105 | + IgnoreNamespaceOverride bool `json:"ignoreNamespaceOverride"` |
| 106 | + |
| 107 | + MatchIntegratedRegistry bool `json:"matchIntegratedRegistry"` |
| 108 | + MatchRegistries []string `json:"matchRegistries"` |
| 109 | + |
| 110 | + // AllowResolutionFailure allows the subsequent rules to be bypassed if the integrated registry does |
| 111 | + // not have access to image metadata (no image exists matching the image digest). |
| 112 | + AllowResolutionFailure bool `json:"allowResolutionFailure"` |
| 113 | + |
| 114 | + MatchDockerImageLabels []ValueMatch `json:"matchDockerImageLabels"` |
| 115 | + MatchImageLabels []ValueMatch `json:"matchImageLabels"` |
| 116 | + MatchImageAnnotations []ValueMatch `json:"matchImageAnnotations"` |
| 117 | + MatchSignatures []SignatureMatch `json:"matchSignatures"` |
| 118 | +} |
| 119 | + |
| 120 | +type ValueMatch struct { |
| 121 | + Key string `json:"key"` |
| 122 | + |
| 123 | + // One of the following conditions must apply |
| 124 | + Set bool `json:"set"` |
| 125 | + Value string `json:"value"` |
| 126 | +} |
| 127 | + |
| 128 | +type SignatureMatch struct { |
| 129 | +} |
0 commit comments