Skip to content

Commit 2937e9c

Browse files
authored
Merge pull request #8117 from jlamillan/jlamillan/oci_sdk_65.90
Upgrade OCI provider SDK to v65.90.0. Required for Go 1.24.
2 parents ff55955 + 3fd510b commit 2937e9c

File tree

1,325 files changed

+17401
-7142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,325 files changed

+17401
-7142
lines changed

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/gofrs/flock/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ go get -u github.com/gofrs/flock
2121

2222
## Usage
2323
```Go
24-
import "github.com/gofrs/flock"
24+
import "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/gofrs/flock"
2525

2626
fileLock := flock.New("/var/lock/go-lock.lock")
2727

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/certificate_retriever.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/configuration.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/dispatcher_modifier.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/federation_client.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
// Package auth provides supporting functions and structs for authentication
@@ -203,6 +203,13 @@ func newAuthClient(region common.Region, provider common.KeyProvider) *common.Ba
203203
client.Host = region.Endpoint("auth")
204204
}
205205
client.BasePath = "v1/x509"
206+
207+
if common.GlobalAuthClientCircuitBreakerSetting != nil {
208+
client.Configuration.CircuitBreaker = common.NewCircuitBreaker(common.GlobalAuthClientCircuitBreakerSetting)
209+
} else if !common.IsEnvVarFalse("OCI_SDK_AUTH_CLIENT_CIRCUIT_BREAKER_ENABLED") {
210+
common.Logf("Configuring DefaultAuthClientCircuitBreakerSetting for federation client")
211+
client.Configuration.CircuitBreaker = common.NewCircuitBreaker(common.DefaultAuthClientCircuitBreakerSetting())
212+
}
206213
return &client
207214
}
208215

@@ -288,7 +295,7 @@ func (c *x509FederationClient) getSecurityToken() (securityToken, error) {
288295
var httpResponse *http.Response
289296
defer common.CloseBodyIfValid(httpResponse)
290297

291-
for retry := 0; retry < 5; retry++ {
298+
for retry := 0; retry < 3; retry++ {
292299
request := c.makeX509FederationRequest()
293300

294301
if httpRequest, err = common.MakeDefaultHTTPRequestWithTaggedStruct(http.MethodPost, "", request); err != nil {
@@ -298,7 +305,10 @@ func (c *x509FederationClient) getSecurityToken() (securityToken, error) {
298305
if httpResponse, err = c.authClient.Call(context.Background(), &httpRequest); err == nil {
299306
break
300307
}
301-
308+
// Don't retry on 4xx errors
309+
if httpResponse != nil && httpResponse.StatusCode >= 400 && httpResponse.StatusCode <= 499 {
310+
return nil, fmt.Errorf("error %s returned by auth service: %s", httpResponse.Status, err.Error())
311+
}
302312
nextDuration := time.Duration(1000.0*(math.Pow(2.0, float64(retry)))) * time.Millisecond
303313
time.Sleep(nextDuration)
304314
}

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/federation_client_oke_workload_identity.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth
@@ -125,8 +125,14 @@ func (c *x509FederationClientForOkeWorkloadIdentity) getSecurityToken() (securit
125125

126126
statusCode := response.StatusCode
127127
if statusCode != http.StatusOK {
128-
return nil, fmt.Errorf("failed to get a RPST token from Proxymux: URL: %s, Status: %s, Message: %s",
129-
c.proxymuxEndpoint, response.Status, body.String())
128+
if statusCode == http.StatusForbidden {
129+
return nil, fmt.Errorf("please ensure the cluster type is enhanced: Status: %s, Message: %s",
130+
response.Status, body.String())
131+
} else {
132+
return nil, fmt.Errorf("failed to get a RPST token from Proxymux: URL: %s, Status: %s, Message: %s",
133+
c.proxymuxEndpoint, response.Status, body.String())
134+
}
135+
130136
}
131137

132138
if _, err = body.ReadFrom(response.Body); err != nil {

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/instance_principal_delegation_token_provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/instance_principal_key_provider.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth
@@ -7,9 +7,9 @@ import (
77
"bytes"
88
"crypto/rsa"
99
"fmt"
10+
"math/rand"
1011
"net/http"
1112
"os"
12-
"strings"
1313
"time"
1414

1515
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common"
@@ -18,7 +18,6 @@ import (
1818
const (
1919
defaultMetadataBaseURL = `http://169.254.169.254/opc/v2`
2020
metadataBaseURLEnvVar = `OCI_METADATA_BASE_URL`
21-
metadataFallbackURL = `http://169.254.169.254/opc/v1`
2221
regionPath = `/instance/region`
2322
leafCertificatePath = `/identity/cert.pem`
2423
leafCertificateKeyPath = `/identity/key.pem`
@@ -106,19 +105,19 @@ func newInstancePrincipalKeyProvider(modifier func(common.HTTPRequestDispatcher)
106105
func getRegionForFederationClient(dispatcher common.HTTPRequestDispatcher, url string) (r common.Region, err error) {
107106
var body bytes.Buffer
108107
var statusCode int
109-
MaxRetriesFederationClient := 3
108+
MaxRetriesFederationClient := 8
110109
for currTry := 0; currTry < MaxRetriesFederationClient; currTry++ {
111110
body, statusCode, err = httpGet(dispatcher, url)
112111
if err == nil && statusCode == 200 {
113112
return common.StringToRegion(body.String()), nil
114113
}
115114
common.Logf("Error in getting region from url: %s, Status code: %v, Error: %s", url, statusCode, err.Error())
116-
if statusCode == 404 && strings.Compare(url, getMetadataBaseURL()+regionPath) == 0 {
117-
common.Logf("Falling back to http://169.254.169.254/opc/v1 to try again...\n")
118-
updateX509CertRetrieverURLParas(metadataFallbackURL)
119-
url = regionURL
115+
nextDuration := time.Duration(float64(int(1)<<currTry)+rand.Float64()) * time.Second
116+
if nextDuration > 30*time.Second {
117+
nextDuration = 30*time.Second + time.Duration(rand.Float64())*time.Second
120118
}
121-
time.Sleep(1 * time.Second)
119+
common.Logf("Retrying for getRegionForFederationClinet function, current retry count is:%v, sleep after %v", currTry+1, nextDuration)
120+
time.Sleep(nextDuration)
122121
}
123122
return
124123
}

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/jwt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/resource_principal_delegation_token_provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/resource_principal_key_provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/resource_principal_token_path_provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/resource_principals_v1.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/resource_principals_v3.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/auth/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package auth

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/circuit_breaker.go

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package common
55

66
import (
77
"fmt"
8+
"math/rand"
89
"net/http"
910
"os"
1011
"strconv"
@@ -29,6 +30,16 @@ const (
2930
DefaultCircuitBreakerServiceName string = ""
3031
// DefaultCircuitBreakerHistoryCount is the default count of failed response history in circuit breaker
3132
DefaultCircuitBreakerHistoryCount int = 5
33+
// MinAuthClientCircuitBreakerResetTimeout is the min value of openStateWindow, which is the wait time before setting the breaker to halfOpen state from open state
34+
MinAuthClientCircuitBreakerResetTimeout = 30
35+
// MaxAuthClientCircuitBreakerResetTimeout is the max value of openStateWindow, which is the wait time before setting the breaker to halfOpen state from open state
36+
MaxAuthClientCircuitBreakerResetTimeout = 49
37+
// AuthClientCircuitBreakerName is the default circuit breaker name for the DefaultAuthClientCircuitBreakerSetting
38+
AuthClientCircuitBreakerName = "FederationClientCircuitBreaker"
39+
// AuthClientCircuitBreakerDefaultFailureThreshold is the default requests failure rate for the DefaultAuthClientCircuitBreakerSetting
40+
AuthClientCircuitBreakerDefaultFailureThreshold float64 = 0.65
41+
// AuthClientCircuitBreakerDefaultMinimumRequests is the default value of minimumRequests in closed status
42+
AuthClientCircuitBreakerDefaultMinimumRequests uint32 = 3
3243
)
3344

3445
// CircuitBreakerSetting wraps all exposed configurable params of circuit breaker
@@ -213,7 +224,7 @@ func NewCircuitBreakerSettingWithOptions(opts ...CircuitBreakerOption) *CircuitB
213224
for _, opt := range opts {
214225
opt(cbst)
215226
}
216-
if defaultLogger.LogLevel() == verboseLogging {
227+
if defaultLogger != nil && defaultLogger.LogLevel() == verboseLogging {
217228
Debugf("Circuit Breaker setting: %s\n", cbst.String())
218229
}
219230

@@ -383,3 +394,17 @@ func ConfigCircuitBreakerFromGlobalVar(baseClient *BaseClient) {
383394
baseClient.Configuration.CircuitBreaker = NewCircuitBreaker(GlobalCircuitBreakerSetting)
384395
}
385396
}
397+
398+
// DefaultAuthClientCircuitBreakerSetting returns the default circuit breaker setting for the Auth Client
399+
func DefaultAuthClientCircuitBreakerSetting() *CircuitBreakerSetting {
400+
return NewCircuitBreakerSettingWithOptions(
401+
WithOpenStateWindow(time.Duration(rand.Intn(MaxAuthClientCircuitBreakerResetTimeout+1-MinAuthClientCircuitBreakerResetTimeout)+MinAuthClientCircuitBreakerResetTimeout)*time.Second),
402+
WithName(AuthClientCircuitBreakerName),
403+
WithFailureRateThreshold(AuthClientCircuitBreakerDefaultFailureThreshold),
404+
WithMinimumRequests(AuthClientCircuitBreakerDefaultMinimumRequests),
405+
)
406+
}
407+
408+
// GlobalAuthClientCircuitBreakerSetting is global level circuit breaker setting for the Auth Client
409+
// than client level circuit breaker
410+
var GlobalAuthClientCircuitBreakerSetting *CircuitBreakerSetting = nil

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
// Package common provides supporting functions and structs used by service packages

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package common

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/configuration.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package common

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/errors.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package common
@@ -25,7 +25,7 @@ type ServiceError interface {
2525
GetMessage() string
2626

2727
// A short error code that defines the error, meant for programmatic parsing.
28-
// See https://docs.cloud.oracle.com/Content/API/References/apierrors.htm
28+
// See https://docs.oracle.com/iaas/Content/API/References/apierrors.htm
2929
GetCode() string
3030

3131
// Unique Oracle-assigned identifier for the request.

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/eventual_consistency.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
package common

cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common/helpers.go

+25-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
// This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
33

44
//lint:file-ignore SA1019 older versions of staticcheck (those compatible with Golang 1.17) falsely flag x509.IsEncryptedPEMBlock and x509.DecryptPEMBlock.
@@ -10,13 +10,16 @@ import (
1010
"crypto/rsa"
1111
"crypto/x509"
1212
"encoding/pem"
13+
"errors"
1314
"fmt"
1415
"net/textproto"
1516
"os"
1617
"reflect"
1718
"strconv"
1819
"strings"
1920
"time"
21+
22+
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/youmark/pkcs8"
2023
)
2124

2225
// String returns a pointer to the provided string
@@ -222,24 +225,30 @@ func PrivateKeyFromBytes(pemData []byte, password *string) (key *rsa.PrivateKey,
222225
// PrivateKeyFromBytesWithPassword is a helper function that will produce a RSA private
223226
// key from bytes and a password.
224227
func PrivateKeyFromBytesWithPassword(pemData, password []byte) (key *rsa.PrivateKey, e error) {
225-
if pemBlock, _ := pem.Decode(pemData); pemBlock != nil {
226-
decrypted := pemBlock.Bytes
227-
if x509.IsEncryptedPEMBlock(pemBlock) {
228-
if password == nil {
229-
e = fmt.Errorf("private key password is required for encrypted private keys")
230-
return
231-
}
232-
if decrypted, e = x509.DecryptPEMBlock(pemBlock, password); e != nil {
233-
return
234-
}
235-
}
236-
237-
key, e = parsePKCSPrivateKey(decrypted)
238-
239-
} else {
228+
pemBlock, _ := pem.Decode(pemData)
229+
if pemBlock == nil {
240230
e = fmt.Errorf("PEM data was not found in buffer")
241231
return
242232
}
233+
234+
decrypted := pemBlock.Bytes
235+
// Support for encrypted PKCS8 format, this format can not be handled by x509.IsEncryptedPEMBlock func
236+
if key, e = pkcs8.ParsePKCS8PrivateKeyRSA(pemBlock.Bytes, password); key != nil {
237+
return
238+
}
239+
// if pemBlock.Type == "ENCRYPTED PRIVATE KEY" {
240+
// return pkcs8.ParsePKCS8PrivateKeyRSA(pemData, password)
241+
// }
242+
if x509.IsEncryptedPEMBlock(pemBlock) {
243+
if password == nil {
244+
return nil, errors.New("private key password is required for encrypted private keys")
245+
}
246+
247+
if decrypted, e = x509.DecryptPEMBlock(pemBlock, password); e != nil {
248+
return
249+
}
250+
}
251+
key, e = parsePKCSPrivateKey(decrypted)
243252
return
244253
}
245254

0 commit comments

Comments
 (0)