Azure Key Vault Chef 食谱

詹姆斯陈

我是编码新手,但正在学习。我希望有人可以帮助查看我在网上找到的这个 ruby​​ 代码,它有助于从 Azure Key Vault 中获取秘密。我会把它贴在下面。我只需要帮助澄清每个代码块所指的内容。

不确定下面的代码指的是什么。我知道它们是属性,但它们是如何工作的?

node.default['azurespn']['client_id'] = azurespn[node.environment]['client_id']
node.default['azurespn']['tenant_id'] = azurespn[node.environment]['tenant_id']
node.default['azurespn']['client_secret'] = azurespn[node.environment]['client_secret']

食谱:

# retrieve the secret stored in azure key vault using this chef recipe
 include_recipe 'microsoft_azure'
 azurespn = data_bag_item('azurespn', 'azurespnenv')
 node.default['azurespn']['client_id'] = azurespn[node.environment]['client_id']
 node.default['azurespn']['tenant_id'] = azurespn[node.environment]['tenant_id']
 node.default['azurespn']['client_secret'] = azurespn[node.environment]['client_secret']
 spn = {
 'tenant_id' => "#{node['azurespn']['tenant_id']}",
 'client_id' => "#{node['azurespn']['client_id']}",
 'secret' => "#{node['azurespn']['client_secret']}"
 }
 secret = vault_secret("#{node['windowsnode']['vault_name']}", "#{node['windowsnode'] 
['secret']}", spn)
 file 'c:/jenkins/secret' do
 action :create
 content "#{secret}"
 rights :full_control, 'Administrators', :one_level_deep => true
 end
 Chef::Log.info("secret is '#{secret}' ")
seshadri_c

问:不确定下面的代码指的是什么。我知道它们是属性,但它们是如何工作的?

正如您所理解的,这段代码正在设置一些节点属性。这些属性的值是从数据包中读取的(在上一行中),即azurespn = data_bag_item('azurespn', 'azurespnenv')

现在azurespn变量包含数据包 item 的内容azurespnenv为了更好地理解,请尝试knife data bag show azurespn azurespnenv. 我创建了一个虚拟数据包结构只是为了说明。

dev:
  client_id:     win10
  client_secret: topsecret
  tenant_id:     testtenant
qa:
  client_id:     ubuntu
  client_secret: changeme
  tenant_id:     footenant
id:       azurespnenv

在这个数据包中,我们有两个环境 -devqa.

让我们以 1 行为例:

node.default['azurespn']['client_id'] = azurespn[node.environment]['client_id']

因此,azurespn[node.environment]['client_id']client_id根据该节点的 Chef 环境选择适当的。翻译成:

node.default['azurespn']['client_id'] = azurespn['dev']['client_id']
#=> 'win10'
node.default['azurespn']['client_id'] = azurespn['qa']['client_id']
#=> 'ubuntu'

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章