1 /* 2 Copyright 2023 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 v1 18 19 import ( 20 "time" 21 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 bootstrapapi "k8s.io/cluster-bootstrap/token/api" 24 ) 25 26 const ( 27 // DefaultTokenDuration specifies the default amount of time that a bootstrap token will be valid 28 // Default behaviour is 24 hours 29 DefaultTokenDuration = 24 * time.Hour 30 ) 31 32 var ( 33 // DefaultTokenUsages specifies the default functions a token will get 34 DefaultTokenUsages = bootstrapapi.KnownTokenUsages 35 36 // DefaultTokenGroups specifies the default groups that this token will authenticate as when used for authentication 37 DefaultTokenGroups = []string{"system:bootstrappers:kubeadm:default-node-token"} 38 ) 39 40 // SetDefaults_BootstrapToken sets the defaults for an individual Bootstrap Token 41 func SetDefaults_BootstrapToken(bt *BootstrapToken) { 42 if bt.TTL == nil { 43 bt.TTL = &metav1.Duration{ 44 Duration: DefaultTokenDuration, 45 } 46 } 47 if len(bt.Usages) == 0 { 48 bt.Usages = DefaultTokenUsages 49 } 50 51 if len(bt.Groups) == 0 { 52 bt.Groups = DefaultTokenGroups 53 } 54 } 55