<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: sent2020</title>
    <description>The latest articles on Forem by sent2020 (@sent2020).</description>
    <link>https://forem.com/sent2020</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F726066%2F1ad87ef1-64f5-4a63-b749-346ebcbf76d5.png</url>
      <title>Forem: sent2020</title>
      <link>https://forem.com/sent2020</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sent2020"/>
    <language>en</language>
    <item>
      <title>AWS deployment from GitHub Actions with OIDC</title>
      <dc:creator>sent2020</dc:creator>
      <pubDate>Sun, 16 Oct 2022 16:49:45 +0000</pubDate>
      <link>https://forem.com/aws-builders/aws-deployment-from-github-actions-with-oidc-3leo</link>
      <guid>https://forem.com/aws-builders/aws-deployment-from-github-actions-with-oidc-3leo</guid>
      <description>&lt;p&gt;GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. Until AWS provided supported for OIDC, access and secret keys were used to make deployments in the Github Actions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring OpenID Connect in AWS and role creation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create Github as an identity provider in AWS provider with the below values.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Provider URL as https://token.actions.githubusercontent.com
Audience as sts.amazonaws.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure the role with the below trust policy. Replace GitHub org repo details with the details of your organization. Replace AWS account id also&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Federated": "arn:aws:iam::123456123456:oidc-provider/token.actions.githubusercontent.com"
            },
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringLike": {
                    "token.actions.githubusercontent.com:sub": "repo:git-org/git-repo:*"
                },
                "ForAllValues:StringEquals": {
                    "token.actions.githubusercontent.com:iss": "https://token.actions.githubusercontent.com",
                    "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
                }
            }
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Policy for the role can be assigned based on the action which is performed on the AWS account. S3 permissions is assigned for demo purpose.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "Version": "2012-10-17",
  "Statement": {
    "Effect": "Allow",
    "Action": "s3:ListBucket",
    "Resource": "*"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  GitHub Actions workflow
&lt;/h2&gt;

&lt;p&gt;Below permissions needs to be added in the GitHub yaml for use in GitHub Actions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;permissions:
  id-token: write # required to use OIDC authentication
  contents: read # This is required for actions/checkout@v2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is the Github Actions file which will list buckets in an AWS account and also list in the another account using cross account access&lt;/p&gt;

&lt;p&gt;In the step &lt;strong&gt;Assume execution role&lt;/strong&gt; cross account access is achieved by assuming the previous role as environmental variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Hello from AWS
on:
  push:
permissions:
  id-token: write
  contents: read
jobs:
  greeting:
    runs-on: ubuntu-latest
    steps:
    - name: Configure AWS credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-region: us-east-1
        role-to-assume: arn:aws:iam::123456789:role/github-actions
    - name: Print assumed role
      run: aws sts get-caller-identity
    - name: s3 list 
      run: aws s3 ls
    - name: Assume execution role
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
        aws-region: us-east-1
        aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
        aws-session-token: ${{ env.AWS_SESSION_TOKEN }}
        role-duration-seconds: 3000
        role-skip-session-tagging: true
        role-to-assume: arn:aws:iam::123456789:role/github-cross-role
    - name: Print assumed role
      run: aws sts get-caller-identity
    - name: s3 list 
      run: aws s3 ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reference workflow can be found in the repo &lt;a href="https://github.com/sent2020/aws-oidc"&gt;https://github.com/sent2020/aws-oidc&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Crossplane on Amazon EKS with IRSA</title>
      <dc:creator>sent2020</dc:creator>
      <pubDate>Sat, 15 Oct 2022 17:36:50 +0000</pubDate>
      <link>https://forem.com/aws-builders/crossplane-on-amazon-eks-with-irsa-4i51</link>
      <guid>https://forem.com/aws-builders/crossplane-on-amazon-eks-with-irsa-4i51</guid>
      <description>&lt;p&gt;In this post we are going to setup Crossplane on AWS EKS Cluster with IRSA and provision the AWS Cloud Services.&lt;/p&gt;

&lt;p&gt;IRSA is leveraged to launch the AWS Cloud Services&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Amazon EKS&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Amazon EKS is a managed Kubernetes service to run Kubernetes in the AWS cloud&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Crossplane&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Crossplane is a framework for building cloud native control planes without needing to write code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/crossplane/crossplane"&gt;https://github.com/crossplane/crossplane&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;## Launch EKS Cluster with IRSA for Crossplane&lt;/strong&gt;&lt;br&gt;
Leverage EKSCTL to launch the EKS Cluster using the below configuration, provided yaml leverages existing VPC to launch the Cluster. Substitute subnet ids before creating the cluster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  name: crossplane-demo
  region: us-east-1
  version: '1.21'
vpc:
  subnets:
    private:
      us-east-1a: { id: subnet-1234}
      us-east-1b: { id: subnet-1234}
  clusterEndpoints:
    publicAccess:  true
iam:
  withOIDC: true
  serviceAccounts:
  - metadata:
      name: provider-aws-f78664a342f1
      namespace: crossplane-system
    attachPolicyARNs:
    - "arn:aws:iam::aws:policy/AdministratorAccess"
managedNodeGroups:
  - name: crossplane-nodegroup
    labels: { role: workers }
    instanceType: t3a.medium
    desiredCapacity: 1
    volumeSize: 30
    privateNetworking: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the above contents in cluster.yaml and use the below command to create the cluster&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eksctl create cluster -f cluster.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install Crossplane
&lt;/h2&gt;

&lt;p&gt;Install the Crossplane using the helm chart by using the below commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create namespace crossplane-system

helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update

helm install crossplane --namespace crossplane-system crossplane-stable/crossplane
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install Crossplane AWS provider
&lt;/h2&gt;

&lt;p&gt;Provider contains the CRDs to launch the AWS Cloud Services. Apply the below configuration yamls to install the provider. Replace AWS_PROVIDER_ARN with the ARN of the role created during cluster creation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: pkg.crossplane.io/v1alpha1
kind: ControllerConfig
metadata:
  name: aws-config
  annotations:
    eks.amazonaws.com/role-arn: &amp;lt;AWS_PROVIDER_ARN&amp;gt;
spec:
  podSecurityContext:
    fsGroup: 2000
---
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
  name: provider-aws
spec:s
  package: crossplane/provider-aws:v0.24.1
  controllerConfigRef:
    name: aws-config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the below config which will allow Crossplane to use the IRSA role for launching the AWS Cloud Services.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: aws.crossplane.io/v1beta1
kind: ProviderConfig
metadata:
  name: aws-provider
spec:
  credentials:
    source: InjectedIdentity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create a S3 bucket using Crossplane&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Apply the below yaml to test Crossplane setup with IRSA. Once this yaml is applied a S3 bucket will be created in the name s3-demo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: s3.aws.crossplane.io/v1beta1
kind: Bucket
metadata:
  name: s3-demo
spec:
  deletionPolicy: Delete
  forProvider:
    acl: private
    locationConstraint: us-east-1
    serverSideEncryptionConfiguration:
      rules:
        - applyServerSideEncryptionByDefault:
            sseAlgorithm: AES256
    versioningConfiguration:
      status: Enabled
  providerConfigRef:
    name: aws-provider
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Notes&lt;/strong&gt;:
&lt;/h2&gt;

&lt;p&gt;In the EKS Cluster creation Admin policy is used for service account. This policy can be restricted to the particular service like S3, SQS based on the services created through Crossplane. &lt;/p&gt;

</description>
      <category>eks</category>
      <category>kubernetes</category>
      <category>crossplane</category>
    </item>
    <item>
      <title>EKS Security Best Practices</title>
      <dc:creator>sent2020</dc:creator>
      <pubDate>Fri, 15 Oct 2021 17:22:41 +0000</pubDate>
      <link>https://forem.com/aws-builders/eks-security-best-practices-3f18</link>
      <guid>https://forem.com/aws-builders/eks-security-best-practices-3f18</guid>
      <description>&lt;p&gt;In this blog we are going to see the security best practices for EKS cluster related to IRSA roles and service account tokens. &lt;/p&gt;

&lt;h4&gt;
  
  
  Restrict IRSA Trust policy to Service Account Name Scope and Don't use *.
&lt;/h4&gt;

&lt;p&gt;Sample Trust policy for the IRSA role. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;{&lt;br&gt;
    "Version": "2012-10-17",&lt;br&gt;
    "Statement": [{&lt;br&gt;
        "Effect": "Allow",&lt;br&gt;
        "Principal": {&lt;br&gt;
            "Federated": "arn:aws:iam::CI_ACCOUNT_ID:oidc-provider/OIDC_PROVIDER"&lt;br&gt;
        },&lt;br&gt;
        "Action": "sts:AssumeRoleWithWebIdentity",&lt;br&gt;
        "Condition": {&lt;br&gt;
            "StringEquals": {&lt;br&gt;
                "&amp;lt;OIDC_PROVIDER&amp;gt;:sub": "system:serviceaccount:&amp;lt;namespace&amp;gt;:&amp;lt;serviceaccount&amp;gt;"&lt;br&gt;
            }&lt;br&gt;
        }&lt;br&gt;
    }]&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Assume a demo namespace has two IRSA roles create with trust policy &lt;a&gt;system:serviceaccount:demo:*&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;IAM Role 1 - ServiceAccount01 - access to S3 &lt;br&gt;
IAM Role 2 - ServiceAccount02 - access to S3 and DynamoDB&lt;/p&gt;

&lt;p&gt;Pod1 with ServiceAccount01 can access Role 2 just by exporting the &lt;code&gt;AWS_ROLE_ARN = &amp;lt;ARN OF IAM ROLE 2&amp;gt;&lt;/code&gt; so that it will get access to S3 and DynamoDB .&lt;/p&gt;

&lt;h4&gt;
  
  
  Enable IRSA role for aws-node daemonset.
&lt;/h4&gt;

&lt;p&gt;EKS supports IRSA roles for the aws-node daemonset, it is security best practice to use IRSA role instead of system node role. &lt;/p&gt;

&lt;h4&gt;
  
  
  Disable auto-mounting of service account tokens
&lt;/h4&gt;

&lt;p&gt;Update the pod spec with &lt;code&gt;automountServiceAccountToken=false&lt;/code&gt; attribute if there is no need for the application to access EKS Control plane API. &lt;/p&gt;

</description>
      <category>aws</category>
      <category>kubernetes</category>
      <category>security</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
