SNOW-1869750 add check for empty private key before trying to generate JWT from it #1285
+4
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This is trying to address an Issue coming from a Snowflake Terraform Provider use-case (Snowflake-Labs/terraform-provider-snowflake#3322) but perhaps beneficial without the TF Provider as well.
The current behaviour is that the driver panics when no private key is specified to be used with keypair auth.
Users of the Provider can choose for keypair auth, and can specify the details needed to set up the connection (like user, account, etc, also the private key), multiple ways:
provider
block in theirmain.tf
SNOWFLAKE_PRIVATE_KEY
It is entirely legal to omit the account configuration from config file, it's no problem if you omit it from the
provider
block as well, but then you need to make sure you have the corresponding envvar for each setting.Now. When the authenticator (
snowflake_jwt
) is specified correctly, thus the driver will want to useAuthTypeJwt
, but private key doesn't exist because the user forgot to specify it in all the possible places, then when driver attempts to parse the private key to prepare the JWT token, this stepwill surely crash with a panic when
config.PrivateKey
is not specified, and is thereforenil
when calling the Public() function on it.The aim of this PR is to detect this condition before the panic can happen and error out gracefully with a descriptive error message so the user would know where to look for the fix.