You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@yunikorn.apache.org by GitBox <gi...@apache.org> on 2022/09/27 06:10:15 UTC

[GitHub] [yunikorn-k8shim] wilfred-s commented on a diff in pull request #465: [YUNIKORN-1322] [admission] add new config value handling and allow/deny label if defined

wilfred-s commented on code in PR #465:
URL: https://github.com/apache/yunikorn-k8shim/pull/465#discussion_r980788342


##########
pkg/plugin/admissioncontrollers/webhook/webhook.go:
##########
@@ -80,6 +92,44 @@ func main() {
 		noLabelNamespaces = ""
 	}
 
+	bypassAuth := defaultBypassAuth
+	bypassAuthEnv, ok := os.LookupEnv(admissionControllerBypassAuth)
+	if ok {
+		parsed, err := strconv.ParseBool(bypassAuthEnv)
+		if err != nil {
+			log.Logger().Warn("Unable to parse value, using default",
+				zap.String("env var", admissionControllerBypassAuth),
+				zap.Bool("default", defaultBypassAuth))
+		} else {
+			bypassAuth = parsed
+		}
+	}
+	systemUsers, ok := os.LookupEnv(admissionControllerSystemUsers)
+	if !ok {
+		systemUsers = defaultSystemUsers
+	}
+	externalUsers, ok := os.LookupEnv(admissionControllerExternalUsers)
+	if !ok {
+		externalUsers = ""
+	}
+	externalGroups, ok := os.LookupEnv(admissionControllerExternalGroups)
+	if !ok {
+		externalUsers = ""

Review Comment:
   This should be `externalGroups` if I am correct.
   Can we add some unit tests so we can catch things like this?



##########
pkg/plugin/admissioncontrollers/webhook/admission_controller.go:
##########
@@ -51,6 +51,7 @@ const (
 	configHotFreshResponse       = "ConfigHotRefresh is disabled. Please use the REST API to update the configuration, or enable configHotRefresh. "
 	admissionReviewAPIVersion    = "admission.k8s.io/v1"
 	admissionReviewKind          = "AdmissionReview"
+	userInfoAnnotation           = "yunikorn.apache.org/user.info"

Review Comment:
   `yunikorn.apache.org` is a constant already defined which we should re-use



##########
pkg/plugin/admissioncontrollers/webhook/usergroup.go:
##########
@@ -0,0 +1,77 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you 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.
+*/
+
+package main
+
+import (
+	"encoding/json"
+	"fmt"
+	"strings"
+
+	"go.uber.org/zap"
+	admissionv1 "k8s.io/api/admission/v1"
+
+	"github.com/apache/yunikorn-k8shim/pkg/log"
+	"github.com/apache/yunikorn-scheduler-interface/lib/go/si"
+)
+
+func (c *admissionController) validateExternalUserInfo(req *admissionv1.AdmissionRequest, userInfo string) error {

Review Comment:
   Is the annotation only used in the error message?
   We should not need to include the annotation details in the error message, they are not really relevant for the rejection of the pod.



##########
pkg/plugin/admissioncontrollers/webhook/admission_controller.go:
##########
@@ -184,6 +239,13 @@ func (c *admissionController) mutate(req *admissionv1.AdmissionRequest) *admissi
 		return admissionResponseBuilder(uid, false, err.Error(), nil)
 	}
 
+	if annotation, ok := pod.Annotations[userInfoAnnotation]; ok && !c.bypassAuth {
+		if err := c.validateExternalUserInfo(req, annotation); err != nil {
+			log.Logger().Error("external authentication failed", zap.Error(err))

Review Comment:
   The message is not correct. The external authentication did not fail. The `real` user is not allowed to set the annotations. Message should be more like: "User XX is not allowed to set user annotation".



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org