更新时间:2022-11-10 GMT+08:00
分享

cam.yaml解析

示例

metadata:
  description: This is an example application for FunctionGraph.
  author: Serverless team
  homePageUrl: https://www.huaweicloud.com/product/functiongraph.html
  version: 1.0.0
components:
  - name: helloworld
    type: Huawei::FunctionGraph::Function
    properties:
      region: cn-east-4
      codeUri: https://test-wkx.obs.cn-north-4.myhuaweicloud.com/helloworld.zip
      projectID: 0531e14952000f742f3ec0088c4b25cf
      handler: index.handler
      runtime: Python3.9
      memorySize: 256
      timeout: 60
      userData:
        key1: value1
        key2: value2
      encryptedUserData: '{"nonce": "ZEUOREFaiahRbMz+K9xQwA==", "header": "aGVhZGVy", "ciphertext": "SCxXsffvpU1BF2Ci8a2RedNQ", "tag": "a+EYRVPOsQ+YpQkMuFg1wA=="}'
      initializerTimeout: 30
      initializerHandler: index.init_handler
      strategyConfig:
        concurrency: 80
        concurrentNum: 20

详解

函数配置在cam.yaml的properties属性下,当前支持的函数配置详解如下:

参数

是否必须

是否更新

描述

region

调用函数所在region。

codeUri

函数代码地址。该值为函数代码包在OBS上的地址。

projectID

租户Project ID。

handler

函数执行入口。

runtime

FunctionGraph函数的执行环境支持Node.js6.10、Python2.7、Python3.6、PHP7.3、Java8、Node.js 8.10、C#.NET Core 2.0、C#.NET Core 2.1。

Python2.7: Python语言2.7版本。

Python3.6: Python语言3.6版本。

PHP7.3: Php语言7.3版本。

Java8: Java语言8版本。

Node.js6.10: Nodejs语言6.10版本。

Node.js8.10: Nodejs语言8.10版本。

C#(.NET Core 2.0): C#语言2.0版本。

C#(.NET Core 2.1): C#语言2.1版本。

C#(.NET Core 3.1): C#语言3.1版本。

Custom: 自定义运行时。

memorySize

函数内存,单位M。

枚举值:

128、256、512、768、1024、1280、1536、1792、2048、2560、3072、3584、4096

timeout

函数运行超时时间,单位秒,范围3~900秒。

userData

用户自定义的name/value信息,在函数中使用的参数。

encryptedUserData

用户自定义的name/value信息,用于需要加密的配置。

initializerTimeout

初始化超时时间,超时函数将被强行停止,范围1~300秒。

initializerHandler

函数初始化入口,规则:xx.xx,必须包含“. ”。 举例:对于node.js函数:myfunction.initializer,则表示函数的文件名为myfunction.js,初始化的入口函数名为initializer。

concurrentNum

函数单实例并发数。

concurrency

单函数最大实例数,0禁用函数,-1无限制,例100,该函数最大实例数100(普通实例+预留实例)。

  1. 当前cam.yaml不支持VPC、委托、磁盘挂载和动态内存配置的更新,如果函数需要使用VPC、委托或者磁盘挂载和动态内存请在函数界面手动配置,在使用函数更新流水线时会保留VPC、委托、磁盘挂载和动态内存配置,不会覆盖掉。
  2. 为了避免在cam.yaml中明文显示函数的加密配置-encryptedUserData,该CICD使用了AES对称加密的GCM模式对encryptedUserData明文内容进行加密,加密输出配置为cam.yaml中encryptedUserData项对应的值。在functions仓库和“函数更新流水线”中encryptedUserData的值以密文传输,在最后部署更新函数时解密更新,所以在执行“函数更新流水线”时需提供AES加密时使用的Key。示例如下:

    encryptedUserData明文:

    '{"password":"123"}'

    使用AES-GCM加密后:

    {"nonce": "ZEUOREFaiahRbMz+K9xQwA==", "header": "aGVhZGVy", "ciphertext": "SCxXsffvpU1BF2Ci8a2RedNQ", "tag": "a+EYRVPOsQ+YpQkMuFg1wA=="},其中ciphertext为加密后的密文。

AES加密使用的Key需妥善保管

Python AES-GCM使用示例:https://pycryptodome.readthedocs.io/en/latest/src/cipher/modern.html?highlight=GCM#gcm-mode

AES-GCM加密脚本如下:

import json
from base64 import b64encode
from Crypto.Cipher import AES
import sys

if __name__ == '__main__':
    key = sys.argv[1].encode()
    data = sys.argv[2].encode()
    header = b"header"
    cipher = AES.new(key, AES.MODE_GCM)
    cipher.update(header)
    ciphertext, tag = cipher.encrypt_and_digest(data)
    json_k = ['nonce', 'header', 'ciphertext', 'tag']
    json_v = [b64encode(x).decode('utf-8') for x in
              [cipher.nonce, header, ciphertext, tag]]
    result = json.dumps(dict(zip(json_k, json_v)))
    print(result)

使用方式为在ECS云服务器上执行如下命令:

python3 aes_gcm_encrypt_tool.py "16个字节的key" '{"password":"123"}',在ECS云服务器上执行。

分享:

    相关文档

    相关产品