Instance IAM Roles

    The default IAM roles will not grant nodes access to the AWS EC2 Container Registry (ECR). To grant access to ECR, update your Cluster Spec with the following and then perform a cluster update:

    Adding ECR permissions will extend the IAM policy documents as below: - Control Plane Nodes: https://github.com/kubernetes/kops/blob/master/pkg/model/iam/tests/iam\_builder\_master\_strict\_ecr.json - Worker Nodes:

    The additional permissions are:

    1. "Sid": "kOpsK8sECR",
    2. "Effect": "Allow",
    3. "Action": [
    4. "ecr:BatchCheckLayerAvailability",
    5. "ecr:BatchGetImage",
    6. "ecr:DescribeRepositories",
    7. "ecr:GetAuthorizationToken",
    8. "ecr:GetDownloadUrlForLayer",
    9. "ecr:GetRepositoryPolicy",
    10. "ecr:ListImages"
    11. ],
    12. "Resource": [
    13. "*"
    14. ]
    15. }

    AWS Permissions Boundaries enable you to use a policy (managed or custom) to set the maximum permissions that roles created by kOps will be able to grant to instances they’re attached to. It can be useful to prevent possible privilege escalations.

    To set a Permissions Boundary for kOps’ roles, update your Cluster Spec with the following and then perform a cluster update:

    1. iam:
    2. permissionsBoundary: aws:arn:iam:123456789000:policy:test-boundary

    NOTE: Currently, kOps only supports using a single Permissions Boundary for all roles it creates. In case you need to set per-role Permissions Boundaries, we recommend that you refer to this section below, and provide your own roles to kOps.

    Introduced
    kOps 1.18

    Policy Overrides are specified by their ARN on AWS and are grouped by their role type. See the example below:

    1. spec:
    2. externalPolicies:
    3. - arn:aws:iam::123456789000:policy/test-policy
    4. master:
    5. - arn:aws:iam::123456789000:policy/test-policy
    6. bastion:
    7. - arn:aws:iam::123456789000:policy/test-policy

    External Policy attachments are treated declaratively. Any policies declared will be attached to the role, any policies not specified will be detached after new policies are attached. This does not replace or affect built in kOps policies in any way.

    It’s important to note that externalPolicies will only handle the attachment and detachment of policies, not creation, modification, or deletion of them.

    Sometimes you may need to extend the kOps instance IAM roles to add additional policies. You can do this through the spec field. For instance, let’s say you want to add DynamoDB and Elasticsearch permissions to your nodes.

    Edit your cluster via kops edit cluster ${CLUSTER_NAME} and add the following to the spec:

    After you’re finished editing, your cluster spec should look something like this:

    1. metadata:
    2. name: ${CLUSTER_NAME}
    3. spec:
    4. cloudProvider: aws
    5. networkCIDR: 10.100.0.0/16
    6. networkID: vpc-a80734c1
    7. nonMasqueradeCIDR: 100.64.0.0/10
    8. zones:
    9. - cidr: 10.100.32.0/19
    10. name: eu-central-1a
    11. additionalPolicies:
    12. node: |
    13. [
    14. {
    15. "Effect": "Allow",
    16. "Action": ["dynamodb:*"],
    17. "Resource": ["*"]
    18. },
    19. {
    20. "Effect": "Allow",
    21. "Resource": ["*"]
    22. }
    23. ]

    Now you can run a cluster update to have the changes take effect:

    1. kops update cluster ${CLUSTER_NAME} --yes
    1. additionalPolicies:
    2. node: |
    3. [
    4. {
    5. "Effect": "Allow",
    6. "Action": ["es:*"],
    7. "Resource": ["*"]
    8. }
    9. ]
    10. master: |
    11. [
    12. {
    13. "Effect": "Allow",
    14. "Action": ["dynamodb:*"],
    15. "Resource": ["*"]
    16. }
    17. ]

    Rather than having kOps create and manage IAM roles and instance profiles, it is possible to use an existing instance profile. This is useful in organizations where security policies prevent tools from creating their own IAM roles and policies. kOps will still output any differences in the IAM Inline Policy for each IAM Role. This is convenient for determining policy changes that need to be made when upgrading kOps. Using IAM Managed Policies will not output these differences; it is up to the user to track expected changes to policies.

    NOTE: Currently kOps only supports using existing instance profiles for every instance group in the cluster, not a mix of existing and managed instance profiles. This is due to the lifecycle overrides being used to prevent creation of the IAM-related resources.

    To do this, get a list of instance group names for the cluster:

    And update every instance group’s spec with the desired instance profile ARNs:

    1. kops edit ig --name ${CLUSTER_NAME} ${INSTANCE_GROUP_NAME}

    Adding the following iam section to the spec:

    1. spec:
    2. iam:

    Now run a cluster update to create the new launch template version, using to prevent IAM-related resources from being created:

    1. kops update cluster ${CLUSTER_NAME} --yes --lifecycle-overrides IAMRole=ExistsAndWarnIfChanges,IAMRolePolicy=ExistsAndWarnIfChanges,IAMInstanceProfileRole=ExistsAndWarnIfChanges

    Every time kops update cluster is run, it must include the above --lifecycle-overrides unless a non-security phase is specified.