Skip to content

release-v0.3.6

Choose a tag to compare

@mingqing mingqing released this 25 May 06:04
· 90 commits to main since this release
22c363d

[0.3.6] - 2024-05-25

Added

实现基于 OPA 的鉴权方案

在使用本方案时,存在以下三种数据:

  1. 权限鉴权模型:由开发人员设计编写,使用 rego 语言;

    • 在各微服务内嵌路径:internal/security/auth.rego
    • 可配置使用外部文件:"security.authorization.opa_native.policy.auth_file" 参数决定
    • 数据源也可来自外部服务
  2. 权限验证数据:由管理人员添加补充,格式微 envoy rbac 数据结构,使用 yaml 格式;

    • 在各微服务内嵌路径:internal/security/data.yaml
    • 可配置使用外部文件:"security.authorization.opa_native.policy.data_file" 参数决定
    • 数据源也可来自外部服务
  3. 用户输入数据:由用户登录后产生的数据,提出关键字根据模型对比,是否允许。

    • 由服务框架自动转换为兼容 opa-envoy-plugin 的 input 结构

当前仅能实现根据 "http method"、"http header"、"http url" 进行权限鉴定。具体使用见参考示例。

K8S 部署模版的优化

  • 变量的默认值

为变量 "KUBERNETES_LABEL_PREFIX", "KUBERNETES_PM2_UUID", "KUBERNETES_CLUSTER_DOMAIN" 设置默认值。

  • 在部署模版添加 tls secret 配置
secretGenerator:
- name: git-lmq-io-tls
  files:
  - tls.crt=config/tls/git.lmq.io.pem
  - tls.key=config/tls/git.lmq.io.key
  type: "kubernetes.io/tls"
  options:
    disableNameSuffixHash: true
  • 添加安全加固策略
......
        securityContext:
          allowPrivilegeEscalation: false
          readOnlyRootFilesystem: true
          capabilities:
            drop:
            - ALL
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext:
        seccompProfile:
          type: RuntimeDefault
        runAsGroup: 65534
        runAsUser: 65534
        runAsNonRoot: true
......

Fixed

配置项 "independent" 中存在 "time.Duration" 类型无法解析

类似如下错误:

>> precheck environment
>> generation release version
>> generation assets to static code
>> generation code from proto files
Using config file: config/app-dev-local.yaml
Start server err: 1 error(s) decoding:

* 'storage_configs[0].write_timeout' expected type 'time.Duration', got unconvertible type 'string', value: '10s'
exit status 1
make: *** [run] Error 1

这个因为 "independent" 使用了全局单独的 mapstructure.Decode 解析,默认仅支持基础类型(bool, int, string),这里通过自定义解析器,添加 "time.Duration" 类型即可,类似viper的实现。

Changed

配置存储在 etcd 更改为 json 格式

跟 k8s crd 类似,不存储为 yaml 避免第三方类库引入,json 格式需压缩。

请求头 “x-tr-request-id" 响应传递行为

如果客户端主动设置了 "x-tr-request-id" 请求头:

  1. 当响应成功时,不能返回客户端设置的 "x-tr-request-id" 值;
  2. 当响应失败时,返回了客户端设置的 "x-tr-request-id" 值,变更为忽略客户端设置值。

默认生成的 swagger 文档使用了驼峰格式

// DemoRequest Demo 方法请求可使用的接口参数
type DemoRequest struct {
    state         protoimpl.MessageState
    sizeCache     protoimpl.SizeCache
    unknownFields protoimpl.UnknownFields

    UserName string             `protobuf:"bytes,3,opt,name=user_name,json=userName,proto3" json:"user_name,omitempty"`
}

在 "protoc-gen-openapiv2" 设置参数 "json_names_for_fields=false" 以使用 "protobuf:name=" 的值替代默认 "protobuf:json=" 的内容来生成 swagger 文档属性。

grpc-ecosystem/grpc-gateway#3594

静态 admin webroot 服务默认生成 index.html 文件

为解决 go embed admin:* 空目录问题,由生成原文件 "public/admin/.not-empty-dir.txt" 变更为 "public/admin/index.html" 文件。