node.js - Bigquery Javascript UDF 使用存储和 kms 库
问题描述
我正在尝试开发用于 AES 解密的 Bigquery Javascript UDF。用于 AES 加密的密钥被加密并存储在 GCS 中。我开发了一个 Javascript 代码,它将执行以下步骤:
- 从 GCS 读取具有 AES 密钥加密值的文件
- 使用 kms 密钥环和 kms 密钥解密 AES 密钥值
- 使用此密钥进行 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 文件?
代码片段
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;
})
谢谢你,阿努
解决方案
- 要回答这个问题:您可以将密钥存储在 GCS 文件中,并通过将该文件作为附加 .js 导入来读取它。
但:
- BigQuery UDF 无法调用外部 API,因此即使“@google-cloud/storage”导入成功,它也无法运行和执行额外的 API 调用。
推荐阅读
- html - 如何使用 html 和 css 在页面上制作幻灯片
- vue.js - Nuxtjs + youtube 数据 api
- javascript - 如何检查 svg 路径是否具有与数组中的值匹配的类,如果是,则添加新类
- optaplanner - Optaplanner 中的容量设施位置
- angular - 无按钮角材质基本小吃吧
- python - 如何控制从自定义对象到 numpy.longdouble 的转换?
- angular - Angular/Typescript 不执行 for 循环
- angular - Angular 材质按钮在对话框打开时处于选择状态
- java - WeakReferenced 对象在调用 System.gc() 后不会被垃圾回收
- ruby-on-rails - 创建索引错误:索引表达式中的函数必须标记为 IMMUTABLE