Skip to content

Production AWS permissions #588

Closed
Closed

Description

@gjolund

In the docs you mention that the scope of IAM admin user permissions is not locked down due to the rapid dev pace of the framework. However using a super admin in production is just the kind of thing this framework was intended to solve by enforcing AWS best practices from the start.

Has there been any recent work done to nail down the scope of permissions needed to use serverless in a prod environment? Using a super user is a non starter at most shops, and a huge security vulnerable everywhere else.

Activity

  1. added this to the v0.5 milestone on Feb 10, 2016
  2. dherault commented on Mar 3, 2016

    @dherault
    Contributor

    👍 #726

  3. eahefnawy commented on Mar 4, 2016

    @eahefnawy
    Contributor

    Serverless is now at a Beta status, so we haven't really made a thorough investigation on that front.

    @doapp-ryanp @Nopik and @erikerikson I think you guys are working in an Enterprise environment. If you guys have time could you please share some thoughts on how you handle production permissions so we can add it to the docs? 😊

  4. modified the milestones: v0.6, v0.5 on Mar 4, 2016
  5. swennemans commented on Mar 4, 2016

    @swennemans

    Also very interested in this. At the very least I would be interested to get a quick explanation how to change user permissions. From the documentation:

    This should be done from the AWS CloudFormation UI, behind a user that has 2FA enabled and a secure password. All the Serverless tooling has a -c, --noExeCf option that will simply update your CloudFormation file, which can then be executed in the UI.

    This is a lack of knowledge from my end, but I'm not sure how I would achieve this. Would I upload the created template from _meta/resources/. in the CloudFormation UI and change the policy in this UI? Specifically in this part:

    image

    Taken for granted that the PowerUser policy would be sufficient, I've added the according policy. However, this will result in an error: Action not allowed by stack policy.

    Could someone give me quick pointer?

    The role of s-resources-cf.json?

    I have specific rules in my s-resources-cf.json eg:

     "Statement": [
                .....
                {
                  "Effect": "Allow",
                  "Action": [
                    "dynamodb:Query"
                  ],
                  "Resource": "arn:aws:dynamodb:${region}:*:table/${project}-videos-${stage}/index/*"
                },
                {
                  "Effect": "Allow",
                  "Action": [
                    "dynamodb:GetItem",
                    "dynamodb:PutItem"
                  ],
                  "Resource": "arn:aws:dynamodb:${region}:*:table/${project}-users-${stage}"
                },
                .....
    

    But from what i understand, this in combination with Administrator keys isn't a safe solution. Is this correct?

  6. erikerikson commented on Mar 4, 2016

    @erikerikson
    Contributor

    @swennemans the requirement for Administration rights is the broad IAM permissions granted via the CFT. Once those roles are create then PowerUser is sufficient for deployment.

  7. erikerikson commented on Mar 4, 2016

    @erikerikson
    Contributor

    @eahefnawy We handle permissions in a much finer grained and targeted manner than the default CFT. We have roles for each lambda and have very narrow lambda responsibilities (i.e. each distinct resource/method is a separate lambda).

    That said, we have IAM rights broadly (nearly iam:*) that are overridden by custom privilege elevation detection and rejection code that triggers on IAM activity. The detection depends upon naming conventions that identify the creator/owner of the resource. This forces specificity of permissions to those resources we create and control but we go beyond that minimum bar to meet best practices by specifying in detail only the rights that a lambda needs to execute each of usage scenarios.

    To enable this to be a not terrible PITA, we specify each role in a region/environment agnostic manner using Fn:Join in the same manner as the default CFT does so that we specify unique privileges only once. Actually, the CFT is crafted by code so that we cut duplication down even further. In the specification we use naming standards so that we can templatize the customName and customRole attributes in our s-function files for our lambdas.

    I'd expect that it would be easy to generalize the specificity pattern but it wouldn't be a trivial development effort to do so and provide a management interface over top of it. Regardless, it would be desirable and useful.

  8. erikerikson commented on Mar 4, 2016

    @erikerikson
    Contributor

    Feel free to ask for clarification if I have created more questions than answers.

  9. eahefnawy commented on Mar 5, 2016

    @eahefnawy
    Contributor

    @erikerikson thanks a lot for the clarification. Do you think this setup is tied to some rules set up by your company in particular? Because it seems that there's lots of ways to handle production permissions and it all depends on the company policies. In that case I'm not sure what to recommend in our docs, and users will have to create their own policy for managing permission by having some balance between simplicity and security.

  10. erikerikson commented on Mar 5, 2016

    @erikerikson
    Contributor

    @eahefnawy I'd say "yes and no", or "it depends", or something else non committal. I know that the IAM rights set up we have is not off the shelf and as such, its probably not terribly common. That said, I think the least privilege approaches to lambda rights is something we did as an important best practice as opposed to being a reaction to company policy. It could be important for Serverless to consider enabling smarter more fine grained permissions management options if only to reduce the liability for the tool of being viewed as insecure by design. If you end up deciding that it is, I'd say this isn't your highest priority. That said, given the per stage rights "bubble" that is created (and punting on external resource access management to users) I can see a reasonable argument for not enabling fine grained control from a "is it necessary/wasted resources" standpoint.

    Stepping back a little, this all assumes that we're talking about the IAM roles as provided in the CFT and applied to our systems. The other IAM roles (or at least policy given rights) involved here are the deployment permission rights. I believe that the narrowing of the declaration of the necessary rights for each of the various aspects of a Serverless project's deployment to the cloud would be wonderful and fundamentally pragmatic. Again though, I'm not sure this is the highest priority concern.

    To take that perspective on your original question:
    I deploy under the rights I have been assigned by our central cloud management group. Those rights more expansive than some teams but realistically you can expect a lot of variance across companies. That said, if the developers using the tools are not empowered to make the IAM rights changes, then you have to allow them to hand off the smallest portion of highest privilege CFT to the team that has those rights. We had more of a subtle situation in that the ApiGateway rights are harder to control in our scheme and so we have to get another team to create our API that are thereafter allowed to modify (and thereby deploy against). Since we could add the ApiGateway ID in manually, we were okay. As a second example, the pattern might generalize and imply the flexibility that you need to enable: manual and separated processes for doing any of the things that Serverless does to accomplish a full deployment. That is, at least in theory. If a team doesn't have the rights to alter Lambdas and ApiGateways, then... maybe this isn't the tool for them.

  11. erikerikson commented on Mar 5, 2016

    @erikerikson
    Contributor

    @eahefnawy for all my assertions of lower priority on these items, part of that is that I've been in a state of facing blocking issues and because these are not blocking in the "impossible" sense for my organization, I have deprioritized them. I can imagine a world wherein organizational constraints impinge in order to make some of these issues "blockers" by organizational decision. I imagine you know what I mean: security and privacy organizations and the like with gate passing or design review approval powers.

  12. 11 remaining items

  13. DanielRuskin1 commented on May 31, 2016

    @DanielRuskin1

    Cool, makes sense. I ended up just removing the CF permission completely for my deployment, I'll probably just make those updates manually.

  14. flomotlik commented on Aug 19, 2016

    @flomotlik
    Contributor

    Duplicate of #1439 so I'm closing here but we'll keep the discussion going there.

  15. berry2012 commented on Jan 26, 2018

    @berry2012

    create a serverless.json policy with the code below and attach to user or role that runs serverless project in your environment.

        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "VisualEditor0",
                "Effect": "Allow",
                "Action": [
                    "cloudformation:CreateUploadBucket",
                    "cloudformation:CancelUpdateStack",
                    "cloudformation:CreateStack",
                    "cloudformation:DeleteStack",
                    "cloudformation:UpdateStack",
                    "cloudformation:UpdateTerminationProtection",
                    "cloudformation:CreateChangeSet",
                    "cloudformation:Describe*",
                    "cloudformation:ContinueUpdateRollback",
                    "cloudformation:EstimateTemplateCost",
                    "cloudformation:PreviewStackUpdate",
                    "cloudformation:List*",
                    "cloudformation:ExecuteChangeSet",
                    "cloudformation:ValidateTemplate",
                    "cloudformation:Get*"
                ],
                "Resource": "*"
            },
            {
                "Sid": "VisualEditor1",
                "Effect": "Allow",
                "Action": [
                    "lambda:AddPermission",
                    "lambda:InvokeFunction",
                    "lambda:DeleteFunction",
                    "lambda:PublishVersion",
                    "lambda:List*",
                    "lambda:CreateFunction",
                    "lambda:Get*",
                    "lambda:RemovePermission",
                    "lambda:CreateAlias",
                    "lambda:Update*",
                    "apigateway:GET"
                ],
                "Resource": [
                    "arn:aws:lambda:*:*:function:${project}*",
                    "arn:aws:apigateway:*::/restapis"
                ]
            },
            {
                "Sid": "VisualEditor2",
                "Effect": "Allow",
                "Action": "apigateway:*",
                "Resource": "arn:aws:apigateway:*::/restapis/GATEWAY_ID/*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "ec2:AuthorizeSecurityGroupIngress",
                    "ec2:Describe*",
                    "ec2:createTags",
                    "ec2:CreateInternetGateway",
                    "ec2:DeleteInternetGateway",
                    "ec2:CreateVpc",
                    "ec2:DeleteVpc",
                    "ec2:ModifyVpcAttribute",
                    "iam:CreateRole",
                    "iam:DeleteRole",
                    "ec2:DeleteInternetGateway",
                    "dynamodb:CreateTable",
                    "dynamodb:DescribeTable",
                    "dynamodb:DeleteTable",
                    "kinesis:CreateStream",
                    "kinesis:DescribeStream",
                    "kinesis:DeleteStream",
                    "ec2:CreateNetworkAcl",
                    "ec2:DeleteNetworkAcl",
                    "ec2:CreateRouteTable",
                    "ec2:DeleteRouteTable",
                    "ec2:AttachInternetGateway",
                    "ec2:DetachInternetGateway",
                    "ec2:CreateSubnet",
                    "ec2:DeleteSubnet",
                    "ec2:CreateSecurityGroup",
                    "ec2:DeleteSecurityGroup",
                    "ec2:CreateNetworkAclEntry",
                    "ec2:DeleteNetworkAclEntry",
                    "iam:PutRolePolicy",
                    "iam:DeleteRolePolicy",
                    "iam:GetRole",
                    "states:CreateStateMachine",
                    "states:DeleteStateMachine"
                ],
                "Resource": "*"
            }
        ]
    }```
    
  16. tommedema commented on Aug 10, 2018

    @tommedema

    @berry2012 this gives me:

    An error occurred: ServerlessDeploymentBucket - API: s3:CreateBucket Access Denied.
    
  17. erikerikson commented on Aug 10, 2018

    @erikerikson
    Contributor

    @tommedema - most users in a more restrictive environment pre-create their bucket and specify it using the deploymentBucket parameter

  18. jenyayel commented on Feb 12, 2019

    @jenyayel

    @c-knowles you mentioned:

    I'm using the ${project} variable so it has to be in a CF template read by serverless.

    I cannot figure out where do I need to define this. Is it something that passed as arguments to sls CLI or defined in some section within serverless.yml?

  19. cknowles commented on Feb 14, 2019

    @cknowles

    @jenyayel my comment is a bit old so mainly relevant to version 0.5.5. I think it didn't even have serverless.yml back then from what I remember. The framework setup and configuration changed significantly around 0.6. Having said that the basis of that part of my comment was mostly that serverless would automatically complete the ${project} var for you as long as one placed that inside one of the template files it was preprocessing. In the latest serverless I think that's done for any CloudFormation definition, e.g. see the ${self:service} style under resources: on these docs.

  20. jenyayel commented on Feb 16, 2019

    @jenyayel

    Thanks @c-knowles for getting back! I'll try to define it there, although I think I already did and it did't pick it up.

  21. ptrhck commented on Feb 21, 2019

    @ptrhck

    I would like to discuss one more part regarding this topic as I am interested to limit the S3 permissions. In particular, I would like only allow deleting the buckets containing the specific string -serverlessdeploymentbucket-, none else. I think for deployment with the serverless framework, this is the only permission needed for S3. I tried with the following policy, but it seems to not work. Any ideas?

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": "s3:*",
                "Resource": "arn:aws:s3:::*-serverlessdeploymentbucket-*/*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "s3:ListBucket",
                    "s3:DeleteBucket"
                ],
                "Resource": "arn:aws:s3:::*-serverlessdeploymentbucket-*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "s3:ListBucket",
                    "s3:CreateBucket"
                ],
                "Resource": "arn:aws:s3:::*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "cloudformation:*",
                    "logs:*",
                    "iam:*",
                    "apigateway:*",
                    "lambda:*",
                    "ec2:DescribeSecurityGroups",
                    "ec2:DescribeSubnets",
                    "ec2:DescribeVpcs",
                    "ec2:DescribeNetworkInterfaces",
                    "events:*",
                    "ssm:*"
                ],
                "Resource": [
                    "*"
                ]
            }
        ]
    }
    
  22. joshuaquek commented on Feb 4, 2021

    @joshuaquek

    So far I am using this tool to help me generate policies for my serverless projects:

    https://open-sl.github.io/serverless-permission-generator/

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions