You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "superhawk610 (via GitHub)" <gi...@apache.org> on 2023/10/12 19:30:49 UTC

[PR] go/adbc/driver/snowflake: support PEM decoding JWT private keys [arrow-adbc]

superhawk610 opened a new pull request, #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199

   Resolves #1198.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(go/adbc/driver/snowflake): support PEM decoding JWT private keys [arrow-adbc]

Posted by "superhawk610 (via GitHub)" <gi...@apache.org>.
superhawk610 commented on PR #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199#issuecomment-1762047847

   > see [snowflakedb/gosnowflake@dfb1c18/priv_key_test.go#L52](https://github.com/snowflakedb/gosnowflake/blob/dfb1c18624ebd4023e27839cd32a51955758bd75/priv_key_test.go#L52) for an example
   
   Just saw this, thanks @davidhcoe I'll replace the hard-coded RSA keys with this approach.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(go/adbc/driver/snowflake): support PEM decoding JWT private keys [arrow-adbc]

Posted by "davidhcoe (via GitHub)" <gi...@apache.org>.
davidhcoe commented on PR #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199#issuecomment-1766475502

   We'll probably want to sync up this and whatever lands from my proposal in https://github.com/apache/arrow-adbc/pull/1207 - particularly the support for encrypted keys. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(go/adbc/driver/snowflake): support PEM decoding JWT private keys [arrow-adbc]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade merged PR #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(go/adbc/driver/snowflake): support PEM decoding JWT private keys [arrow-adbc]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on code in PR #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199#discussion_r1358381338


##########
go/adbc/driver/snowflake/snowflake_database.go:
##########
@@ -328,13 +330,28 @@ func (d *databaseImpl) SetOptions(cnOptions map[string]string) error {
 				}
 			}
 
-			d.cfg.PrivateKey, err = x509.ParsePKCS1PrivateKey(data)
+			var block []byte
+			if strings.Contains(string(data), "PRIVATE KEY") {
+				b, _ := pem.Decode(data)
+				block = b.Bytes
+			} else {
+				block = data
+			}
+
+			var key any
+			key, err = x509.ParsePKCS1PrivateKey(block)
+			if err != nil && strings.Contains(err.Error(), "use ParsePKCS8PrivateKey instead") {
+				key, err = x509.ParsePKCS8PrivateKey(block)
+			}
+			
 			if err != nil {
 				return adbc.Error{
 					Msg:  "failed parsing private key file '" + v + "': " + err.Error(),
 					Code: adbc.StatusInvalidArgument,
 				}
 			}
+
+			d.cfg.PrivateKey = key

Review Comment:
   You can't make this assign directly, you need to check that `key` is an `*rsa.PrivateKey` and type assert it. 
   
   While `ParsePKCS1PrivateKey` returns an `*rsa.PrivateKey`, `ParsePKCS8PrivateKey` might return an `*ecdsa.PrivateKey`, an `ed25519.PrivateKey` (not a pointer), or an `*ecdh.PrivateKey` (for X25519) while the Snowflake driver currently only accepts an `*rsa.PrivateKey` as far as I'm aware.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(go/adbc/driver/snowflake): support PEM decoding JWT private keys [arrow-adbc]

Posted by "davidhcoe (via GitHub)" <gi...@apache.org>.
davidhcoe commented on PR #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199#issuecomment-1760527161

   Can you add a unit test for this as well?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(go/adbc/driver/snowflake): support PEM decoding JWT private keys [arrow-adbc]

Posted by "davidhcoe (via GitHub)" <gi...@apache.org>.
davidhcoe commented on code in PR #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199#discussion_r1358624475


##########
go/adbc/driver/snowflake/snowflake_database.go:
##########
@@ -328,13 +330,28 @@ func (d *databaseImpl) SetOptions(cnOptions map[string]string) error {
 				}
 			}
 
