-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-938188 validation of session properties for protecting unauthori…
…zed pool access
- Loading branch information
1 parent
ca5efb5
commit 04633e2
Showing
9 changed files
with
96 additions
and
45 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
Snowflake.Data/Core/Authenticator/AuthenticationPropertiesValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Snowflake.Data.Client; | ||
using Snowflake.Data.Log; | ||
|
||
namespace Snowflake.Data.Core.Authenticator | ||
{ | ||
internal static class AuthenticationPropertiesValidator | ||
{ | ||
private static readonly SFLogger s_logger = SFLoggerFactory.GetLogger<SFSessionProperties>(); | ||
|
||
public static void Validate(SFSessionProperties properties) | ||
{ | ||
if (!properties.TryGetValue(SFSessionProperty.AUTHENTICATOR, out var authenticator)) | ||
{ | ||
s_logger.Error("Unspecified authenticator"); | ||
throw new SnowflakeDbException(SFError.UNKNOWN_AUTHENTICATOR); | ||
} | ||
|
||
bool valid; | ||
var error = ""; | ||
switch (authenticator.ToLower()) | ||
{ | ||
case BasicAuthenticator.AUTH_NAME: | ||
valid = !string.IsNullOrEmpty(properties[SFSessionProperty.USER]) && | ||
!string.IsNullOrEmpty(properties[SFSessionProperty.PASSWORD]); | ||
if (!valid) | ||
error = $"USER and PASSWORD should be provided for Authenticator={authenticator}"; | ||
break; | ||
case ExternalBrowserAuthenticator.AUTH_NAME: | ||
valid = true; | ||
break; | ||
case KeyPairAuthenticator.AUTH_NAME: | ||
valid = !string.IsNullOrEmpty(properties[SFSessionProperty.PRIVATE_KEY]) || | ||
!string.IsNullOrEmpty(properties[SFSessionProperty.PRIVATE_KEY]); | ||
if (!valid) | ||
error = $"PRIVATE_KEY or PRIVATE_KEY should be provided for Authenticator={authenticator}"; | ||
break; | ||
case OAuthAuthenticator.AUTH_NAME: | ||
valid = !string.IsNullOrEmpty(properties[SFSessionProperty.TOKEN]); | ||
if (!valid) | ||
error = $"TOKEN should be provided for Authenticator={authenticator}"; | ||
break; | ||
default: | ||
if (authenticator.Contains(OktaAuthenticator.AUTH_NAME) && | ||
authenticator.StartsWith("https://")) | ||
{ | ||
valid = !string.IsNullOrEmpty(properties[SFSessionProperty.USER]) && | ||
!string.IsNullOrEmpty(properties[SFSessionProperty.PASSWORD]); | ||
if (!valid) | ||
error = $"USER and PASSWORD should be provided for Authenticator={authenticator}"; | ||
} | ||
else | ||
throw new SnowflakeDbException(SFError.UNKNOWN_AUTHENTICATOR, $"Unrecognized Authenticator={authenticator}"); | ||
break; | ||
} | ||
|
||
if (!valid) | ||
{ | ||
s_logger.Error(error); | ||
throw new SnowflakeDbException(SFError.INVALID_CONNECTION_STRING, $"Unrecognized Authenticator={authenticator}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters