Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: drop old golang-jwt/jwt dependency #39804

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17540,25 +17540,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



--------------------------------------------------------------------------------
Dependency : github.com/golang-jwt/jwt/v5
Version: v5.0.0
Licence type (autodetected): MIT
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/golang-jwt/jwt/v5@v5.0.0/LICENSE:

Copyright (c) 2012 Dave Grijalva
Copyright (c) 2021 golang-jwt maintainers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



--------------------------------------------------------------------------------
Dependency : github.com/golang/mock
Version: v1.6.0
Expand Down Expand Up @@ -40126,6 +40107,25 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI



--------------------------------------------------------------------------------
Dependency : github.com/golang-jwt/jwt/v5
Version: v5.0.0
Licence type (autodetected): MIT
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/golang-jwt/jwt/v5@v5.0.0/LICENSE:

Copyright (c) 2012 Dave Grijalva
Copyright (c) 2021 golang-jwt maintainers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



--------------------------------------------------------------------------------
Dependency : github.com/golang-sql/civil
Version: v0.0.0-20190719163853-cb61b32ac6fe
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ require (
github.com/foxcpp/go-mockdns v0.0.0-20201212160233-ede2f9158d15
github.com/g8rswimmer/go-sfdc v0.0.0-00010101000000-000000000000
github.com/go-ldap/ldap/v3 v3.4.6
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/google/cel-go v0.19.0
github.com/googleapis/gax-go/v2 v2.12.0
github.com/gorilla/handlers v1.5.1
Expand Down Expand Up @@ -303,6 +302,7 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/godror/knownpb v0.1.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the changes look good, I suggest that since we have github.com/golang-jwt/jwt/v4 as an indirect dependency, why not use the function from there as the code is essentially the same and there is no overhead as far as I know. It is just that github.com/golang-jwt/jwt/v4 becomes a direct dependency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree. Direct and indirect dependencies are not the same and should not be treated the same.
Beats already disables dead code elimination due to problematic use of reflection, adding more direct dependencies only makes the problem worse by increasing binary size for downstream users.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it is included, right? Indirect are dependencies imported by direct dependencies. So, they are already on the build list. As github.com/golang-jwt/jwt/v4 is already in the build list, I suggested let we make it a direct dependency instead (not v5, but v4).

What do you think?

github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand Down
27 changes: 25 additions & 2 deletions x-pack/filebeat/input/salesforce/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ package salesforce
import (
"bytes"
"context"
"crypto/rsa"
"crypto/x509"
"encoding/csv"
"encoding/json"
"encoding/pem"
"errors"
"fmt"
"io"
Expand All @@ -21,7 +24,6 @@ import (
"github.com/g8rswimmer/go-sfdc/credentials"
"github.com/g8rswimmer/go-sfdc/session"
"github.com/g8rswimmer/go-sfdc/soql"
"github.com/golang-jwt/jwt/v5"
"github.com/hashicorp/go-retryablehttp"
"go.uber.org/zap"

Expand Down Expand Up @@ -409,7 +411,7 @@ func (s *salesforceInput) getSFDCConfig(cfg *config) (*sfdc.Configuration, error
return nil, fmt.Errorf("problem with client key path for JWT auth: %w", err)
}

signKey, err := jwt.ParseRSAPrivateKeyFromPEM(pemBytes)
signKey, err := parseRSAPrivateKeyFromPEM(pemBytes)
if err != nil {
return nil, fmt.Errorf("problem with client key for JWT auth: %w", err)
}
Expand Down Expand Up @@ -454,6 +456,27 @@ func (s *salesforceInput) getSFDCConfig(cfg *config) (*sfdc.Configuration, error
}, nil
}

func parseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error) {
// Parse PEM block
var block *pem.Block
if block, _ = pem.Decode(key); block == nil {
return nil, errors.New("Invalid Key: Key must be a PEM encoded PKCS1 or PKCS8 key")
}

if parsedKey, err := x509.ParsePKCS1PrivateKey(block.Bytes); err == nil {
return parsedKey, nil
}

if parsedKey, err := x509.ParsePKCS8PrivateKey(block.Bytes); err == nil {
if pkey, ok := parsedKey.(*rsa.PrivateKey); ok {
return pkey, nil
}

}

return nil, errors.New("Key is not a valid RSA private key")
}

// retryLog is a shim for the retryablehttp.Client.Logger.
type retryLog struct{ log *logp.Logger }

Expand Down
Loading