Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[方案] 环境属性配置表达式及执行上下文 #391

Closed
wklken opened this issue Nov 16, 2021 · 4 comments
Closed

[方案] 环境属性配置表达式及执行上下文 #391

wklken opened this issue Nov 16, 2021 · 4 comments
Assignees
Milestone

Comments

@wklken
Copy link
Collaborator

wklken commented Nov 16, 2021

注册操作

operator 只是考虑到未来给接入系统留配置的入口, 但是前期及很长一段时间, 都不会用到, 甚至永久不会用; 基本都是固定类型, 固定前端交互, 最多timestamp的时候, 默认给用户展示between或lte;

所以, operators未来再考虑加入; 协议上先不暴露给接入系统, 用户也感知不到

[
    {
        "id": "biz_create",
        "name": "业务创建",
        "name_en": "biz_create",
        "description": "业务创建是...",
        "description_en": "biz_create is...",
        "type": "create",
        "related_resource_types": [],
        "related_environments": [
            {
                "type": "period_daily",   => 数据 两个值
                "operators": ["between"]    // 不需要填, 默认值
            },     
            {
                "type": "current_timestamp",   => 数据 单值/两个值
                "operators": ["lte/gte/between"]    // 必填, 三选一
            },
            {
                "type": "source_ip",      =>  数据 list
                "operators": ["ip_match"]  // 不需要填, 默认值
            },
            {
                "type": "source_system"    => 数据 list
                "operators": ["in"]  // 不需要填, 默认值
            },
            {
                "type": "is_secure_transport"   => 数据 bool
                "operators": ["eq"]  // 不需要填, 默认值
            }
        ],
        "version": 1
    }
]

注意, 如果未来需要加入周期性限制, 例如周一到周五的 20:10 - 21:20, 那么通过以下方式扩展

  • current_weekday in [1 2 3 4 5]
  • current_seconds < X AND current_seconds > Y (从 00:00到当前的秒数)
  • 暂时不考虑支持每月/每年;
  • 周期性的就不是绝对时间戳, 会涉及时区问题, 会涉及需要接入系统传入, 如何处理/统一时区需要考虑

后台表达式

注意资源的field是resource.system + . + resource.Type + . + resource.attr_name; 而环境属性是system + . + _bk_iam_env_ + . + attr_name, 环境属性的system是系统的system, 跟具体某个resource无关

{
    "AND": {
        "content": [
               {
                   "StringEquals": {
                         "bk_cmdb.host.id": ["123"]
                    }
               },

              // period_daily
               {
                   "Eq": {           // period daily
                         "bk_cmdb._bk_iam_env_.tz": " Asia/Shanghai"
                    }
               },
               {
                   "NumericLte": {           // period daily
                         "bk_cmdb._bk_iam_env_.hms": 220000
                    }
               },
               {
                   "NumericGte": {                
                         "bk_cmdb._bk_iam_env_.ts": 80000
                    }
               },

               // period_weekly
               {
                   "Eq": {           // period_weekly
                         "bk_cmdb._bk_iam_env_.tz": " Asia/Shanghai"
                    }
               },
               {
                   "In": {           // pperiod_weekly
                         "bk_cmdb._bk_iam_env_.weekday":  [ 1, 3, 5, 7]
                    }
               },

               // period_monthly
               {
                   "Eq": {           // period_monthly
                         "bk_cmdb._bk_iam_env_.tz": " Asia/Shanghai"
                    }
               },
               {
                   "In": {           // period_monthly
                         "bk_cmdb._bk_iam_env_.monthday":  [ 30, 31]
                    }
               },


               // current_timestamp
               {
                   "NumericLte": {                  => 如果只选择了Lte/Gte, 那么只有一个;
                         "bk_cmdb._bk_iam_env_.ts": 1637032667
                    }
               },
               {
                   "NumericGte": {                 => 如果是between, 二者都有
                         "bk_cmdb._bk_iam_env_.ts": 1637032667
                    }
               },

               // ip
               {
                    "IpMatch": {
                        "bk_cmdb._bk_iam_env_.ip": ["192.168.1.1", "9.168.1.1/16"]
                   }
               },
               // source system
               {
                    "StringEquals": {
                       "bk_cmdb._bk_iam_env_.system": ["bk_cmdb", "bk_job"]                         
                    }
               },
               // is secure
               { 
                   "Bool": {
                       "bk_cmdb._bk_iam_env_.is_secure_transport": true                       
                    }
               }
         ]
    }
}

注意: 开启环境属性, 不一定会有tz, 而是 有配置时间相关环境属性, 一定会配置tz

执行上下文

evalContext

{
    "bk_cmdb._bk_iam_env_": {
         "ts": 1637032693,     // 是一个int64
         "tz": "Asia/Shanghai",
         "hms": 093012,
         "system": "bk_job",
         "ip": "192.168.223.1",
         "is_secure_transport": true
    }
}

注意:

  • 第一期只做ts
  • 其他环境属性, 如果未来开启, 如果鉴权请求没有传递, 默认空值, 需要保证配置了环境属性的执行false

操作符支持

待合并: TencentBlueKing/bk-iam#34


TODO:

@zhu327
Copy link
Member

zhu327 commented Nov 19, 2021

image
原型上操作符本身是可以选择的, 不是固定的

@zhu327
Copy link
Member

zhu327 commented Nov 19, 2021

image
系统id不是必须的

@wklken wklken modified the milestones: Y2021M46, Y2021M47 Nov 22, 2021
@wklken
Copy link
Collaborator Author

wklken commented Nov 22, 2021

需要将 operator改成列表 => 测试

@wklken
Copy link
Collaborator Author

wklken commented Nov 22, 2021

done

TencentBlueKing/bk-iam#42

需要将 operator改成列表 => 测试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants