Skip to content

Commit

Permalink
Add IAM policy for use with Crossplane AWS provider (#96)
Browse files Browse the repository at this point in the history
The initial permissions are meant to be used with Cilium ENI mode (see Crossplane CRs in https://github.com/giantswarm/cluster-aws).
  • Loading branch information
AndiDog authored Apr 30, 2024
1 parent 43559f9 commit acb61d6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
7 changes: 5 additions & 2 deletions capa-controller-role/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ If you don't know what the `INSTALLATION_NAME` value is supposed to be, ask Gian

## with aws cli
### requirements
- `awscli` installed
- `awscli` installed
- `envsubst` tool
- `jq` installed
- working AWS credentials set to the desired target account
Expand Down Expand Up @@ -44,6 +44,9 @@ aws iam attach-role-policy --role-name "${ROLE_NAME}" --policy-arn "${RESOLVER_R
MC_BOOTSTRAP_POLICY_ARN=$(aws iam create-policy --policy-name "giantswarm-${INSTALLATION_NAME}-mc-bootstrap-policy" --description "Giant Swarm managed policy for k8s cluster cleanup" --policy-document file://mc-bootstrap-policy.json | jq -r '.Policy.Arn')
aws iam attach-role-policy --role-name "${ROLE_NAME}" --policy-arn "${MC_BOOTSTRAP_POLICY_ARN}"
CROSSPLANE_ARN=$(aws iam create-policy --policy-name "giantswarm-${INSTALLATION_NAME}-crossplane-policy" --description "Giant Swarm managed policy for k8s cluster creation" --policy-document file://crossplane-policy.json | jq -r '.Policy.Arn')
aws iam attach-role-policy --role-name "${ROLE_NAME}" --policy-arn "${CROSSPLANE_ARN}"
```

### for cleanup execute
Expand All @@ -59,7 +62,7 @@ chmod +x cleanup.sh
- working AWS credentials set to the desired target account
- AWS region has to be set either via aws profile or via env `AWS_REGION`

### adjust `variables.tf`
### adjust `variables.tf`
- `principal_arns_giantswarm_root_account` - can be adjusted to be more strict and specify user which will assume the role - ie `arn:aws:iam::084190472784:user/${INSTALLATION_NAME}-capa-controller`

### execute
Expand Down
4 changes: 2 additions & 2 deletions capa-controller-role/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NC='\033[0m'
ROLE_NAME="giantswarm-${INSTALLATION_NAME}-capa-controller"
AWS_ACCOUNT_ID="$(aws sts get-caller-identity --output text --query 'Account')"

POL_TYPES=("capa-controller" "dns-controller" "eks-controller" "iam-controller" "irsa-controller" "resolver-rule-operator" "network-topology-controller" "mc-bootstrap")
POL_TYPES=("capa-controller" "dns-controller" "eks-controller" "iam-controller" "irsa-controller" "resolver-rule-operator" "network-topology-controller" "mc-bootstrap" "crossplane")
POL_ARN_PREFIX="arn:aws:iam::${AWS_ACCOUNT_ID}:policy"

function echo_fail_or_success {
Expand All @@ -32,7 +32,7 @@ for pol_type in ${POL_TYPES[@]}; do
echo_fail_or_success "$?"

echo -n "|_ Delete policy ${POL_NAME}..."
aws iam delete-policy --policy-arn "${POL_ARN}"
aws iam delete-policy --policy-arn "${POL_ARN}"
echo_fail_or_success "$?"
done

Expand Down
19 changes: 19 additions & 0 deletions capa-controller-role/crossplane-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:AuthorizeSecurityGroupEgress",
"ec2:AuthorizeSecurityGroupIngress",
"ec2:CreateSecurityGroup",
"ec2:DeleteSecurityGroup",
"ec2:DescribeSecurityGroupRules",
"ec2:DescribeSecurityGroups",
"ec2:RevokeSecurityGroupEgress",
"ec2:RevokeSecurityGroupIngress"
],
"Resource": "*"
}
]
}
9 changes: 9 additions & 0 deletions capa-controller-role/giantswarm-capa-role.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,12 @@ resource "aws_iam_role_policy_attachment" "giantswarm-mc-bootstrap-policy-attach
role = aws_iam_role.giantswarm-capa-controller-role.name
policy_arn = aws_iam_policy.giantswarm-mc-bootstrap-policy.arn
}

resource "aws_iam_policy" "giantswarm-crossplane-policy" {
name = "giantswarm-${var.installation_name}-crossplane-policy"
policy = file("${path.module}/crossplane-policy.json")
}
resource "aws_iam_role_policy_attachment" "giantswarm-crossplane-policy-attachment" {
role = aws_iam_role.giantswarm-capa-controller-role.name
policy_arn = aws_iam_policy.giantswarm-crossplane-policy.arn
}
2 changes: 1 addition & 1 deletion capa-controller-role/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ variable "principal_arns_giantswarm_root_account" {
}

variable "installation_name" {
type = string
type = string
description = "If you dont know what `installation_name` value is suppose to be, ask Giant Swarm staff and they will provide it."
}

0 comments on commit acb61d6

Please sign in to comment.