如何通过ARM模板在Azure存储账户上添加加密AKV

如何解决如何通过ARM模板在Azure存储账户上添加加密AKV

我正在尝试在存储帐户 (ADLS gen2) 上添加加密。并使用带有服务主体的 ARM 模板(通过门户它工作正常)。 我发现的代码很简单,就像下面要添加到 StorageAccount 的加密部分的 snipet 一样。

"keySource": "Microsoft.Keyvault","keyvaultproperties": {
    "keyvaulturi": "https://akv-***.vault.azure.net","keyname":"storageKey","keyversion": "c355****68e52361156"                    
}

但是它没有这样做,给出错误

状态消息:由于身份验证问题,操作失败 在密钥保管库上。更多 信息,(代码:KeyVaultAuthenticationFailure)

我的 AKS 在另一个资源组中,而我的存储帐户在不同的资源组中(按照公司标准)。这是原因吗?那我该怎么办?

或者我读过的几篇文章建议在“密钥保管库”上添加访问权限以获取、包装和解包存储帐户的权限。我对此表示怀疑,因为我可以手动将同一密钥的加密添加到存储帐户。

会感谢任何帮助吗?

解决方法

当我重现并发现 AKV 和存储帐户应该在同一资源组和同一区域中时,只有您才能在存储帐户上添加 AKV。

将您的 Azure 存储帐户配置为通过 Azure Key Vault 使用客户管理的密钥,然后指定要与存储帐户关联的密钥。

第 1 步:将此 ARM 模板保存在您的 VS 代码中,并使用任意名称保存该文件。

这是一个完整且功能齐全的 ARM 模板,您需要部署 2 次才能对其进行完全配置。第一次运行将创建 Key Vault 和存储帐户。然后,您需要在 Key Vault 中手动创建密钥并再次运行部署以让它完成其余的工作。

此模板使用嵌套部署将带有关键信息的存储帐户的配置与创建 2 个资源分开,以获得完整示例。

模板

    {
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#","contentVersion": "1.0.0.0","parameters": {
    "keyName": {
      "type": "string","defaultValue": "storage-enc-test"
    },"keyVersion": {
      "type": "string","defaultValue": ""
    },"location": {
      "type": "string","defaultValue": "[resourceGroup().location]"
    },"configureEncryptionKey": {
      "type": "bool","defaultValue": false
    }
  },"variables": {
    "uniqueResourceNameBase": "simplekeyvalut7735"
  },"resources": [
    {
      "condition": "[not(parameters('configureEncryptionKey'))]","type": "Microsoft.KeyVault/vaults","name": "[variables('uniqueResourceNameBase')]","apiVersion": "2016-10-01","location": "[parameters('location')]","properties": {
        "sku": {
          "family": "A","name": "standard"
        },"tenantId": "[subscription().tenantid]","accessPolicies": [],"enableSoftDelete": true,"enablePurgeProtection": true
      },"dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts',variables('uniqueResourceNameBase'))]"
      ]
    },{
      "type": "Microsoft.Storage/storageAccounts","sku": {
        "name": "Standard_LRS","tier": "Standard"
      },"kind": "Storage","apiVersion": "2019-06-01","identity": {
        "type": "SystemAssigned"
      },"properties": {
        "supportsHttpsTrafficOnly": true
      },"dependsOn": []
    },{
      "condition": "[parameters('configureEncryptionKey')]","type": "Microsoft.Resources/deployments","apiVersion": "2019-07-01","name": "updateStorageAccount","dependsOn": [
        "[resourceId('Microsoft.KeyVault/vaults',variables('uniqueResourceNameBase'))]"
      ],"properties": {
        "mode": "Incremental","template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#","contentVersion": "0.1.0.0","resources": [
            {
              "type": "Microsoft.KeyVault/vaults/accessPolicies","name": "[concat(variables('uniqueResourceNameBase'),'/add')]","apiVersion": "2019-09-01","properties": {
                "accessPolicies": [
                  {
                    "tenantId": "[subscription().tenantid]","objectId": "[reference(resourceId('Microsoft.Storage/storageAccounts',variables('uniqueResourceNameBase')),'2019-06-01','full').identity.principalId]","permissions": {
                      "keys": [
                        "wrapkey","unwrapkey","get"
                      ],"secrets": [],"certificates": []
                    }
                  }
                ]
              }
            },{
              "type": "Microsoft.Storage/storageAccounts","sku": {
                "name": "Standard_LRS","tier": "Standard"
              },"identity": {
                "type": "SystemAssigned"
              },"properties": {
                "encryption": {
                  "services": {
                    "file": {
                      "enabled": true
                    },"blob": {
                      "enabled": true
                    }
                  },"keySource": "Microsoft.Keyvault","keyvaultproperties": {
                    "keyvaulturi": "[reference(resourceId('Microsoft.KeyVault/vaults','2016-10-01','full').properties.vaultUri]","keyname": "[parameters('keyName')]","keyversion": "[parameters('keyversion')]"
                  }
                }
              },"dependsOn": [
                "[resourceId('Microsoft.KeyVault/vaults/accessPolicies',variables('uniqueResourceNameBase'),'add')]"
              ]
            }
          ]
        }
      }
    }
  ]
}

我选择了一个变量。

"uniqueResourceNameBase": "simplekeyvalut7735" 用于根据您的选择提供存储帐户和 Key Vault 的名称,您可以编辑上述代码并分配其他名称。

第 2 步:输入以下命令以在您的资源组中部署您的模板。

New-AzResourceGroupDeployment -name testdeployment -ResourceGroupName v-rahul********* -TemplateFile C:\Users\v-rash**\venv\Lib\site-packages\pandas\io\azuredeploy.json

enter image description here

第 3 步:如第 1 步所述,再次运行上述命令一次。

第 4 步:手动创建您的密钥。

第 5 步:最后,在将特殊标志 configureEncryptionKey 设置为 true 的情况下运行,以在存储帐户上运行配置步骤。

New-AzResourceGroupDeployment -name testdeployment -ResourceGroupName v-ra###M## -TemplateFile C:\Users\v-rash**\venv\Lib\site-packages\pandas\io\azuredeploy.json -configureEncryptionKey $true -Verbose

您可能会在设置密钥库密钥名称时遇到此错误。我已经手动设置了 storage-enc-test 并再次运行上述命令。

enter image description here

结果:像这样触发第二次部署:

enter image description here

如果我查看 Azure 门户,我们可以看到密钥已正确配置。

enter image description here

参考:https://www.codeisahighway.com/how-to-use-customer-managed-keys-with-azure-key-vault-and-azure-storage-encryption-using-arm-template/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res