Skip to content

Commit

Permalink
feat: Add Always Encrypted -g (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
shueybubbles authored Sep 3, 2023
1 parent 9a6b932 commit 0a4cd19
Show file tree
Hide file tree
Showing 20 changed files with 1,927 additions and 1,179 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"request": "launch",
"mode" : "auto",
"program": "${workspaceFolder}/cmd/modern",
"args" : ["-Q", "EXIT(select net_transport from sys.dm_exec_connections)"],
"args" : ["-S", "davidshi-2022", "-g", "-Q", "select nvarcharcol from encrypt.dbo.encrypted", "--driver-logging-level=65"],
},
{
"name" : "Run file query",
Expand Down
92 changes: 76 additions & 16 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This repository incorporates material as listed below or described in the code.
## github.com/Azure/azure-sdk-for-go/sdk/azcore

* Name: github.com/Azure/azure-sdk-for-go/sdk/azcore
* Version: v1.6.0
* License: [MIT](https://github.com/Azure/azure-sdk-for-go/blob/sdk/azcore/v1.6.0/sdk/azcore/LICENSE.txt)
* Version: v1.7.1
* License: [MIT](https://github.com/Azure/azure-sdk-for-go/blob/sdk/azcore/v1.7.1/sdk/azcore/LICENSE.txt)

```
MIT License
Expand Down Expand Up @@ -96,11 +96,71 @@ SOFTWARE
```

## github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys

* Name: github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys
* Version: v1.0.0
* License: [MIT](https://github.com/Azure/azure-sdk-for-go/blob/sdk/security/keyvault/azkeys/v1.0.0/sdk/security/keyvault/azkeys/LICENSE.txt)

```
MIT License
Copyright (c) Microsoft Corporation. All rights reserved.
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
```

## github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal

* Name: github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal
* Version: v0.8.0
* License: [MIT](https://github.com/Azure/azure-sdk-for-go/blob/sdk/security/keyvault/internal/v0.8.0/sdk/security/keyvault/internal/LICENSE.txt)

```
MIT License
Copyright (c) Microsoft Corporation. All rights reserved.
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
```

## github.com/AzureAD/microsoft-authentication-library-for-go/apps

* Name: github.com/AzureAD/microsoft-authentication-library-for-go/apps
* Version: v1.0.0
* License: [MIT](https://github.com/AzureAD/microsoft-authentication-library-for-go/blob/v1.0.0/LICENSE)
* Version: v1.1.0
* License: [MIT](https://github.com/AzureAD/microsoft-authentication-library-for-go/blob/v1.1.0/LICENSE)

```
MIT License
Expand Down Expand Up @@ -1408,11 +1468,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

## github.com/golang-jwt/jwt/v4
## github.com/golang-jwt/jwt/v5

* Name: github.com/golang-jwt/jwt/v4
* Version: v4.5.0
* License: [MIT](https://github.com/golang-jwt/jwt/blob/v4.5.0/LICENSE)
* Name: github.com/golang-jwt/jwt/v5
* Version: v5.0.0
* License: [MIT](https://github.com/golang-jwt/jwt/blob/v5.0.0/LICENSE)

```
Copyright (c) 2012 Dave Grijalva
Expand Down Expand Up @@ -4683,8 +4743,8 @@ THE SOFTWARE.
## golang.org/x/crypto

* Name: golang.org/x/crypto
* Version: v0.9.0
* License: [BSD-3-Clause](https://cs.opensource.google/go/x/crypto/+/v0.9.0:LICENSE)
* Version: v0.12.0
* License: [BSD-3-Clause](https://cs.opensource.google/go/x/crypto/+/v0.12.0:LICENSE)

```
Copyright (c) 2009 The Go Authors. All rights reserved.
Expand Down Expand Up @@ -4720,8 +4780,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
## golang.org/x/net

* Name: golang.org/x/net
* Version: v0.10.0
* License: [BSD-3-Clause](https://cs.opensource.google/go/x/net/+/v0.10.0:LICENSE)
* Version: v0.14.0
* License: [BSD-3-Clause](https://cs.opensource.google/go/x/net/+/v0.14.0:LICENSE)

```
Copyright (c) 2009 The Go Authors. All rights reserved.
Expand Down Expand Up @@ -4757,8 +4817,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
## golang.org/x/sys

* Name: golang.org/x/sys
* Version: v0.8.0
* License: [BSD-3-Clause](https://cs.opensource.google/go/x/sys/+/v0.8.0:LICENSE)
* Version: v0.11.0
* License: [BSD-3-Clause](https://cs.opensource.google/go/x/sys/+/v0.11.0:LICENSE)

```
Copyright (c) 2009 The Go Authors. All rights reserved.
Expand Down Expand Up @@ -4794,8 +4854,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
## golang.org/x/text

* Name: golang.org/x/text
* Version: v0.9.0
* License: [BSD-3-Clause](https://cs.opensource.google/go/x/text/+/v0.9.0:LICENSE)
* Version: v0.12.0
* License: [BSD-3-Clause](https://cs.opensource.google/go/x/text/+/v0.12.0:LICENSE)

```
Copyright (c) 2009 The Go Authors. All rights reserved.
Expand Down
5 changes: 4 additions & 1 deletion cmd/sqlcmd/sqlcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type SQLCmdArguments struct {
RemoveControlCharacters *int
EchoInput bool
QueryTimeout int
EnableColumnEnryption bool
// Keep Help at the end of the list
Help bool
}
Expand Down Expand Up @@ -380,7 +381,7 @@ func setFlags(rootCmd *cobra.Command, args *SQLCmdArguments) {
rootCmd.Flags().StringVarP(&args.Query, "query", "Q", "", localizer.Sprintf("Executes a query when sqlcmd starts and then immediately exits sqlcmd. Multiple-semicolon-delimited queries can be executed"))
rootCmd.Flags().StringVarP(&args.Server, "server", "S", "", localizer.Sprintf("%s Specifies the instance of SQL Server to which to connect. It sets the sqlcmd scripting variable %s.", localizer.ConnStrPattern, localizer.ServerEnvVar))
_ = rootCmd.Flags().IntP(disableCmdAndWarn, "X", 0, localizer.Sprintf("%s Disables commands that might compromise system security. Passing 1 tells sqlcmd to exit when disabled commands are run.", "-X[1]"))
rootCmd.Flags().StringVar(&args.AuthenticationMethod, "authentication-method", "", localizer.Sprintf("Specifies the SQL authentication method to use to connect to Azure SQL Database. One of: ActiveDirectoryDefault, ActiveDirectoryIntegrated, ActiveDirectoryPassword, ActiveDirectoryInteractive, ActiveDirectoryManagedIdentity, ActiveDirectoryServicePrincipal, SqlPassword"))
rootCmd.Flags().StringVar(&args.AuthenticationMethod, "authentication-method", "", localizer.Sprintf("Specifies the SQL authentication method to use to connect to Azure SQL Database. One of: ActiveDirectoryDefault, ActiveDirectoryIntegrated, ActiveDirectoryPassword, ActiveDirectoryInteractive, ActiveDirectoryManagedIdentity, ActiveDirectoryServicePrincipal, ActiveDirectoryAzCli, ActiveDirectoryDeviceCode, SqlPassword"))
rootCmd.Flags().BoolVarP(&args.UseAad, "use-aad", "G", false, localizer.Sprintf("Tells sqlcmd to use ActiveDirectory authentication. If no user name is provided, authentication method ActiveDirectoryDefault is used. If a password is provided, ActiveDirectoryPassword is used. Otherwise ActiveDirectoryInteractive is used"))
rootCmd.Flags().BoolVarP(&args.DisableVariableSubstitution, "disable-variable-substitution", "x", false, localizer.Sprintf("Causes sqlcmd to ignore scripting variables. This parameter is useful when a script contains many %s statements that may contain strings that have the same format as regular variables, such as $(variable_name)", localizer.InsertKeyword))
var variables map[string]string
Expand Down Expand Up @@ -422,6 +423,7 @@ func setFlags(rootCmd *cobra.Command, args *SQLCmdArguments) {
_ = rootCmd.Flags().IntP(removeControlCharacters, "k", 0, localizer.Sprintf("%s Remove control characters from output. Pass 1 to substitute a space per character, 2 for a space per consecutive characters", "-k [1|2]"))
rootCmd.Flags().BoolVarP(&args.EchoInput, "echo-input", "e", false, localizer.Sprintf("Echo input"))
rootCmd.Flags().IntVarP(&args.QueryTimeout, "query-timeout", "t", 0, "Query timeout")
rootCmd.Flags().BoolVarP(&args.EnableColumnEnryption, "enable-column-encryption", "g", false, localizer.Sprintf("Enable column encryption"))
}

func setScriptVariable(v string) string {
Expand Down Expand Up @@ -680,6 +682,7 @@ func setConnect(connect *sqlcmd.ConnectSettings, args *SQLCmdArguments, vars *sq
connect.ExitOnError = args.ExitOnError
connect.ErrorSeverityLevel = args.ErrorSeverityLevel
connect.DedicatedAdminConnection = args.DedicatedAdminConnection
connect.EnableColumnEnryption = args.EnableColumnEnryption
}

func isConsoleInitializationRequired(connect *sqlcmd.ConnectSettings, args *SQLCmdArguments) bool {
Expand Down
20 changes: 11 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@ require (
github.com/docker/go-connections v0.4.0
github.com/golang-sql/sqlexp v0.1.0
github.com/google/uuid v1.3.0
github.com/microsoft/go-mssqldb v1.5.0
github.com/microsoft/go-mssqldb v1.6.0
github.com/opencontainers/image-spec v1.0.2
github.com/peterh/liner v1.2.2
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
golang.org/x/sys v0.8.0
golang.org/x/text v0.9.0
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.11.0
golang.org/x/text v0.12.0
golang.org/x/tools v0.6.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v0.8.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
Expand All @@ -39,7 +41,7 @@ require (
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/mux v1.8.0 // indirect
Expand All @@ -66,9 +68,9 @@ require (
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/net v0.14.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 0a4cd19

Please sign in to comment.