iam.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package ecs
  14. const (
  15. ecsTaskExecutionPolicy = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
  16. ecrReadOnlyPolicy = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
  17. ecsEC2InstanceRole = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
  18. actionGetSecretValue = "secretsmanager:GetSecretValue"
  19. actionGetParameters = "ssm:GetParameters"
  20. actionDecrypt = "kms:Decrypt"
  21. actionAutoScaling = "application-autoscaling:*"
  22. actionGetMetrics = "cloudwatch:GetMetricStatistics"
  23. actionDescribeService = "ecs:DescribeServices"
  24. actionUpdateService = "ecs:UpdateService"
  25. )
  26. var (
  27. ecsTaskAssumeRolePolicyDocument = policyDocument("ecs-tasks.amazonaws.com")
  28. ec2InstanceAssumeRolePolicyDocument = policyDocument("ec2.amazonaws.com")
  29. ausocalingAssumeRolePolicyDocument = policyDocument("application-autoscaling.amazonaws.com")
  30. )
  31. func policyDocument(service string) PolicyDocument {
  32. return PolicyDocument{
  33. Version: "2012-10-17", // https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_version.html
  34. Statement: []PolicyStatement{
  35. {
  36. Effect: "Allow",
  37. Principal: PolicyPrincipal{
  38. Service: service,
  39. },
  40. Action: []string{"sts:AssumeRole"},
  41. },
  42. },
  43. }
  44. }
  45. // PolicyDocument describes an IAM policy document
  46. // could alternatively depend on https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/master/cmd/clusterawsadm/api/iam/v1alpha1/types.go
  47. type PolicyDocument struct {
  48. Version string `json:",omitempty"`
  49. Statement []PolicyStatement `json:",omitempty"`
  50. }
  51. // PolicyStatement describes an IAM policy statement
  52. type PolicyStatement struct {
  53. Effect string `json:",omitempty"`
  54. Action []string `json:",omitempty"`
  55. Principal PolicyPrincipal `json:",omitempty"`
  56. Resource []string `json:",omitempty"`
  57. }
  58. // PolicyPrincipal describes an IAM policy principal
  59. type PolicyPrincipal struct {
  60. Service string `json:",omitempty"`
  61. }