shan18 / Flash

Create, train and deploy AI models without writing code
https://shan18.github.io/Flash/
MIT License
21 stars 7 forks source link

Overprivilege analysis of IAM policy in your application #17

Closed dattapubali closed 4 months ago

dattapubali commented 5 months ago

We are submitting this issue to notify you of an IAM policy analysis we conducted based on an October 2021 copy of the shan18/Flash repository. We recognize that your application has continued to change since then, but wanted to share our results with you.

Analyzing inference/serverless.yml in https://github.com/shan18/Flash/tree/43868e9, we determined that the use of the s3:*wildcard permission in the provider-level iamRoleStatements definition resulted in over-privileged functions. By looking at the API calls that were actually being made by your application at that time, we determined that the following changes would reduce unnecessary privilege while still permitting the application to function:

Note: the following policy changes use the https://github.com/functionalone/serverless-iam-roles-per-function serverless plugin to create detailed per-function iam policies.

High level overview: The check and inference functions only need s3:GetObject permissions and the clean function needs s3:GetObject, s3:PutObject, and s3:DeleteObject permissions.

…
functions:
  check:
    handler: handler.check
    module: check
    memorySize: 3008 # MB
    timeout: 30 # seconds
    events:
      - http:
          path: check
          method: post
          cors: true
    iamRoleStatements:
      - Effect: Allow
        Action:
          - "s3:GetObject"
        Resource:
          - arn:aws:s3:::${self:custom.secrets.bucket}/*
  inference:
    handler: handler.inference
    module: infer
    memorySize: 3008 # MB
    timeout: 30 # seconds
    events:
      - http:
          path: inference
          method: post
          cors: true
    iamRoleStatements:
      - Effect: Allow
        Action:
          - "s3:GetObject"
        Resource:
          - arn:aws:s3:::${self:custom.secrets.bucket}/*
  clean:
    handler: handler.clean
    module: clean
    memorySize: 3008 # MB
    timeout: 30 # seconds
    events:
      - http:
          path: clean
          method: get
          cors: true
      - schedule: rate(2 hours)
    iamRoleStatements:
      - Effect: Allow
        Action:
          - "s3:GetObject"
          - "s3:PutObject"
          - "s3:DeleteObject"
        Resource:
          - arn:aws:s3:::${self:custom.secrets.bucket}/*
…

Your IAM policy was studied as part of a research project that was conducted jointly by researchers at the North Carolina State University and the University of Illinois at Urbana-Champaign. We developed an algorithm that leveraged graph reachability analysis to inspect privilege in serverless applications. This work has been accepted to appear at the 2024 Web Conference (Paper Title: “GRASP: Hardening Serverless Applications through Graph Reachability Analysis of Security Policies”). We will be discussing the results from our 2021 analysis of your application as part of this work, but will be sure to note that the policy has been updated since then.

If you’d like, we’d be happy to update our analysis to reflect the present state of your application. Do let us know if you have any thoughts or feedback.

Best, Pubali Datta (co-authors: Isaac Polinsky, Adam Bates, Will Enck)

shan18 commented 4 months ago

Thanks for reporting this issue and for the suggestions. I've updated the policies in serverless.yml