【问题标题】:Bigquery Javascript UDF using storage and kms librariesBigquery Javascript UDF 使用存储和 kms 库
【发布时间】:2019-11-15 13:25:14
【问题描述】:

我正在尝试开发用于 AES 解密的 Bigquery Javascript UDF。 用于 AES 加密的密钥被加密并存储在 GCS 中。 我开发了一个 Javascript 代码,它将执行以下步骤:

  1. 从 GCS 读取具有 AES 密钥加密值的文件
  2. 使用 kms 密钥环和 kms 密钥解密 AES 密钥值
  3. 使用此密钥进行 AES 解密。

我正在使用以下语句获取存储和 kms 库:

const Storage = require('@google-cloud/storage'); const kms = require('@google-cloud/kms');

当我必须从 Bigquery UDF 调用相同的功能时,我将如何进行 确定这些库可用吗? (我不想在 Bigquery UDF 中硬编码 AES 密钥)

我在 Bigquery UDF 定义中看到了 [OPTIONS (library = library_array)] 的选项,但我 不确定存储和 kms 集成需要哪些特定的 .js 文件?

代码 sn-p

const Storage = require('@google-cloud/storage');
const storage = new Storage.Storage();
const kms = require('@google-cloud/kms');
const client = new kms.KeyManagementServiceClient();
bucketName ="gs://testbucket"
const keyFile = storage.bucket(bucketName).file("key.enc");
'use strict';

  async function decrypt(ciphertext){
   const name=<replace with crypto-key-path>;
   const [result] = await client.decrypt({name, ciphertext});
   return Buffer.from(result.plaintext, 'base64').toString();
  }
   var key=saltFile.download(function(err, contents) { 
     key=decrypt(contents);
     key.then(function (value) {
            key = value.trim();
            console.log(value);     
        });
     return key;
   })

谢谢你, 阿努

【问题讨论】:

    标签: node.js encryption google-cloud-platform google-bigquery


    【解决方案1】:
    • 回答问题:您可以将密钥存储在 GCS 文件中,并通过将该文件作为附加 .js 导入来读取它。

    但是:

    • BigQuery UDF 无法调用外部 API,因此即使“@google-cloud/storage”导入成功,也无法运行和执行额外的 API 调用。

    【讨论】:

    • 您好 Felipe,感谢您的回复。我想知道是否有办法将 js 文件上传到存储桶并使用 OPTIONS (library = library_array) 指向它们。我对 AES.js 及其工作进行了相同的尝试。但是对于存储和 kms,js 文件中列出了许多其他依赖项,因此很难一一上传到谷歌云存储桶
    • 以防万一,您知道原生 BigQuery 加密功能吗?它们确实支持多种 AES 模式:cloud.google.com/bigquery/docs/reference/standard-sql/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    • 2020-04-05
    • 1970-01-01
    • 2019-07-08
    • 1970-01-01
    相关资源
    最近更新 更多