k8s.io/kubernetes@v1.29.3/pkg/apis/abac/v1beta1/conversion.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1beta1
    18  
    19  import (
    20  	"k8s.io/apimachinery/pkg/conversion"
    21  	"k8s.io/kubernetes/pkg/apis/abac"
    22  )
    23  
    24  // allAuthenticated matches k8s.io/apiserver/pkg/authentication/user.AllAuthenticated,
    25  // but we don't want an client library (which must include types), depending on a server library
    26  const allAuthenticated = "system:authenticated"
    27  
    28  func Convert_v1beta1_Policy_To_abac_Policy(in *Policy, out *abac.Policy, s conversion.Scope) error {
    29  	if err := autoConvert_v1beta1_Policy_To_abac_Policy(in, out, s); err != nil {
    30  		return err
    31  	}
    32  
    33  	// In v1beta1, * user or group maps to all authenticated subjects
    34  	if in.Spec.User == "*" || in.Spec.Group == "*" {
    35  		out.Spec.Group = allAuthenticated
    36  		out.Spec.User = ""
    37  	}
    38  
    39  	return nil
    40  }