「Vault」:修訂間差異

出自Gea-Suan Lin's Wiki
跳至導覽 跳至搜尋
本頁面具有訪問限制。如果您看見此訊息,這代表您沒有訪問本頁面的權限。
 
(未顯示同一使用者於中間所作的 9 次修訂)
行 11: 行 11:
== AppRole<ref>{{Cite web |url=https://learn.hashicorp.com/vault/identity-access-management/approle |title=AppRole Pull Authentication |language=en |accessdate=2020-07-29}}</ref> ==
== AppRole<ref>{{Cite web |url=https://learn.hashicorp.com/vault/identity-access-management/approle |title=AppRole Pull Authentication |language=en |accessdate=2020-07-29}}</ref> ==


===  建立 ===
以下的指令可以透過Vault的CLI操作,會需要設定對應的Endpoint(環境變數<code>VAULT_ADDR</code>)與token(環境變數<code>VAULT_TOKEN</code>)。
 先 產生AppRole
 
===  啟用 ===
 
 先 啟用AppRole:
 
<syntaxhighlight lang="bash">
vault auth enable approle
</syntaxhighlight>
 
=== TTL設定 ===
 
你可能會想要改掉預設的TTL,目前的預設是30天(768h),這邊設定為100年


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
vault write auth/approle/role/example_role token_policies="example_policy1,example_policy2"
vault read sys/auth/approle/tune
vault write sys/auth/approle/tune max_lease_ttl=876000h
vault write sys/auth/approle/tune default_lease_ttl=876000h
vault read sys/auth/approle/tune
</syntaxhighlight>
</syntaxhighlight>


  如果還在測試而沒有HTTPS的情況下,可以加上<code>-address=http://127.0.0.1:8200/</code>(或是對應的位置)
=== 建立 ===
 
先產生AppRole


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
vault write -address=http://127.0.0.1:8200/ auth/approle/role/example_role token_policies="example_policy1,example_policy2"
vault write auth/approle/role/example_role token_policies="example_policy1,example_policy2"
</syntaxhighlight>
</syntaxhighlight>


行 36: 行 52:
</syntaxhighlight>
</syntaxhighlight>


 其中的<code>secret_id</code>就是我們要的,而<code>secret_id_accessor</code>則可以拿來renew用(但比較少用到)。
 其中 輸出 的<code>secret_id</code>就是我們要的,而<code>secret_id_accessor</code>則可以拿來renew用(但比較少用到)。


=== 使用 ===
=== 使用 ===

於 2021年6月30日 (三) 07:44 的最新修訂

Vault是一套由HashiCorp開發的密碼管理軟體。

概要

Vault可以拿來存放各類credential資料,像是Key或是Password,這個方法比Twelve-Factor App methodology所提到的方法(利用環境變數)安全許多。

安裝

AppRole[1]

以下的指令可以透過Vault的CLI操作,會需要設定對應的Endpoint(環境變數VAULT_ADDR)與token(環境變數VAULT_TOKEN)。

啟用

先啟用AppRole:

vault auth enable approle

TTL設定

你可能會想要改掉預設的TTL,目前的預設是30天(768h),這邊設定為100年:

vault read sys/auth/approle/tune
vault write sys/auth/approle/tune max_lease_ttl=876000h
vault write sys/auth/approle/tune default_lease_ttl=876000h
vault read sys/auth/approle/tune

建立

先產生AppRole:

vault write auth/approle/role/example_role token_policies="example_policy1,example_policy2"

接下來是讀取role-id

vault read auth/approle/role/example_role/role-id

產生對應的secret-id

vault write -f auth/approle/role/example_role/secret-id

其中輸出的secret_id就是我們要的,而secret_id_accessor則可以拿來renew用(但比較少用到)。

使用

這邊使用HTTPie產生JSON request:

http https://vault.example.com/v1/auth/approle/login role_id=x secret_id=y

回傳的client_token就可以拿來使用。

相關連結

參考文獻

  1. AppRole Pull Authentication. [2020-07-29] (English). 

外部連結