-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate k8gb.io/exposed-ip-addresses annotation
Signed-off-by: Andre Aguas <[email protected]>
- Loading branch information
Showing
9 changed files
with
270 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{ if .Values.k8gb.validatingAdmissionPolicy.enabled -}} | ||
--- | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: ValidatingAdmissionPolicyBinding | ||
metadata: | ||
name: k8gb-exposed-ip-annotation | ||
spec: | ||
policyName: k8gb-exposed-ip-annotation | ||
matchResources: | ||
namespaceSelector: {} | ||
validationActions: | ||
- Deny | ||
--- | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: ValidatingAdmissionPolicy | ||
metadata: | ||
name: k8gb-exposed-ip-annotation | ||
spec: | ||
validations: | ||
- expression: object.metadata.annotations['k8gb.io/exposed-ip-addresses'].matches('^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$') | ||
message: The annotation 'k8gb.io/exposed-ip-addresses' must contain a valid IPv4 address | ||
matchConditions: | ||
- name: hasExposedIPAddressesAnnotation | ||
expression: "has(object.metadata.annotations) && 'k8gb.io/exposed-ip-addresses' in object.metadata.annotations" | ||
matchConstraints: | ||
resourceRules: | ||
- apiGroups: ["k8gb.absa.oss"] | ||
apiVersions: ["v1beta1"] | ||
operations: ["CREATE", "UPDATE"] | ||
resources: ["gslbs"] | ||
failurePolicy: Fail | ||
{{ end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package utils | ||
|
||
/* | ||
Copyright 2022 The k8gb Contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic | ||
*/ | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"strings" | ||
) | ||
|
||
// ParseIPAddresses parse a comma separated string of ip addresses into a list of net.IP | ||
func ParseIPAddresses(ipsStr string) ([]string, error) { | ||
IPs := []string{} | ||
for _, ipStr := range strings.Split(ipsStr, ",") { | ||
ipAddr := net.ParseIP(ipStr) | ||
if ipAddr == nil { | ||
return []string{}, fmt.Errorf("invalid IP address: %s", ipStr) | ||
} | ||
IPs = append(IPs, ipAddr.String()) | ||
} | ||
|
||
return IPs, nil | ||
} |
Oops, something went wrong.