Skip to content

Find, verify, and analyze leaked credentials

Replace deprecated google.CredentialsFromJSON with CredentialsFromJSONWithType (#5428)

Bryan Beverly37a6f6e548d0
diff --git a/go.mod b/go.mod
index 4c7cdfd84..5e5eb6fae 100644
--- a/go.mod
+++ b/go.mod
@@ -107,7 +107,7 @@ require (
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.53.0
golang.org/x/net v0.56.0
- golang.org/x/oauth2 v0.34.0
+ golang.org/x/oauth2 v0.36.0
golang.org/x/sync v0.21.0
golang.org/x/text v0.39.0
golang.org/x/time v0.14.0
diff --git a/go.sum b/go.sum
index 888c54961..d50ae8889 100644
--- a/go.sum
+++ b/go.sum
@@ -903,8 +903,8 @@ golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4Iltr
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
-golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw=
-golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
+golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
+golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
diff --git a/pkg/detectors/gcp/gcp.go b/pkg/detectors/gcp/gcp.go
index e7b8ee2f9..b0f59af0c 100644
--- a/pkg/detectors/gcp/gcp.go
+++ b/pkg/detectors/gcp/gcp.go
@@ -165,7 +165,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
func verifyMatch(ctx context.Context, credBytes []byte) (bool, error) {
- credentials, err := google.CredentialsFromJSON(ctx, credBytes, "https://www.googleapis.com/auth/cloud-platform")
+ credentials, err := google.CredentialsFromJSONWithType(ctx, credBytes, google.ServiceAccount, "https://www.googleapis.com/auth/cloud-platform")
if err != nil {
return false, err
}
diff --git a/pkg/detectors/gcpapplicationdefaultcredentials/gcpapplicationdefaultcredentials.go b/pkg/detectors/gcpapplicationdefaultcredentials/gcpapplicationdefaultcredentials.go
index 6ab4c93c5..bd682fd13 100644
--- a/pkg/detectors/gcpapplicationdefaultcredentials/gcpapplicationdefaultcredentials.go
+++ b/pkg/detectors/gcpapplicationdefaultcredentials/gcpapplicationdefaultcredentials.go
@@ -111,7 +111,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
func verifyMatch(ctx context.Context, client *http.Client, token string) (bool, map[string]string, error) {
// First load the credential from the found key
- credentials, err := google.CredentialsFromJSON(ctx, []byte(token), "https://www.googleapis.com/auth/cloud-platform")
+ credentials, err := google.CredentialsFromJSONWithType(ctx, []byte(token), google.AuthorizedUser, "https://www.googleapis.com/auth/cloud-platform")
if err != nil {
return false, nil, err
}
diff --git a/pkg/sources/gcs/gcs_manager.go b/pkg/sources/gcs/gcs_manager.go
index 964779ac3..1ecb95a4a 100644
--- a/pkg/sources/gcs/gcs_manager.go
+++ b/pkg/sources/gcs/gcs_manager.go
@@ -144,7 +144,7 @@ func withAPIKey(ctx context.Context, apiKey string) gcsManagerOption {
// withJSONServiceAccount uses the provided JSON service account when creating a new GCS client.
func withJSONServiceAccount(ctx context.Context, jsonServiceAccount []byte) gcsManagerOption {
- creds, err := google.CredentialsFromJSON(ctx, jsonServiceAccount, storage.ScopeReadOnly)
+ creds, err := google.CredentialsFromJSONWithType(ctx, jsonServiceAccount, google.ServiceAccount, storage.ScopeReadOnly)
if err != nil {
return func(m *gcsManager) error {
return fmt.Errorf("failed to load credentials: %w", err)