mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #119643 from carlory/fix-119638
Fix Non Constant-Time Comparison of Service Account Token Secrets
This commit is contained in:
		@@ -17,8 +17,8 @@ limitations under the License.
 | 
			
		||||
package serviceaccount
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"context"
 | 
			
		||||
	"crypto/subtle"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
@@ -125,7 +125,7 @@ func (v *legacyValidator) Validate(ctx context.Context, tokenData string, public
 | 
			
		||||
			klog.V(4).Infof("Token is deleted and awaiting removal: %s/%s for service account %s/%s", namespace, secretName, namespace, serviceAccountName)
 | 
			
		||||
			return nil, errors.New("Token has been invalidated")
 | 
			
		||||
		}
 | 
			
		||||
		if !bytes.Equal(secret.Data[v1.ServiceAccountTokenKey], []byte(tokenData)) {
 | 
			
		||||
		if subtle.ConstantTimeCompare(secret.Data[v1.ServiceAccountTokenKey], []byte(tokenData)) == 0 {
 | 
			
		||||
			klog.V(4).Infof("Token contents no longer matches %s/%s for service account %s/%s", namespace, secretName, namespace, serviceAccountName)
 | 
			
		||||
			return nil, errors.New("Token does not match server's copy")
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user