KIMS v2 uses no access keys on AWS. Everything reaches AWS through two roles:
| Role | Used by | Gets credentials through |
|---|---|---|
The pods' role, for example kims-app-prod (UAT kims-app-uat) |
CMS, worker and CronJob pods, and the content load pod, through the kims service account |
IRSA (serviceAccount.roleArn in the Helm values) |
| The Jenkins agent's role (KIMS's existing one) | The kims-site-build and kims-platform jobs |
The agent's EC2 instance profile, or IRSA if the agent runs on EKS |
Nothing else in AWS is used: S3, CloudFront (and its KeyValueStore if redirects are on), ECR, and eks:DescribeCluster. No Lambda, SSM, Secrets Manager or Cognito.
#Who does what
| Task | Usually done by | What our engineer needs |
|---|---|---|
| Create the pods' role | KIMS's cloud team (IAM is often restricted) | Its ARN for serviceAccount.roleArn |
| Add the site build and platform policies to the agent's role | KIMS's cloud team, because other jobs may share the agent | A yes that it is done |
| Check each policy works | Our engineer | Read rights on IAM, or the first deploy and build |
#Every AWS call KIMS v2 makes
Built from the code, so each policy below holds exactly these and no more.
| Caller | File | SDK calls | IAM actions |
|---|---|---|---|
| CMS (browser upload URL) | packages/content/src/media/blob-store.ts presignUpload |
Presigned PutObject on originals/... |
s3:PutObject (the URL carries the pod's rights) |
| CMS, worker | blob-store.ts put, get, head, list, delete, deletePrefix |
PutObject, GetObject (with Range), HeadObject, ListObjectsV2, DeleteObject, DeleteObjects |
s3:PutObject, s3:GetObject, s3:ListBucket, s3:DeleteObject on the assets bucket |
| Content load pod | scripts/handover/data-bundle.mjs load |
HeadObject, PutObject, ListObjectsV2 |
s3:GetObject, s3:PutObject, s3:ListBucket on the assets bucket |
| Site build, Bundle media | scripts/site-build/media.mjs, s3.mjs |
GetObject on derived/... |
s3:GetObject on the assets bucket |
| Site build, Sync | scripts/site-build/sync.mjs, s3.mjs |
ListObjectsV2, PutObject, DeleteObjects |
s3:ListBucket, s3:PutObject, s3:DeleteObject on the website bucket |
| Site build, Invalidate | scripts/site-build/cloudfront.mjs invalidate |
CreateInvalidation |
cloudfront:CreateInvalidation on the distribution |
Site build, Redirects (only with KIMS_REDIRECTS_KVS_ARN) |
cloudfront.mjs syncRedirects |
DescribeKeyValueStore, ListKeys, UpdateKeys |
cloudfront-keyvaluestore:DescribeKeyValueStore, :ListKeys, :UpdateKeys on the store |
| Platform job, Image | deploy/jenkins/Jenkinsfile.platform |
docker buildx imagetools inspect, docker buildx build --push |
ECR login and push actions on kims/kims-v2 |
| Platform job, Deploy (agent role mapped in EKS) | aws eks update-kubeconfig on the agent |
DescribeCluster |
eks:DescribeCluster |
HeadObject is authorised by s3:GetObject, and DeleteObjects by s3:DeleteObject. ListObjectsV2 is s3:ListBucket on the bucket ARN, not on bucket/*.
The pods never touch the website bucket or CloudFront. Older notes (and comments in the windows-fixes branch's values file) gave the pods' role both buckets and cloudfront:CreateInvalidation. On main, the source of truth, the pods' role has the assets bucket only; the website bucket and the invalidation belong to the Jenkins site job (docs/ON-SITE-DEPLOYMENT.md AWS set-up F; deploy/jenkins/README.md section 5).
#Set the names once
Used by every CLI block on this page. Replace every <...>.
export AWS_REGION=ap-south-2
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
CLUSTER=<EKS_CLUSTER_NAME>
NAMESPACE=kims
ASSETS_BUCKET=kims-hospitals-assets-prod
WEBSITE_BUCKET=kims-hospitals-website-prod
DISTRIBUTION_ID=<DISTRIBUTION_ID>
AGENT_ROLE=<JENKINS_AGENT_ROLE_NAME>
ISSUER=$(aws eks describe-cluster --name "$CLUSTER" --query cluster.identity.oidc.issuer --output text)
OIDC=${ISSUER#https://}
echo "$ACCOUNT $OIDC"export AWS_REGION=ap-south-2
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
CLUSTER=<EKS_CLUSTER_NAME>
NAMESPACE=kims
ASSETS_BUCKET=kims-hospitals-assets-prod
WEBSITE_BUCKET=kims-hospitals-website-prod
DISTRIBUTION_ID=<DISTRIBUTION_ID>
AGENT_ROLE=<JENKINS_AGENT_ROLE_NAME>
ISSUER=$(aws eks describe-cluster --name "$CLUSTER" --query cluster.identity.oidc.issuer --output text)
OIDC=${ISSUER#https://}
echo "$ACCOUNT $OIDC"$env:AWS_REGION = "ap-south-2"
$Account = aws sts get-caller-identity --query Account --output text
$Cluster = "<EKS_CLUSTER_NAME>"
$Namespace = "kims"
$AssetsBucket = "kims-hospitals-assets-prod"
$WebsiteBucket = "kims-hospitals-website-prod"
$DistributionId = "<DISTRIBUTION_ID>"
$AgentRole = "<JENKINS_AGENT_ROLE_NAME>"
$Issuer = aws eks describe-cluster --name $Cluster --query cluster.identity.oidc.issuer --output text
$Oidc = $Issuer -replace '^https://', ''
"$Account $Oidc"OIDC looks like oidc.eks.ap-south-2.amazonaws.com/id/<OIDC_ID>. For UAT: NAMESPACE=kims-uat and UAT's buckets and distribution.
#The pods' role (IRSA)
#Trust policy
Lets only the service account kims in the environment's namespace assume the role, through the cluster's OIDC provider (EKS, OIDC provider).
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::<AWS_ACCOUNT_ID>:oidc-provider/oidc.eks.<REGION>.amazonaws.com/id/<OIDC_ID>"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks.<REGION>.amazonaws.com/id/<OIDC_ID>:sub": "system:serviceaccount:kims:kims",
"oidc.eks.<REGION>.amazonaws.com/id/<OIDC_ID>:aud": "sts.amazonaws.com"
}
}
}
]
}UAT: system:serviceaccount:kims-uat:kims. The second kims is the service account, named after the Helm release; it changes only if KIMS uses another release name.
#Permissions policy (assets bucket only)
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AssetsObjects",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
"Resource": "arn:aws:s3:::<ASSETS_BUCKET>/*"
},
{
"Sid": "AssetsList",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::<ASSETS_BUCKET>"
}
]
}This is main's policy (AWS set-up F) unchanged. It could be narrowed further to originals/* and derived/*, the only two prefixes the code writes (packages/content/src/media/keys.ts), but nothing else lives in the bucket, so the gain is small.
#Console steps
- IAM console > Roles > Create role.
- Trusted entity type: Custom trust policy. Replace the text with the trust policy above, values filled in. Next.
- Add permissions: add nothing. Next.
- Role name:
kims-app-prod(UATkims-app-uat). Description:KIMS v2 pods: assets bucket. Create role. - Open the role > Permissions tab > Add permissions > Create inline policy > JSON tab > paste the permissions policy > Next > Policy name
kims-assets> Create policy. - Copy the role's ARN from its Summary. It goes in
serviceAccount.roleArn(Helm values).
#CLI steps
cat > app-trust.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Federated": "arn:aws:iam::$ACCOUNT:oidc-provider/$OIDC" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"$OIDC:sub": "system:serviceaccount:$NAMESPACE:kims",
"$OIDC:aud": "sts.amazonaws.com"
}
}
}
]
}
EOF
cat > app-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{ "Sid": "AssetsObjects", "Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
"Resource": "arn:aws:s3:::$ASSETS_BUCKET/*" },
{ "Sid": "AssetsList", "Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::$ASSETS_BUCKET" }
]
}
EOF
aws iam create-role --role-name kims-app-prod --description "KIMS v2 pods: assets bucket" \
--assume-role-policy-document file://app-trust.json --query Role.Arn --output text
aws iam put-role-policy --role-name kims-app-prod --policy-name kims-assets --policy-document file://app-policy.jsoncat > app-trust.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Federated": "arn:aws:iam::$ACCOUNT:oidc-provider/$OIDC" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"$OIDC:sub": "system:serviceaccount:$NAMESPACE:kims",
"$OIDC:aud": "sts.amazonaws.com"
}
}
}
]
}
EOF
cat > app-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{ "Sid": "AssetsObjects", "Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
"Resource": "arn:aws:s3:::$ASSETS_BUCKET/*" },
{ "Sid": "AssetsList", "Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::$ASSETS_BUCKET" }
]
}
EOF
aws iam create-role --role-name kims-app-prod --description "KIMS v2 pods: assets bucket" \
--assume-role-policy-document file://app-trust.json --query Role.Arn --output text
aws iam put-role-policy --role-name kims-app-prod --policy-name kims-assets --policy-document file://app-policy.json@"
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Federated": "arn:aws:iam::${Account}:oidc-provider/${Oidc}" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"${Oidc}:sub": "system:serviceaccount:${Namespace}:kims",
"${Oidc}:aud": "sts.amazonaws.com"
}
}
}
]
}
"@ | Set-Content -Encoding ascii app-trust.json
@"
{
"Version": "2012-10-17",
"Statement": [
{ "Sid": "AssetsObjects", "Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
"Resource": "arn:aws:s3:::$AssetsBucket/*" },
{ "Sid": "AssetsList", "Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::$AssetsBucket" }
]
}
"@ | Set-Content -Encoding ascii app-policy.json
aws iam create-role --role-name kims-app-prod --description "KIMS v2 pods: assets bucket" `
--assume-role-policy-document file://app-trust.json --query Role.Arn --output text
aws iam put-role-policy --role-name kims-app-prod --policy-name kims-assets --policy-document file://app-policy.jsonThe first command prints the role ARN. In PowerShell, ${Account} and ${Oidc} are in braces because a : straight after a variable name is read as part of it.
#If KIMS uses EKS Pod Identity instead
Only if KIMS's platform team insists (EKS, IRSA or Pod Identity). Same permissions policy; this trust policy; leave serviceAccount.roleArn empty; create a Pod Identity association for namespace kims, service account kims, this role.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "pods.eks.amazonaws.com" },
"Action": ["sts:AssumeRole", "sts:TagSession"]
}
]
}aws eks create-pod-identity-association --cluster-name "$CLUSTER" \
--namespace "$NAMESPACE" --service-account kims \
--role-arn "arn:aws:iam::$ACCOUNT:role/kims-app-prod"aws eks create-pod-identity-association --cluster-name "$CLUSTER" \
--namespace "$NAMESPACE" --service-account kims \
--role-arn "arn:aws:iam::$ACCOUNT:role/kims-app-prod"aws eks create-pod-identity-association --cluster-name $Cluster `
--namespace $Namespace --service-account kims `
--role-arn "arn:aws:iam::${Account}:role/kims-app-prod"#The Jenkins site job
The kims-site-build job runs on the agent and reaches AWS with the agent's role through the SDK's default credential chain (Jenkinsfile.site: "AWS access comes from the agent's IAM role"). It needs no AWS CLI. Add this as an inline policy kims-site-build on the agent's role. If one agent builds both environments, list both environments' buckets, distributions and stores.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadAssets",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::<ASSETS_BUCKET>", "arn:aws:s3:::<ASSETS_BUCKET>/*"]
},
{
"Sid": "WriteWebsite",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::<WEBSITE_BUCKET>", "arn:aws:s3:::<WEBSITE_BUCKET>/*"]
},
{
"Sid": "Invalidate",
"Effect": "Allow",
"Action": "cloudfront:CreateInvalidation",
"Resource": "arn:aws:cloudfront::<AWS_ACCOUNT_ID>:distribution/<DISTRIBUTION_ID>"
}
]
}Only once redirects use a KeyValueStore (KIMS_REDIRECTS_KVS_ARN set in kims-site-env; see CloudFront), add:
{
"Sid": "Redirects",
"Effect": "Allow",
"Action": [
"cloudfront-keyvaluestore:DescribeKeyValueStore",
"cloudfront-keyvaluestore:ListKeys",
"cloudfront-keyvaluestore:UpdateKeys"
],
"Resource": "arn:aws:cloudfront::<AWS_ACCOUNT_ID>:key-value-store/<KVS_ID>"
}Set AWS_REGION for the site build. The CloudFront and KeyValueStore clients in scripts/site-build/cloudfront.mjs are created with no region (new CloudFrontClient({})). Tried with the repository's SDK: with no AWS_REGION and no region in an AWS config file, both fail with Region is missing. The S3 calls are not affected (they use S3_REGION). On an EC2 agent nothing sets AWS_REGION by itself, so the invalidation would be recorded as a warning on every build, and redirects would fail. Add a line AWS_REGION=<REGION> (the same value as S3_REGION) to the folder's kims-site-env file (Site job), or set a region in ~/.aws/config for the user Jenkins runs as.
#Console steps
- IAM > Roles > the agent's role (find it below) > Permissions tab > Add permissions > Create inline policy > JSON.
- Paste the policy, values filled in > Next > Policy name
kims-site-build> Create policy.
Find the agent's role if it is an EC2 instance: EC2 > Instances > the agent > Security tab > IAM Role.
PROFILE_ARN=$(aws ec2 describe-instances --instance-ids <AGENT_INSTANCE_ID> \
--query "Reservations[0].Instances[0].IamInstanceProfile.Arn" --output text)
aws iam get-instance-profile --instance-profile-name "${PROFILE_ARN##*/}" \
--query "InstanceProfile.Roles[0].RoleName" --output textPROFILE_ARN=$(aws ec2 describe-instances --instance-ids <AGENT_INSTANCE_ID> \
--query "Reservations[0].Instances[0].IamInstanceProfile.Arn" --output text)
aws iam get-instance-profile --instance-profile-name "${PROFILE_ARN##*/}" \
--query "InstanceProfile.Roles[0].RoleName" --output text$ProfileArn = aws ec2 describe-instances --instance-ids <AGENT_INSTANCE_ID> `
--query "Reservations[0].Instances[0].IamInstanceProfile.Arn" --output text
aws iam get-instance-profile --instance-profile-name $ProfileArn.Split('/')[-1] `
--query "InstanceProfile.Roles[0].RoleName" --output textNone means the instance has no role: KIMS attaches one (The Jenkins agent's own role).
#CLI steps
cat > site-build-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{ "Sid": "ReadAssets", "Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::$ASSETS_BUCKET", "arn:aws:s3:::$ASSETS_BUCKET/*"] },
{ "Sid": "WriteWebsite", "Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::$WEBSITE_BUCKET", "arn:aws:s3:::$WEBSITE_BUCKET/*"] },
{ "Sid": "Invalidate", "Effect": "Allow",
"Action": "cloudfront:CreateInvalidation",
"Resource": "arn:aws:cloudfront::$ACCOUNT:distribution/$DISTRIBUTION_ID" }
]
}
EOF
aws iam put-role-policy --role-name "$AGENT_ROLE" --policy-name kims-site-build --policy-document file://site-build-policy.jsoncat > site-build-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{ "Sid": "ReadAssets", "Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::$ASSETS_BUCKET", "arn:aws:s3:::$ASSETS_BUCKET/*"] },
{ "Sid": "WriteWebsite", "Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::$WEBSITE_BUCKET", "arn:aws:s3:::$WEBSITE_BUCKET/*"] },
{ "Sid": "Invalidate", "Effect": "Allow",
"Action": "cloudfront:CreateInvalidation",
"Resource": "arn:aws:cloudfront::$ACCOUNT:distribution/$DISTRIBUTION_ID" }
]
}
EOF
aws iam put-role-policy --role-name "$AGENT_ROLE" --policy-name kims-site-build --policy-document file://site-build-policy.json@"
{
"Version": "2012-10-17",
"Statement": [
{ "Sid": "ReadAssets", "Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::$AssetsBucket", "arn:aws:s3:::$AssetsBucket/*"] },
{ "Sid": "WriteWebsite", "Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::$WebsiteBucket", "arn:aws:s3:::$WebsiteBucket/*"] },
{ "Sid": "Invalidate", "Effect": "Allow",
"Action": "cloudfront:CreateInvalidation",
"Resource": "arn:aws:cloudfront::${Account}:distribution/$DistributionId" }
]
}
"@ | Set-Content -Encoding ascii site-build-policy.json
aws iam put-role-policy --role-name $AgentRole --policy-name kims-site-build --policy-document file://site-build-policy.jsonput-role-policy prints nothing on success. Running it again replaces the policy, which is how you add UAT's resources or the Redirects statement later.
#The Jenkins platform job: ECR push and EKS deploy
The kims-platform job pushes the image and deploys with Helm. With the ECR credential helper (ECR) and the agent's role mapped in EKS (EKS access entries), it needs:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EcrLogin",
"Effect": "Allow",
"Action": "ecr:GetAuthorizationToken",
"Resource": "*"
},
{
"Sid": "PushImage",
"Effect": "Allow",
"Action": [
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:CompleteLayerUpload",
"ecr:GetDownloadUrlForLayer",
"ecr:InitiateLayerUpload",
"ecr:PutImage",
"ecr:UploadLayerPart"
],
"Resource": "arn:aws:ecr:<REGION>:<AWS_ACCOUNT_ID>:repository/kims/kims-v2"
},
{
"Sid": "WriteKubeconfig",
"Effect": "Allow",
"Action": "eks:DescribeCluster",
"Resource": "arn:aws:eks:<REGION>:<AWS_ACCOUNT_ID>:cluster/<EKS_CLUSTER_NAME>"
}
]
}ecr:GetAuthorizationTokenonly accepts*: it issues a login, and the second statement decides what that login may push to.BatchGetImagealso covers the job'sdocker buildx imagetools inspect, which reuses an image already pushed for the same commit.- Drop
WriteKubeconfigif Jenkins deploys with akims-kubeconfigfile credential instead. - The ECR part is
main's (AWS set-up G);eks:DescribeClusteris from the same section's "Deploying to the cluster".
Console: as for the site job, inline policy name kims-platform.
cat > platform-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{ "Sid": "EcrLogin", "Effect": "Allow", "Action": "ecr:GetAuthorizationToken", "Resource": "*" },
{ "Sid": "PushImage", "Effect": "Allow",
"Action": ["ecr:BatchCheckLayerAvailability", "ecr:BatchGetImage", "ecr:CompleteLayerUpload",
"ecr:GetDownloadUrlForLayer", "ecr:InitiateLayerUpload", "ecr:PutImage", "ecr:UploadLayerPart"],
"Resource": "arn:aws:ecr:$AWS_REGION:$ACCOUNT:repository/kims/kims-v2" },
{ "Sid": "WriteKubeconfig", "Effect": "Allow", "Action": "eks:DescribeCluster",
"Resource": "arn:aws:eks:$AWS_REGION:$ACCOUNT:cluster/$CLUSTER" }
]
}
EOF
aws iam put-role-policy --role-name "$AGENT_ROLE" --policy-name kims-platform --policy-document file://platform-policy.jsoncat > platform-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{ "Sid": "EcrLogin", "Effect": "Allow", "Action": "ecr:GetAuthorizationToken", "Resource": "*" },
{ "Sid": "PushImage", "Effect": "Allow",
"Action": ["ecr:BatchCheckLayerAvailability", "ecr:BatchGetImage", "ecr:CompleteLayerUpload",
"ecr:GetDownloadUrlForLayer", "ecr:InitiateLayerUpload", "ecr:PutImage", "ecr:UploadLayerPart"],
"Resource": "arn:aws:ecr:$AWS_REGION:$ACCOUNT:repository/kims/kims-v2" },
{ "Sid": "WriteKubeconfig", "Effect": "Allow", "Action": "eks:DescribeCluster",
"Resource": "arn:aws:eks:$AWS_REGION:$ACCOUNT:cluster/$CLUSTER" }
]
}
EOF
aws iam put-role-policy --role-name "$AGENT_ROLE" --policy-name kims-platform --policy-document file://platform-policy.json@"
{
"Version": "2012-10-17",
"Statement": [
{ "Sid": "EcrLogin", "Effect": "Allow", "Action": "ecr:GetAuthorizationToken", "Resource": "*" },
{ "Sid": "PushImage", "Effect": "Allow",
"Action": ["ecr:BatchCheckLayerAvailability", "ecr:BatchGetImage", "ecr:CompleteLayerUpload",
"ecr:GetDownloadUrlForLayer", "ecr:InitiateLayerUpload", "ecr:PutImage", "ecr:UploadLayerPart"],
"Resource": "arn:aws:ecr:$($env:AWS_REGION):${Account}:repository/kims/kims-v2" },
{ "Sid": "WriteKubeconfig", "Effect": "Allow", "Action": "eks:DescribeCluster",
"Resource": "arn:aws:eks:$($env:AWS_REGION):${Account}:cluster/$Cluster" }
]
}
"@ | Set-Content -Encoding ascii platform-policy.json
aws iam put-role-policy --role-name $AgentRole --policy-name kims-platform --policy-document file://platform-policy.jsonInline policies on the agent's role apply to every job on that agent. Agree it with KIMS's Jenkins admins first. If they prefer, put KIMS v2's jobs on a dedicated agent (label kims-build) with its own role.
#The Jenkins agent's own role
Usually exists. If the agent has none:
| Agent runs on | Trust policy principal |
|---|---|
| An EC2 instance | { "Service": "ec2.amazonaws.com" } with sts:AssumeRole, attached through an instance profile (IAM console: Roles > Create role > AWS service > EC2; then EC2 > the instance > Actions > Security > Modify IAM role) |
| A pod on EKS | The same shape as the pods' trust policy, naming the agent's own namespace and service account |
| Outside AWS | No role possible. Ask KIMS: the site build would need access keys, which KIMS v2 avoids on purpose |
#Check the policies
#Simulate before the first run
Needs iam:SimulatePrincipalPolicy (KIMS's cloud team has it; ReadOnlyAccess does not include it).
aws iam simulate-principal-policy \
--policy-source-arn "arn:aws:iam::$ACCOUNT:role/kims-app-prod" \
--action-names s3:PutObject s3:GetObject s3:DeleteObject \
--resource-arns "arn:aws:s3:::$ASSETS_BUCKET/originals/test.jpg" \
--query "EvaluationResults[].{action:EvalActionName,decision:EvalDecision}" --output table
aws iam simulate-principal-policy \
--policy-source-arn "arn:aws:iam::$ACCOUNT:role/kims-app-prod" \
--action-names s3:PutObject \
--resource-arns "arn:aws:s3:::$WEBSITE_BUCKET/index.html" \
--query "EvaluationResults[].{action:EvalActionName,decision:EvalDecision}" --output tableaws iam simulate-principal-policy \
--policy-source-arn "arn:aws:iam::$ACCOUNT:role/kims-app-prod" \
--action-names s3:PutObject s3:GetObject s3:DeleteObject \
--resource-arns "arn:aws:s3:::$ASSETS_BUCKET/originals/test.jpg" \
--query "EvaluationResults[].{action:EvalActionName,decision:EvalDecision}" --output table
aws iam simulate-principal-policy \
--policy-source-arn "arn:aws:iam::$ACCOUNT:role/kims-app-prod" \
--action-names s3:PutObject \
--resource-arns "arn:aws:s3:::$WEBSITE_BUCKET/index.html" \
--query "EvaluationResults[].{action:EvalActionName,decision:EvalDecision}" --output tableaws iam simulate-principal-policy `
--policy-source-arn "arn:aws:iam::${Account}:role/kims-app-prod" `
--action-names s3:PutObject s3:GetObject s3:DeleteObject `
--resource-arns "arn:aws:s3:::$AssetsBucket/originals/test.jpg" `
--query "EvaluationResults[].{action:EvalActionName,decision:EvalDecision}" --output table
aws iam simulate-principal-policy `
--policy-source-arn "arn:aws:iam::${Account}:role/kims-app-prod" `
--action-names s3:PutObject `
--resource-arns "arn:aws:s3:::$WebsiteBucket/index.html" `
--query "EvaluationResults[].{action:EvalActionName,decision:EvalDecision}" --output tableYou should see allowed three times for the assets bucket, then implicitDeny for the website bucket: the pods must not be able to write the website. Run the same against the agent's role with cloudfront:CreateInvalidation on arn:aws:cloudfront::<AWS_ACCOUNT_ID>:distribution/<DISTRIBUTION_ID>: allowed.
#Check by use
| Role | Proven by | You should see |
|---|---|---|
| Pods' role | Upload an image in the Media library | Its sizes appear within a minute |
| Pods' role | The content load (Content load) | 11,307 files uploaded |
| Agent, platform | The first kims-platform run |
Image pushed, helm upgrade succeeded |
| Agent, site | The first kims-site-build run |
Stages Bundle media, Sync, Invalidate CloudFront all succeeded (not "warning") |
#If it goes wrong
| What you see | Likely cause | What to do |
|---|---|---|
Pods: Not authorized to perform sts:AssumeRoleWithWebIdentity |
Trust policy sub names another namespace or service account, or the OIDC id is another cluster's |
Compare with system:serviceaccount:<NAMESPACE>:kims and the cluster's issuer |
Pods: InvalidIdentityToken: No OpenIDConnect provider found |
The cluster's OIDC provider is not in IAM | EKS, OIDC provider |
Pods: AccessDenied ... s3:PutObject on the assets bucket |
Policy names another bucket, or a bucket or VPC endpoint policy denies | Check the bucket name; Networking, S3 endpoint |
Site build: AccessDenied at Sync |
Agent lacks website bucket rights, or s3:ListBucket is on bucket/* instead of the bucket |
Put ListBucket on arn:aws:s3:::<WEBSITE_BUCKET> |
Site build: Invalidate CloudFront shows a warning Region is missing |
No AWS_REGION for the build |
Add AWS_REGION=<REGION> to kims-site-env (warning above) |
Site build: Invalidate shows AccessDenied |
Distribution ARN wrong (CloudFront ARNs have no region: arn:aws:cloudfront::<ACCOUNT>:distribution/<ID>) |
Fix the ARN |
Site build: Redirects fails AccessDenied |
No Redirects statement, or the store ARN differs from KIMS_REDIRECTS_KVS_ARN |
Add the statement with the exact ARN |
Platform job: denied: ... ecr:InitiateLayerUpload |
Push statement missing or wrong repository ARN | ARN must end repository/kims/kims-v2 |
MalformedPolicyDocument |
A <...> left in, or a BOM on Windows |
Fill every value; write the file with -Encoding ascii |
#Sources
kims-v2/docs/ON-SITE-DEPLOYMENT.mdonmain(AWS set-up F and G)kims-v2/deploy/jenkins/README.mdandREADME-site.mdonmainkims-v2/deploy/jenkins/Jenkinsfile.site,Jenkinsfile.platformonmainkims-v2/deploy/helm/kims/values-production.example.yaml,templates/serviceaccount.yamlkims-v2/packages/content/src/media/blob-store.ts,kims-v2/packages/content/src/media/keys.tskims-v2/scripts/site-build/s3.mjs,sync.mjs,media.mjs,cloudfront.mjskims-v2/scripts/handover/data-bundle.mjs- https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html
- https://docs.aws.amazon.com/eks/latest/userguide/pod-id-role.html
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-with-s3-policy-actions.html
- https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudfront.html
- https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudfrontkeyvaluestore.html
- https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-push-iam.html
- https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_testing-policies.html
- https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-region.html