Skip to content

Commit 3f4e311

Browse files
AWS VPC state sync implementation (#625)
1 parent 8bd1dce commit 3f4e311

File tree

4 files changed

+693
-4
lines changed

4 files changed

+693
-4
lines changed

docs/CLOUD.md

Lines changed: 300 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ This network state enables better network flow analysis and region/zone attribut
2121
## Supported Cloud Providers
2222

2323
Currently supported:
24-
- GCP - Support with Workload Identity and Service Account authentication
24+
- **GCP** - Workload Identity and Service Account authentication
25+
- **AWS** - IRSA (IAM Roles for Service Accounts) and IAM User authentication
2526

2627
Coming soon:
27-
- AWS
2828
- Azure
2929

3030
---
@@ -206,3 +206,301 @@ helm upgrade --install castai-kvisor castai-helm/castai-kvisor \
206206
```
207207

208208
---
209+
210+
## AWS EKS Configuration
211+
212+
### Prerequisites
213+
214+
1. **AWS Account** with the VPC you want to monitor
215+
2. **IAM Role or User** with the following permissions:
216+
- `ec2:DescribeVpcs`
217+
- `ec2:DescribeSubnets`
218+
- `ec2:DescribeVpcPeeringConnections`
219+
220+
**Recommended IAM Policy:**
221+
```json
222+
{
223+
"Version": "2012-10-17",
224+
"Statement": [
225+
{
226+
"Effect": "Allow",
227+
"Action": [
228+
"ec2:DescribeVpcs",
229+
"ec2:DescribeSubnets",
230+
"ec2:DescribeVpcPeeringConnections"
231+
],
232+
"Resource": "*"
233+
}
234+
]
235+
}
236+
```
237+
238+
3. **VPC ID** - The ID of the VPC to monitor (e.g., `vpc-0123456789abcdef0`)
239+
240+
### Authentication Methods
241+
242+
Choose one of the following authentication methods:
243+
244+
#### Option 1: IRSA - IAM Roles for Service Accounts (Recommended)
245+
246+
**Step 1: Create IAM Policy**
247+
248+
```bash
249+
export AWS_REGION="us-east-1"
250+
export POLICY_NAME="KvisorVPCReaderPolicy"
251+
252+
cat > kvisor-vpc-policy.json <<EOF
253+
{
254+
"Version": "2012-10-17",
255+
"Statement": [
256+
{
257+
"Effect": "Allow",
258+
"Action": [
259+
"ec2:DescribeVpcs",
260+
"ec2:DescribeSubnets",
261+
"ec2:DescribeVpcPeeringConnections"
262+
],
263+
"Resource": "*"
264+
}
265+
]
266+
}
267+
EOF
268+
269+
aws iam create-policy \
270+
--policy-name ${POLICY_NAME} \
271+
--policy-document file://kvisor-vpc-policy.json \
272+
--region ${AWS_REGION}
273+
```
274+
275+
**Step 2: Create IAM Role for Service Account**
276+
277+
You have two options:
278+
279+
**Option A: Use existing kvisor service account (Recommended)**
280+
281+
```bash
282+
export CLUSTER_NAME="your-eks-cluster"
283+
export NAMESPACE="kvisor"
284+
export SERVICE_ACCOUNT_NAME="kvisor"
285+
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
286+
287+
# Associate OIDC provider with cluster (if not already done)
288+
eksctl utils associate-iam-oidc-provider \
289+
--cluster ${CLUSTER_NAME} \
290+
--region ${AWS_REGION} \
291+
--approve
292+
293+
# Get OIDC provider URL
294+
export OIDC_PROVIDER=$(aws eks describe-cluster --name ${CLUSTER_NAME} --region ${AWS_REGION} --query "cluster.identity.oidc.issuer" --output text | sed -e "s/^https:\/\///")
295+
296+
# Create IAM role with trust policy for the existing service account
297+
cat > trust-policy.json <<EOF
298+
{
299+
"Version": "2012-10-17",
300+
"Statement": [
301+
{
302+
"Effect": "Allow",
303+
"Principal": {
304+
"Federated": "arn:aws:iam::${AWS_ACCOUNT_ID}:oidc-provider/${OIDC_PROVIDER}"
305+
},
306+
"Action": "sts:AssumeRoleWithWebIdentity",
307+
"Condition": {
308+
"StringEquals": {
309+
"${OIDC_PROVIDER}:sub": "system:serviceaccount:${NAMESPACE}:${SERVICE_ACCOUNT_NAME}",
310+
"${OIDC_PROVIDER}:aud": "sts.amazonaws.com"
311+
}
312+
}
313+
}
314+
]
315+
}
316+
EOF
317+
318+
# Create the IAM role
319+
aws iam create-role \
320+
--role-name KvisorVPCReaderRole \
321+
--assume-role-policy-document file://trust-policy.json
322+
323+
# Attach the policy to the role
324+
aws iam attach-role-policy \
325+
--role-name KvisorVPCReaderRole \
326+
--policy-arn arn:aws:iam::${AWS_ACCOUNT_ID}:policy/${POLICY_NAME}
327+
328+
# Get the role ARN (you'll need this for helm values)
329+
export ROLE_ARN=$(aws iam get-role --role-name KvisorVPCReaderRole --query 'Role.Arn' --output text)
330+
echo "Role ARN: ${ROLE_ARN}"
331+
```
332+
333+
**Option B: Let eksctl create a new service account**
334+
335+
```bash
336+
export CLUSTER_NAME="your-eks-cluster"
337+
export NAMESPACE="kvisor"
338+
export SERVICE_ACCOUNT_NAME="kvisor"
339+
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
340+
341+
# Associate OIDC provider with cluster (if not already done)
342+
eksctl utils associate-iam-oidc-provider \
343+
--cluster ${CLUSTER_NAME} \
344+
--region ${AWS_REGION} \
345+
--approve
346+
347+
# Create IAM role and service account
348+
eksctl create iamserviceaccount \
349+
--cluster=${CLUSTER_NAME} \
350+
--namespace=${NAMESPACE} \
351+
--name=${SERVICE_ACCOUNT_NAME} \
352+
--attach-policy-arn=arn:aws:iam::${AWS_ACCOUNT_ID}:policy/${POLICY_NAME} \
353+
--region=${AWS_REGION} \
354+
--approve
355+
```
356+
357+
**Step 3: Configure Helm Values**
358+
359+
Create or update your `values.yaml`:
360+
361+
**For Option A (existing service account):**
362+
363+
```yaml
364+
controller:
365+
extraArgs:
366+
# Cloud provider configuration
367+
cloud-provider: aws
368+
369+
# VPC controller configuration
370+
cloud-provider-vpc-sync-enabled: true
371+
cloud-provider-vpc-name: "vpc-0123456789abcdef0"
372+
cloud-provider-vpc-sync-interval: 1h # Optional: refresh interval
373+
cloud-provider-vpc-cache-size: 10000 # Optional: cache size
374+
375+
serviceAccount:
376+
create: true
377+
name: kvisor
378+
annotations:
379+
eks.amazonaws.com/role-arn: "arn:aws:iam::YOUR_ACCOUNT_ID:role/KvisorVPCReaderRole"
380+
```
381+
382+
**For Option B (eksctl-created service account):**
383+
384+
```yaml
385+
controller:
386+
extraArgs:
387+
# Cloud provider configuration
388+
cloud-provider: aws
389+
390+
# VPC controller configuration
391+
cloud-provider-vpc-sync-enabled: true
392+
cloud-provider-vpc-name: "vpc-0123456789abcdef0"
393+
cloud-provider-vpc-sync-interval: 1h # Optional: refresh interval
394+
cloud-provider-vpc-cache-size: 10000 # Optional: cache size
395+
396+
serviceAccount:
397+
create: false
398+
```
399+
400+
**Step 4: Install/Upgrade kvisor**
401+
402+
```bash
403+
helm upgrade --install castai-kvisor castai-helm/castai-kvisor \
404+
--namespace kvisor \
405+
--create-namespace \
406+
--values values.yaml
407+
```
408+
409+
---
410+
411+
#### Option 2: IAM User with Access Keys
412+
413+
**Step 1: Create IAM User and Policy**
414+
415+
```bash
416+
export USER_NAME="kvisor-vpc-reader"
417+
export POLICY_NAME="KvisorVPCReaderPolicy"
418+
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
419+
420+
# Create policy
421+
cat > kvisor-vpc-policy.json <<EOF
422+
{
423+
"Version": "2012-10-17",
424+
"Statement": [
425+
{
426+
"Effect": "Allow",
427+
"Action": [
428+
"ec2:DescribeVpcs",
429+
"ec2:DescribeSubnets",
430+
"ec2:DescribeVpcPeeringConnections"
431+
],
432+
"Resource": "*"
433+
}
434+
]
435+
}
436+
EOF
437+
438+
aws iam create-policy \
439+
--policy-name ${POLICY_NAME} \
440+
--policy-document file://kvisor-vpc-policy.json
441+
442+
# Create IAM user
443+
aws iam create-user --user-name ${USER_NAME}
444+
445+
# Attach policy to user
446+
aws iam attach-user-policy \
447+
--user-name ${USER_NAME} \
448+
--policy-arn arn:aws:iam::${AWS_ACCOUNT_ID}:policy/${POLICY_NAME}
449+
450+
# Create access key
451+
aws iam create-access-key --user-name ${USER_NAME} > access-key.json
452+
```
453+
454+
**Step 2: Create Kubernetes Secret**
455+
456+
```bash
457+
export AWS_ACCESS_KEY_ID=$(cat access-key.json | jq -r '.AccessKey.AccessKeyId')
458+
export AWS_SECRET_ACCESS_KEY=$(cat access-key.json | jq -r '.AccessKey.SecretAccessKey')
459+
460+
kubectl create namespace kvisor
461+
462+
kubectl create secret generic aws-credentials \
463+
--from-literal=AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
464+
--from-literal=AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
465+
--namespace kvisor
466+
467+
# Delete the local credentials file
468+
rm access-key.json
469+
```
470+
471+
**Step 3: Configure Helm Values**
472+
473+
Create or update your `values.yaml`:
474+
475+
```yaml
476+
controller:
477+
extraArgs:
478+
# Cloud provider configuration
479+
cloud-provider: aws
480+
481+
# VPC controller configuration
482+
cloud-provider-vpc-sync-enabled: true
483+
cloud-provider-vpc-name: "vpc-0123456789abcdef0"
484+
cloud-provider-vpc-sync-interval: 1h # Optional: refresh interval
485+
cloud-provider-vpc-cache-size: 10000 # Optional: cache size
486+
487+
# Mount credentials as environment variables
488+
envFrom:
489+
- secretRef:
490+
name: aws-credentials
491+
492+
serviceAccount:
493+
create: true
494+
name: kvisor
495+
```
496+
497+
**Step 4: Install/Upgrade kvisor**
498+
499+
```bash
500+
helm upgrade --install castai-kvisor castai-helm/castai-kvisor \
501+
--namespace kvisor \
502+
--create-namespace \
503+
--values values.yaml
504+
```
505+
506+
---

0 commit comments

Comments
 (0)