netatlas Star on GitHub

EKS

netatlas reads an EKS cluster as the AWS role its pod runs as. It signs the same token aws eks get-token makes with that role, so it needs no Kubernetes token for EKS clusters. This page sets up the role, the access in each cluster, and the cluster's entry.

The pod's AWS role

Give the pod an IAM role in one of two ways:

  • IAM roles for service accounts: annotate the chart's ServiceAccount with the role.

    serviceAccount:
      annotations:
        eks.amazonaws.com/role-arn: arn:aws:iam::111122223333:role/netatlas
  • EKS Pod Identity: create a Pod Identity association for the ServiceAccount netatlas in the namespace netatlas runs in.

The role needs no AWS permission of its own: EKS trusts the token because the role signed it, and each cluster's access entry decides what the role may read. netatlas signs a new token every 10 minutes and uses it until then, as EKS accepts one for 15 minutes.

Access in each cluster

Each cluster gives the role an access entry of type STANDARD that maps it to the Kubernetes group netatlas-readers, with no access policy, and binds that group to netatlas's own read-only ClusterRole.

No EKS access policy fits: AmazonEKSViewPolicy cannot read Istio's AuthorizationPolicies, and AmazonEKSAdminViewPolicy can read Secrets, which netatlas must not read. The ClusterRole grants get, list and watch on what netatlas watches, and, on Kubescape's results, which netatlas lists and reads but never watches, only the verbs it uses: list on the two kinds of summaries, get and list on the images' lists of vulnerabilities and get on the full configuration scans. It grants nothing else (The role).

An access entry that you set up before 0.3.0 has a ClusterRole without the rules for Kubescape's results. Apply the Terraform example again in that cluster to update it (Grant the access again).

The Terraform example

examples/terraform/eks-access creates the access entry, the ClusterRole and its binding in one cluster. It takes two inputs:

  • cluster_name: the EKS cluster netatlas reads, for example prod-eu-1.
  • netatlas_role_arn: the IAM role netatlas's pod runs as, for example arn:aws:iam::111122223333:role/netatlas.

The AWS provider takes its region and credentials from the environment, as the AWS CLI does. Apply it once per cluster, with an identity that may create access entries and ClusterRoles there. Access entries work across accounts, so netatlas can read clusters in other accounts than its own.

Use the example at the tag of the netatlas version you run: it reads the ClusterRole's rules from the chart in the same checkout, so the tag decides which version's rules the role holds. Clone it into a folder named after the cluster:

git clone --branch v0.3.1 --depth 1 https://github.com/kitecorp/netatlas.git netatlas-prod-eu-1
cd netatlas-prod-eu-1/examples/terraform/eks-access
terraform init
terraform apply -var 'cluster_name=prod-eu-1' -var 'netatlas_role_arn=arn:aws:iam::111122223333:role/netatlas'

Terraform keeps what it created in a state file in that folder, so keep the checkout: a later version is applied by checking its tag out in it (Grant the access again). Use one checkout per cluster: each holds that cluster's state. Applied in one checkout with another cluster_name, Terraform would replace the first cluster's access entry with one in the second cluster, and netatlas could no longer read the first.

The cluster's entry

An EKS cluster's entry in clusters (Clusters lists every field) names its API server and CA, which aws eks describe-cluster prints:

aws eks describe-cluster --name <cluster> --region <region> --query cluster.endpoint --output text
aws eks describe-cluster --name <cluster> --region <region> --query cluster.certificateAuthority.data --output text

The first is the entry's server, and the second its caData:

clusters:
  - name: prod-eu-1
    server: https://ABCDEF0123456789.gr7.eu-west-1.eks.amazonaws.com
    caData: LS0tLS1CRUdJTi...
    login:
      type: eks
      clusterName: prod-eu-1
      region: eu-west-1