-			d.cfg.PrivateKey, err = x509.ParsePKCS1PrivateKey(data)
+			var block []byte
+			if strings.Contains(string(data), "PRIVATE KEY") {
+				b, _ := pem.Decode(data)
+				block = b.Bytes
+			} else {
+				block = data
+			}
+
+			var key any
+			key, err = x509.ParsePKCS1PrivateKey(block)
+			if err != nil && strings.Contains(err.Error(), "use ParsePKCS8PrivateKey instead") {
+				key, err = x509.ParsePKCS8PrivateKey(block)
+			}
+			
 			if err != nil {
 				return adbc.Error{
 					Msg:  "failed parsing private key file '" + v + "': " + err.Error(),
 					Code: adbc.StatusInvalidArgument,
 				}
 			}
+
+			d.cfg.PrivateKey = key

Review Comment:
   see https://github.com/snowflakedb/gosnowflake/blob/dfb1c18624ebd4023e27839cd32a51955758bd75/priv_key_test.go#L52 for an example



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(go/adbc/driver/snowflake): support PEM decoding JWT private keys [arrow-adbc]

Posted by "superhawk610 (via GitHub)" <gi...@apache.org>.
superhawk610 commented on PR #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199#issuecomment-1765249137

   @davidhcoe updated the test to connect to Snowflake! I had to open a trial Snowflake account to verify this locally and it took a bit to figure out the expected configuration, so I figured I'd document it here:
   
   1. Open a Snowflake account, note the username/password/account.
   2. From the Snowflake console, execute the following statements:
   ```sql
   create database adbc_testing;
   grant all on database adbc_testing to public;
   grant all on schema adbc_testing.public to public;
   grant all on warehouse compute_wh to public;
   ```
   3. Set the following environment variables (replacing `$SNOW_*` accordingly) to test locally:
   ```env
   export SNOWFLAKE_URI="$SNOW_USER:$SNOW_PASS/$SNOW_ACCOUNT/adbc_testing?warehouse=compute_wh&role=public"
   export SNOWFLAKE_DATABASE="adbc_testing"
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(go/adbc/driver/snowflake): support PEM decoding JWT private keys [arrow-adbc]

Posted by "davidhcoe (via GitHub)" <gi...@apache.org>.
davidhcoe commented on code in PR #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199#discussion_r1358841245


##########
go/adbc/driver/snowflake/snowflake_database_test.go:
##########
@@ -0,0 +1,94 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package snowflake
+
+import (
+	"crypto/rand"
+	"crypto/rsa"
+	"crypto/x509"
+	"encoding/pem"
+	"os"
+	"testing"
+
+	"github.com/apache/arrow-adbc/go/adbc/driver/driverbase"
+	"github.com/apache/arrow/go/v13/arrow/memory"
+)
+
+func TestSetOptionsJwtPrivateKey(t *testing.T) {

Review Comment:
   I imagined this would more so validate that you can connect to Snowflake with the JWT token and not just set the value. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(go/adbc/driver/snowflake): support PEM decoding JWT private keys [arrow-adbc]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on PR #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199#issuecomment-1761666821

   Aside from fixing the failing builds, I agree with @davidhcoe that I'd like a unit test for this if possible please.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(go/adbc/driver/snowflake): support PEM decoding JWT private keys [arrow-adbc]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on PR #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199#issuecomment-1773328964

   This looks good to me, though we may need to make some modifications after this lands based on what permissions the testing user our CI has (it may not have the ACCOUNTADMIN permissions to add the RSA key or something). 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] go/adbc/driver/snowflake: support PEM decoding JWT private keys [arrow-adbc]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199#issuecomment-1760249400

   :warning: Please follow the [Conventional Commits format in CONTRIBUTING.md](https://github.com/apache/arrow-adbc/blob/main/CONTRIBUTING.md) for PR titles.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(go/adbc/driver/snowflake): support PEM decoding JWT private keys [arrow-adbc]

Posted by "davidhcoe (via GitHub)" <gi...@apache.org>.
davidhcoe commented on PR #1199:
URL: https://github.com/apache/arrow-adbc/pull/1199#issuecomment-1771605663

   @zeroshade - if this one is ready to land, I can sync https://github.com/apache/arrow-adbc/pull/1207 to it


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org