谷歌云的简单秘密商店

wisel的Python项目详细描述


明智-谷歌云KMS的简单秘密商店

概述

聪明是一个简单的秘密管理库。机密存储在加密的 谷歌云存储(GCS)存储桶中的表单。加密例程利用google 云的密钥管理存储(KMS)服务。一旦秘密被解密,它们就是 作为python中的dict()随时可用。

安装

pip3 install wisely

用法

配置

在您开始之前,Wisley需要一个简单的配置。为了, simplity,本文档假设您已经created a GCS bucket 用于秘密存储,也有created a KMS keyring and key

让我们熟悉一些配置所需的基本术语:

  • project\u id:谷歌云项目id

  • secret_path:gcs中机密文件的文件名

  • keyring\u id:kms keyring名称

  • crypto\u id:指定密钥环内的kms密钥名

  • location\u id:密钥环所在的google云区域

  • 存储桶名称:gcs存储机密的存储桶名称

  • mode:用于分析机密的方法。有效选项是KV、JSON或RAW

  • delim:处于模式kv时键/值的分隔符

    wisley.cfg


    明智的配置文件是一个简单的yaml文件。默认情况下,明智地 在~/.wisley中查找配置文件。基本结构是:

     [secret_name]
     project_id = my_google_project-10234
     secret_path = secrets.txt
     keyring_id = my_soooper_keyring
     crypto_id = the_key
     location_id = us-west1-a
     bucket_name = sooper-secret-bucket-12312321
     mode = kv
     delim = :
    

    如果存在{{< CD4>}配置节,则WISLY将首先加载这些部分。为了 例如,如果在你所有的秘密中都有一个共享的project_id,你可以 想在[global]中定义project_id

         [global]
         project_id = my_google_project-10234
    
         [secret_name_one]
         secret_path = secrets-one.txt
         keyring_id = my_soooper_keyring
         crypto_id = the_key_one
         location_id = us-west1-a
         bucket_name = sooper-secret-bucket-12312321
    
         [secret_name_two]
         secret_path = secrets-two.txt
         keyring_id = my_soooper_keyring
         crypto_id = the_key_two
         location_id = us-west1-a
         bucket_name = sooper-secret-bucket-12312321
    

    环境变量


    如果未定义配置选项,则明智地尝试收集 环境变量中所需的配置选项:

     WISELY_PROJECT_ID=my_google_project-10234
     WISELY_SECRET_PATH=secrets.txt
     WISELY_KEYRING_ID=my_soooper_keyring
     WISELY_CRYPTO_ID=the_key
     WISELY_LOCATION_ID=us-east1-a
     WISELY_BUCKET_NAME=sooper-secret-bucket-12312321
    

添加/更新机密配置

Wisley提供了一个简单的cli界面,允许添加机密配置:

wisley secret_name --path secrets.txt --project my_google_project-10234 \
        --keyring my_soooper_keyring --crypto the_key \
        --bucket sooper-secret-bucket-12312321 --location us-west1-a

同样,如果要更新单个机密配置,例如 更新bucket名称,只需添加--update参数:

wisley secret_name --update --bucket new-secret-bucket-121321

添加机密

机密文件可以是纯文本、键/值对或json。默认情况下,明智地 假设模式是键/值对。

例如:

    USER=joebob
    PASS=soopersecret321

或者,如果json:

    {"USER": "joebob", "PASS": "soopersecret321"}

机密文件也可以是纯文本,不会被明智地解析。

要添加新密码,只需运行:

    wisely encrypt secret_name cleartext-file.txt

一旦完成,加密文件将被加密并上载到指定的 地面军事系统桶。如果要更新加密的机密文件:

    wisely decrypt secret_name -o cleartext-file.txt

在脚本中使用

在脚本中明智地使用是非常容易的。有两种方法可以实例化Wisley

您可以通过所有必需的配置选项:

    from wisely import Wisely

    project_id = 'my_google_project-10234'
    secret_path = 'secrets.txt'
    keyring_id = 'my_soooper_keyring'
    crypto_id = 'the_key'
    location = 'us-west1-a'
    bucket_name = 'sooper-secret-bucket-12312321'
    mode = 'json'

    wise = Wisley(
        project_id=project_id, secret_path=secret_path, keyring_id=keyring_id,
        crypto_id=crypto_id, location=location, bucket_name=bucket_name,
        mode=mode)

    secrets = wise.decrypt()

    user = secrets['USER']
    pass = secrets['PASS']

    print('User: {}, Pass: {}'.format(user, pass))

或者,如果正确定义了所有环境变量:

    from wisely import Wisely

    wise = Wisely()
    secrets = wise.decrypt()

    user = secrets['USER']
    pass = secrets['PASS']

    print('User: {}, Pass: {}'.format(user, pass))

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaJSonarray不会从SeekBar读取double   使用另一个类从Java中的2D数组打印用户输入   java ClassNotFoundException的原因   spring调用两个方法以返回Java中的不同页面   httpurlconnection Java禁止的代码错误,但浏览器错误(2)   java画布矩阵转换   java:在另一个java映射中使用“Map”作为值   java“未找到用于解密的证书”(Apache CXF,WSSecurity)   java如何查看JTable中选择的行   java在没有xmlwrappers的情况下重复xml元素序列集   java将垂直直方图打印到控制台   java Spring JDBCTemplate:构造不带特殊字符的JSON   java PayPal RestApi获取用户信息