我目前有一个与https://docs.microsoft.com/en-us/sql/relational-databases/security/encryption/configure-always-encrypted-keys-using-powershell?view=sql-server-ver15中描述的脚本类似的脚本,但是这个脚本使用的是Powershell5,在我们的azure-devops环境中的linux代理上,它对我是不可用的。正因为如此,我们无法使用大多数azure-sql命令。是否有替代这些sqlserver模块cmdlet的方法。
发布于 2021-04-08 05:07:45
推荐的替代方案是使用云控制台,但您也可以使用linux powershell,如下所示:
我不能保证这一切都能正常工作,但该特定命令只创建一个SqlColumnMasterKeySettings对象,该对象包含有关列主键位置的信息。您可能只需要手动创建一个,但您需要知道确切的值。我建议先在windows机器上运行它,看看您的环境应该有什么值。
# On Windows [Optional]
$cmkSettings = New-SqlAzureKeyVaultColumnMasterKeySettings -KeyURL $akvKey.Key.Kid
$cmkSettings | Format-List KeystoreProviderName,KeyPath
KeystoreProviderName : # Take these strings
KeyPath : # And use them in your script on linux
# Now on Linux, using the values above:
$cmkSettings = [Microsoft.SqlServer.Management.PowerShell.AlwaysEncrypted.SqlColumnMasterKeySettings]::new("YourKeystoreProviderName","YourKeyPath")
New-SqlColumnMasterKey -Name 'CMK1' -InputObject $database -ColumnMasterKeySettings $cmkSettings
# Success!键设置属性只是保存到您的SQL实例中的字符串,所以这应该可以很好地工作。更难的部分是认证到Azure以从你的主密钥创建密钥,但你可以尝试导入桌面版本的命令,如下所示:
# Start a NEW powershell session without the sqlserver module:
pwsh
# Get the module directory:
$d = (Get-Item (Get-Module SqlServer).path).DirectoryName
# Import the desktop version of these assemblies:
Import-Module "$d/Microsoft.SqlServer.Diagnostics.Strace.dll"
Import-Module "$d/Microsoft.SqlServer.Management.PSSnapins.dll"
Import-Module "$d/Microsoft.SqlServer.Management.AzureAuthenticationManagement.dll"
Import-Module "$d/Microsoft.SqlServer.Management.AlwaysEncrypted.Types.dll"
# Then import the module normally (there will be errors - you can ignore these)
Import-Module SqlServer
# Now you may be able to authenticate to Azure to generate new keys:
# Required to generate new keys
# NOTE: -Interactive fails on linux
Add-SqlAzureAuthenticationContext -ClientID "YourID" -Secret "YourSecret" -Tenant "YourTenant"
# Create a key using your master key:
New-SqlColumnEncryptionKey -Name 'CEK1' -InputObject $database -ColumnMasterKey 'CMK1'这在我安装的centos7/pwsh7.1.3上有效-确保你有SqlServer版本的21.1.18245 (目前只有10天),因为很多新的sql命令都移植到了pwsh7.1中。
https://stackoverflow.com/questions/66988342
复制相似问题