代码之家  ›  专栏  ›  技术社区  ›  Ganesh Satpute

无服务器白名单不同的IP到不同的功能

  •  0
  • Ganesh Satpute  · 技术社区  · 5 年前

    如果我必须将给定的无服务器部署中的所有函数都列为白名单,那么我可以使用这样的方法。

    provider:
      name: aws
      ...
      resourcePolicy:
        - Effect: Deny
          Principal: '*'
          Action: execute-api:Invoke
          Resource:
            - execute-api:/*/*/*
          Condition:
            NotIpAddress:
              aws:SourceIp:
                - '141.206.243.10/32' # Teradata IP
                - '142.0.162.0/32'    # Eloqua IPs
        - Effect: Allow
          Principal: '*'
          Action: execute-api:Invoke
          Resource:
            - execute-api:/*/*/*
    

    例如,在我的场景中,我有两个api

    1. 获取员工

    我想限制 GetEmployees 在某个IP范围内可用 1.2.3.x/24 PutEmployees 4.5.6.x/24 .

    0 回复  |  直到 5 年前
        1
  •  1
  •   K Mo    5 年前

    资源策略附加到API网关,而不是单独的路径,因此每个API网关只能有一个资源策略文档。

    但是,由于策略中的规则是一组规则,因此可以使用以下格式为不同阶段、路径和方法创建单独的规则:

    execute-api:/{stage}/{path}/{method}
    

    所以你需要在你的资源策略中,更具体一点。

    provider:
      name: aws
      ...
      resourcePolicy:
        - Effect: Allow
          Principal: '*'
          Action: execute-api:Invoke
          Resource:
            - execute-api:/*/*/*
        - Effect: Deny
          Principal: '*'
          Action: execute-api:Invoke
          Resource:
            - execute-api:/*/GetEmployees/*
          Condition:
            NotIpAddress:
              aws:SourceIp:
                - '1.2.3.x/24'
        - Effect: Deny
          Principal: '*'
          Action: execute-api:Invoke
          Resource:
            - execute-api:/*/PutEmployees/*
          Condition:
            NotIpAddress:
              aws:SourceIp:
                - '4.5.6.x/24'