2017-03-01 66 views
2

我想注入一個帶有鹽的gpg密鑰。密鑰本身是在一個安全的支柱,而是提供了關鍵的附庸新安裝的GPG設置,我不得不把鑰匙插進一個文件,所以我有一些像使用一個安全的tmpfile與saltstack

import_gpg_key: 
    file.managed: 
    - name: /tmp/secret.key 
    - contents_pillar: gpg:secret_key 
    - user: me 
    - group: me 
    - mode: 0600 
    cmd.run: 
    - name: gpg --batch --import /tmp/secret.key 
    - runas: me 
    - unless: gpg --list-secret-keys {{ pillar['gpg']['default_key_fingerprint'] }} 

## 
# FIXME Is there no way to avoid 
# writing the secret to disk, or 
# at least use a secure tmpfile? 
/tmp/secret.key: 
    file.absent 

正如我所說的在我的評論中,我寧願不把祕密寫在磁盤上,但如果這是不可避免的,是否有一種方法可以使用安全的tmp文件和隨機路徑,這是不容易猜測的?

回答

1

有一個module that allows gpg imports from text你可能會使用module state

未經測試的草圖稱之爲:

import_gpg_key: 
    module.run: 
    - name: gpg.import_key 
    - user: me 
    - kwargs: 
     text: {{ pillar['gpg']['secret_key'] }} 
    - unless: gpg --list-secret-keys {{ pillar['gpg']['default_key_fingerprint'] }} 

恐怕unless不在這裏工作了(至少它在文檔中未提及) - 但你可以使用另外的cmd.runwatch_in這可能會成爲這個狀態的一個條件。