Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infrastructure #77

Closed
wants to merge 189 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
997580b
adds the trust policy, the role, a readme to include some comments ab…
carlosvalarezo Aug 17, 2023
706fbd6
removes github directory from the gitignore file in order to use gith…
carlosvalarezo Aug 17, 2023
4869c36
creates the cv-eks-cluster-role role using githubactions to avoid doi…
carlosvalarezo Aug 17, 2023
1c19650
removes action not found
carlosvalarezo Aug 17, 2023
73a5482
removes action not found
carlosvalarezo Aug 17, 2023
8ddc0d1
adds aws-default-region since This is a problem with awscli trying to…
carlosvalarezo Aug 17, 2023
96b2c13
adds aws configure command rather than aws iam create-role directly
carlosvalarezo Aug 17, 2023
f7a4308
uses env to get the secrets and use them in aws configure
carlosvalarezo Aug 18, 2023
aae39af
uses echo to check values
carlosvalarezo Aug 18, 2023
bbc0f8c
uses DEVELOP as part of the env variable in order to retrieve the sec…
carlosvalarezo Aug 18, 2023
20ef118
removes unnecesary echo
carlosvalarezo Aug 18, 2023
38887d5
uses env to validate the secrets available
carlosvalarezo Aug 18, 2023
5cdc4b3
uses env to validate the secrets available
carlosvalarezo Aug 18, 2023
8088326
adds enviroment o define the environment
carlosvalarezo Aug 18, 2023
faed0ad
uses env variables to pass secrets to ther aws configure command
carlosvalarezo Aug 18, 2023
b0f29b4
checks if the credentials file was created
carlosvalarezo Aug 18, 2023
9e1e8b5
checks if the credentials file was created
carlosvalarezo Aug 18, 2023
18202a8
checks if the credentials file was created
carlosvalarezo Aug 18, 2023
a09fa5b
adds region to the command and validates the creds to execute commands
carlosvalarezo Aug 18, 2023
86cc2a0
adds region to the command and validates the creds to execute commands
carlosvalarezo Aug 18, 2023
22535ee
adds region to the command and validates the creds to execute commands
carlosvalarezo Aug 18, 2023
ffab863
adds region to the command and validates the creds to execute commands
carlosvalarezo Aug 18, 2023
f9a9d0f
adds region to the command and validates the creds to execute commands
carlosvalarezo Aug 18, 2023
b50e1ec
sets the env vars for all the steps
carlosvalarezo Aug 18, 2023
d3f9e9d
updates the name of the job and adds the step to attach the policy to…
carlosvalarezo Aug 21, 2023
cc419cd
updates the ubuntu runner and installs jq to extract values later
carlosvalarezo Aug 21, 2023
8b00ebb
moves to env vars cluster role and policy name and use them in the re…
carlosvalarezo Aug 21, 2023
06408da
removes unnecesary install of jq and updates the name of the env vars
carlosvalarezo Aug 21, 2023
2ea1787
adds the steps to create the role and to attach the policy for the no…
carlosvalarezo Aug 21, 2023
5faa55f
configures the yaml file to create the k8s eks cluster via eksctl
carlosvalarezo Aug 21, 2023
3a0feba
setup the runner installing eksctl
carlosvalarezo Aug 21, 2023
ad3f00f
setup the runner installing eksctl
carlosvalarezo Aug 21, 2023
2fe543c
setup the runner installing eksctl
carlosvalarezo Aug 21, 2023
98946d6
updates the path of the script file
carlosvalarezo Aug 21, 2023
f899779
updates the path of the script file
carlosvalarezo Aug 21, 2023
9ea53fc
updates the path of the script file
carlosvalarezo Aug 21, 2023
c30549e
creates the cluster
carlosvalarezo Aug 21, 2023
45414eb
uses the correct file to create the cluster using eksctl
carlosvalarezo Aug 21, 2023
ac8f9fe
create the ssh key files getting the values from the secrets repo
carlosvalarezo Aug 21, 2023
72490f4
creates the .ssh directory
carlosvalarezo Aug 21, 2023
d51df7f
adds new comments and separates the setup of the roles and policies f…
carlosvalarezo Aug 21, 2023
e7f5dff
moves to infrastructure branch and updates the workflow
carlosvalarezo Aug 21, 2023
2ed9284
removes unnecesary code from original repo and updates the deployemnt…
carlosvalarezo Aug 22, 2023
ec9d679
adds eksctl-install.sh file
carlosvalarezo Aug 22, 2023
6d43045
adds missing step to checkout code in the infra pipeline
carlosvalarezo Aug 22, 2023
6021810
creates the deployment workflow to be triggered once the infra is cre…
carlosvalarezo Aug 22, 2023
d667676
sort out the steps correctly
carlosvalarezo Aug 22, 2023
ce56861
encrypts kubeconfig file to use in the develop workflow and have acce…
carlosvalarezo Aug 23, 2023
7b602ea
encrypts kubeconfig file to use in the develop workflow and have acce…
carlosvalarezo Aug 23, 2023
ad53ed0
uses curly brackets for all the env vars and shows the current env vars
carlosvalarezo Aug 23, 2023
af53e47
encodes the encrypted value to sort out the problem of gpg is multili…
carlosvalarezo Aug 23, 2023
f2c7da8
updates the command to include GPG_PRIVATE_KEY as value to import the…
carlosvalarezo Aug 23, 2023
cb440a2
updates the command to include GPG_PRIVATE_KEY as value to import the…
carlosvalarezo Aug 23, 2023
5a4dc5d
updates the command to decode the GPG_PRIVATE_KEY
carlosvalarezo Aug 23, 2023
6528e01
uses the GPG_PUBLIC KEY and encrypts the file to be decrypted by the …
carlosvalarezo Aug 23, 2023
e7d9f1e
removes the skip one step
carlosvalarezo Aug 23, 2023
46ca5da
removes the skip one step
carlosvalarezo Aug 23, 2023
8e3d791
removes the skip one step
carlosvalarezo Aug 23, 2023
2e45b08
skips a couple of steps
carlosvalarezo Aug 23, 2023
6ebff87
skips a couple of steps
carlosvalarezo Aug 23, 2023
4a3e7a5
skips a couple of steps
carlosvalarezo Aug 23, 2023
a50bfd8
disables interactive tty
carlosvalarezo Aug 23, 2023
51bc5b7
disables interactive tty
carlosvalarezo Aug 23, 2023
de58aa2
disables interactive tty
carlosvalarezo Aug 23, 2023
89fa539
disables interactive tty
carlosvalarezo Aug 23, 2023
85a4274
disables interactive tty
carlosvalarezo Aug 23, 2023
53cbc78
disables interactive tty
carlosvalarezo Aug 23, 2023
dba4277
disables interactive tty
carlosvalarezo Aug 23, 2023
ecd2963
disables interactive tty
carlosvalarezo Aug 23, 2023
e13eaba
tries another gpg command to encrypt with symmetric option
carlosvalarezo Aug 23, 2023
f6d6e91
tries openssl alternative rather than gpg
carlosvalarezo Aug 23, 2023
c4306fe
uses passphrase for openssl
carlosvalarezo Aug 23, 2023
5b9f7c7
uses passphrase for openssl
carlosvalarezo Aug 23, 2023
9d89950
uses passphrase for openssl
carlosvalarezo Aug 23, 2023
0d13e10
uses passphrase to encrypt the file using openssl
carlosvalarezo Aug 23, 2023
3724de9
updates the workflow and enables the skipped steps
carlosvalarezo Aug 23, 2023
860a6cd
updates the workflow and enables the skipped steps
carlosvalarezo Aug 23, 2023
db64c47
restores the kubeconfig file that allows to connect to the AWS EKS K8…
carlosvalarezo Aug 23, 2023
82f427f
uses the download-artifact actions
carlosvalarezo Aug 23, 2023
d42acba
uses the dawidd6/action-download-artifact action
carlosvalarezo Aug 23, 2023
12306a8
uses the dawidd6/action-download-artifact action
carlosvalarezo Aug 23, 2023
0ec4e3e
adds the name of the file
carlosvalarezo Aug 23, 2023
51ebaa7
shows kube config
carlosvalarezo Aug 24, 2023
591db5d
Merge pull request #1 from carlosvalarezo/infrastructure
carlosvalarezo Aug 24, 2023
09ee5e8
Merge pull request #2 from carlosvalarezo/develop
carlosvalarezo Aug 24, 2023
057217a
skips the cluster creation
carlosvalarezo Aug 24, 2023
fd3e034
swift to master branch
carlosvalarezo Aug 24, 2023
6b8a59f
creates the role, policy and trust-policy for codepipeline and codebu…
carlosvalarezo Aug 25, 2023
2e5b162
corrects some typos in the name of the files
carlosvalarezo Aug 25, 2023
8b2bd71
Merge pull request #3 from carlosvalarezo/infrastructure
carlosvalarezo Aug 25, 2023
952ab78
updates the name of the branch
carlosvalarezo Aug 25, 2023
55bd91e
updates the name of the branch from master to infrastructure for cv-i…
carlosvalarezo Aug 25, 2023
fe912e5
creates a new workflow to create the kvm and to save the secrets secu…
carlosvalarezo Aug 25, 2023
6cdff68
updates the command to get the KVM ARN
carlosvalarezo Aug 25, 2023
85f02f8
updates the command to get the KVM ARN
carlosvalarezo Aug 25, 2023
97e7eac
updates the command to get the KVM ARN
carlosvalarezo Aug 25, 2023
7221e73
updates the command to get the KVM ARN
carlosvalarezo Aug 25, 2023
4d02585
tries gpg to encrypt the files using these strategies: import the tru…
carlosvalarezo Aug 28, 2023
f7c493b
tries gpg to encrypt the files using these strategies: import the tru…
carlosvalarezo Aug 28, 2023
e3a2763
splits the trust-owners import command in two steps
carlosvalarezo Aug 28, 2023
b4fa74e
uses base64 in order to avoid errors like: missing semicolon and othe…
carlosvalarezo Aug 28, 2023
caacce3
uses file rather than env variable for gpg trust owners
carlosvalarezo Aug 28, 2023
f9a954c
show the content of trust-file
carlosvalarezo Aug 28, 2023
2f31b04
includes the missing env var
carlosvalarezo Aug 28, 2023
8450391
alters the order to formerly import the keys and lately import the tr…
carlosvalarezo Aug 28, 2023
5446c30
alters the order to formerly import the trust owners and lately the keys
carlosvalarezo Aug 28, 2023
3b4cb21
removes the armos and sign flags from gpg command
carlosvalarezo Aug 28, 2023
427d085
lists the files to check if the file got encrypted
carlosvalarezo Aug 28, 2023
632cefc
updates the path of the encrypted file and show the directory where i…
carlosvalarezo Aug 28, 2023
d99f10e
removes the openssl command and uses gpg to encrypt the file
carlosvalarezo Aug 28, 2023
2aa81e6
removes unnecesary code
carlosvalarezo Aug 28, 2023
1c4ea99
creates fake kubeconfig file to test the encryption without creation …
carlosvalarezo Aug 28, 2023
0c6a067
Merge pull request #4 from carlosvalarezo/infrastructure
carlosvalarezo Aug 28, 2023
f01b278
uploads the artifact to the github workspaces to be accesible from an…
carlosvalarezo Aug 28, 2023
00868a1
Merge pull request #5 from carlosvalarezo/infrastructure
carlosvalarezo Aug 28, 2023
265386c
tries gpg to encrypt the files using these strategies: import the tru…
carlosvalarezo Aug 28, 2023
43f2801
tries gpg to encrypt the files using these strategies: import the tru…
carlosvalarezo Aug 28, 2023
d7de65c
splits the trust-owners import command in two steps
carlosvalarezo Aug 28, 2023
dfb74b6
uses base64 in order to avoid errors like: missing semicolon and othe…
carlosvalarezo Aug 28, 2023
6983445
uses file rather than env variable for gpg trust owners
carlosvalarezo Aug 28, 2023
bdb633b
show the content of trust-file
carlosvalarezo Aug 28, 2023
3b2a33e
includes the missing env var
carlosvalarezo Aug 28, 2023
30ca049
alters the order to formerly import the keys and lately import the tr…
carlosvalarezo Aug 28, 2023
2f6da02
alters the order to formerly import the trust owners and lately the keys
carlosvalarezo Aug 28, 2023
395bce7
removes the armos and sign flags from gpg command
carlosvalarezo Aug 28, 2023
30a95d0
lists the files to check if the file got encrypted
carlosvalarezo Aug 28, 2023
8496d30
updates the path of the encrypted file and show the directory where i…
carlosvalarezo Aug 28, 2023
5c076b3
removes the openssl command and uses gpg to encrypt the file
carlosvalarezo Aug 28, 2023
d231b36
removes unnecesary code
carlosvalarezo Aug 28, 2023
4b289bd
creates fake kubeconfig file to test the encryption without creation …
carlosvalarezo Aug 28, 2023
16c6291
uploads the artifact to the github workspaces to be accesible from an…
carlosvalarezo Aug 28, 2023
c31dc3e
downloads the artifact and decrypts kubeconfig
carlosvalarezo Aug 29, 2023
2145a60
adds the missing env vars
carlosvalarezo Aug 29, 2023
33e11d5
shows the values
carlosvalarezo Aug 29, 2023
ca8b775
shows the values
carlosvalarezo Aug 29, 2023
185598c
shows the values
carlosvalarezo Aug 29, 2023
f9bb720
checkout the code
carlosvalarezo Aug 29, 2023
ec47724
lists the content of GITHUB_WORKSPACE
carlosvalarezo Aug 29, 2023
be3973a
shows the env vars
carlosvalarezo Aug 29, 2023
170728c
gets the RUN_ID of the workflow that uploaded the artifact in order t…
carlosvalarezo Aug 29, 2023
6a13f5e
downloads the artifiact: kube_config in a different directory to decr…
carlosvalarezo Aug 29, 2023
62356b4
includes the tty env var to sort out Inappropriate ioctl for device e…
carlosvalarezo Aug 29, 2023
516c0f2
solves typo in the decrypt command
carlosvalarezo Aug 29, 2023
1fe3a36
fixes decryption command
carlosvalarezo Aug 29, 2023
9c5e56b
show the content of artifiacts directory
carlosvalarezo Aug 29, 2023
d0e1ccd
uses different gpg command
carlosvalarezo Aug 29, 2023
b2af628
shows gpg keys avaalable
carlosvalarezo Aug 29, 2023
c57efb9
shows gpg secret keys available
carlosvalarezo Aug 29, 2023
c424622
uses recipinet flag in the gpg decrypt command
carlosvalarezo Aug 29, 2023
4fa9f8d
changes the recipient Id to email in the gpg command
carlosvalarezo Aug 29, 2023
8c9bf83
adds the name of the file to the gpgp command
carlosvalarezo Aug 29, 2023
fda0622
removes the name of gpg file since it was already in the directory
carlosvalarezo Aug 29, 2023
e261f8e
comments GPG_TTY env var
carlosvalarezo Aug 29, 2023
2a04aa5
uses the file gpg.conf and gpg-agent.conf to sort out public key decr…
carlosvalarezo Aug 29, 2023
81a1187
fixes touch rather than tail
carlosvalarezo Aug 29, 2023
674e466
reenable tty to sort out the problem: cannot open /dev/tty: No such d…
carlosvalarezo Aug 29, 2023
97f89b8
adds no-tty flag to sort out the problem: cannot open /dev/tty: No su…
carlosvalarezo Aug 29, 2023
569f70d
disables GPG_TTY env var to sort out the problem: cannot open /dev/tt…
carlosvalarezo Aug 29, 2023
c549df5
enables GPG_TTY env var and flags batch and yes to gpg command to sor…
carlosvalarezo Aug 29, 2023
4b380ee
removes flags batch and yes to gpg command to sort out the problem: c…
carlosvalarezo Aug 29, 2023
9dd1a6e
adds the passphrase to gpg command to sort out the problem: cannot op…
carlosvalarezo Aug 29, 2023
161ec4e
uses the default-key flag in gpg command to sort out the problem: can…
carlosvalarezo Aug 29, 2023
b00a754
checks the recipients for the encrypted file
carlosvalarezo Aug 29, 2023
0e6b6ed
reduces the gpg command to the minimum flags
carlosvalarezo Aug 29, 2023
82e8db6
tries another gpg command with the passphrase as parameter an another…
carlosvalarezo Aug 29, 2023
0fdf8d3
decrypts the file in the final destination once everything is working…
carlosvalarezo Aug 29, 2023
0e03cfc
removes the GPG_TTY env var
carlosvalarezo Aug 29, 2023
ecc0b52
removes unnecesary code
carlosvalarezo Aug 30, 2023
bc04661
creates a new script to setup the gpg agent. It includes the step to …
carlosvalarezo Aug 30, 2023
407d40f
updates the artifact name
carlosvalarezo Aug 30, 2023
bb8b6a4
includes the dependency between jobs to let the first job to produce …
carlosvalarezo Aug 30, 2023
9c4d5fc
updates the name of the artifact
carlosvalarezo Aug 30, 2023
9b11d6e
updates the path of the downloaded artifact
carlosvalarezo Aug 30, 2023
f8c2818
lists the workspace to see the files
carlosvalarezo Aug 30, 2023
d58f42c
checks the env var to be used in later steps
carlosvalarezo Aug 30, 2023
7eef591
updates the env var assignement
carlosvalarezo Aug 30, 2023
4c5bacb
inserts the very first securesctring in the aws ssm
carlosvalarezo Aug 30, 2023
d65e852
adds the setup credentials step
carlosvalarezo Aug 30, 2023
04720db
encloses in quotes the arn kvm
carlosvalarezo Aug 30, 2023
05c2a28
fixes typo in aws credentials env vars name
carlosvalarezo Aug 30, 2023
4e62aae
removes unnecesary code and includes region flag in the aws ssm param…
carlosvalarezo Aug 30, 2023
4d9f31f
updates the region both in the action to setup aws creds and in the a…
carlosvalarezo Aug 30, 2023
c7ce018
updates the aws ssm command and uses env vars in the respective place…
carlosvalarezo Aug 31, 2023
ee9de1e
uses the vars value in the region field
carlosvalarezo Aug 31, 2023
4bacbda
adds the flag overwrite to do it when the secret already exists
carlosvalarezo Aug 31, 2023
9428fc7
fixes the typos in the aws ssm commands
carlosvalarezo Aug 31, 2023
341d7f1
Merge branch 'master' into secrets
carlosvalarezo Sep 1, 2023
0311573
Merge pull request #6 from carlosvalarezo/secrets
carlosvalarezo Sep 1, 2023
16ed879
uses env variables to create the IAM resources. Also updates the file…
carlosvalarezo Sep 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/scripts/eksctl-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

ARCH=amd64
PLATFORM=$(uname -s)_$ARCH

curl -sLO "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_$PLATFORM.tar.gz"

# (Optional) Verify checksum
curl -sL "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_checksums.txt" | grep $PLATFORM | sha256sum --check

tar -xzf eksctl_$PLATFORM.tar.gz -C /tmp && rm eksctl_$PLATFORM.tar.gz

sudo mv /tmp/eksctl /usr/local/bin
10 changes: 10 additions & 0 deletions .github/scripts/gpg-agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

echo ${GPG_TRUST_OWNERS} | base64 --decode > trust-file
gpg --import-ownertrust < trust-file
echo ${GPG_PUBLIC_KEY} | base64 --decode | gpg --import
echo ${GPG_PRIVATE_KEY} | base64 --decode | gpg --import --batch
echo "use-agent" >> ${HOME}/.gnupg/gpg.conf
echo "pinentry-mode loopback" >> ${HOME}/.gnupg/gpg.conf
touch ${HOME}/.gnupg/gpg-agent.conf
echo "allow-loopback-pinentry" >> ${HOME}/.gnupg/gpg-agent.conf
3 changes: 3 additions & 0 deletions .github/scripts/gpg-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

sudo apt-get install gnupg
15 changes: 15 additions & 0 deletions .github/scripts/kubectl-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

echo "Validate the instalation"

curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"

echo "$(cat kubectl.sha256) kubectl" | sha256sum --check

if [ $? -eq 0 ]; then
echo "Previous command was successful"
else
echo "Previous command failed"
fi
101 changes: 101 additions & 0 deletions .github/workflows/cv-infrastructure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Create AWS infrastructure
on:
push:
branches:
- infrastructure
jobs:
setup_roles_and_policies:
runs-on: ubuntu-latest
environment:
name: develop
env:
CLUSTER_ROLE_NAME: ${{ vars.CLUSTER_ROLE_NAME }}
CLUSTER_POLICY_NAME: ${{ vars.CLUSTER_POLICY_NAME }}
NODEGROUP_ROLE_NAME: ${{ vars.NODEGROUP_ROLE_NAME }}
NODEGROUP_POLICY_NAME: ${{ vars.NODEGROUP_POLICY_NAME }}
CODEPIPELINE_ROLE_NAME: ${{ vars.CODEPIPELINE_ROLE_NAME }}
CODEPIPELINE_POLICY_NAME: ${{ vars.CODEPIPELINE_POLICY_NAME }}
CODEBUILD_ROLE_NAME: ${{ vars.CODEBUILD_ROLE_NAME }}
CODEBUILD_POLICY_NAME: ${{ vars.CODEBUILD_POLICY_NAME }}
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Setup AWS CLI
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}

- name: Creates the role that will assume the trust policy to deal with the cluster
run: aws iam create-role --role-name ${CLUSTER_ROLE_NAME} --assume-role-policy-document file://${GITHUB_WORKSPACE}/eksk8s/eks-cluster-trust-policy.json

- name: Attaches the policy to the cluster role
run: aws iam put-role-policy --role-name ${CLUSTER_ROLE_NAME} --policy-name ${CLUSTER_POLICY_NAME} --policy-document file://${GITHUB_WORKSPACE}/eksk8s/eks-cluster-policy.json

- name: Creates the role that will assume the trust policy to deal with the node-group
run: aws iam create-role --role-name ${NODEGROUP_ROLE_NAME} --assume-role-policy-document file://${GITHUB_WORKSPACE}/eksk8s/eks-nodegroup-trust-policy.json

- name: Attaches the policy for the node-group role
run: aws iam put-role-policy --role-name ${NODEGROUP_ROLE_NAME} --policy-name ${NODEGROUP_POLICY_NAME} --policy-document file://${GITHUB_WORKSPACE}/eksk8s/eks-nodegroup-policy.json

- name: Create the role that will assume the trust policy to deal with the codepipeline service
run: aws iam create-role --role-name ${CODEPIPELINE_ROLE_NAME} --assume-role-policy-document file://${GITHUB_WORKSPACE}/eksk8s/codepipeline-trust-policy.json

- name: Attaches the policy for the codepipeline role
run: aws iam put-role-policy --role-name ${CODEPIPELINE_ROLE_NAME} --policy-name ${CODEPIPELINE_POLICY_NAME} --policy-document file://${GITHUB_WORKSPACE}/eksk8s/codepipeline-policy.json

- name: Create the role that will assume the trust policy to deal with the codebuild service
run: aws iam create-role --role-name ${CODEBUILD_ROLE_NAME} --assume-role-policy-document file://${GITHUB_WORKSPACE}/eksk8s/codebuild-trust-policy.json

- name: Attaches the policy for the codebuild role
run: aws iam put-role-policy --role-name ${CODEBUILD_ROLE_NAME} --policy-name ${CODEBUILD_POLICY_NAME} --policy-document file://${GITHUB_WORKSPACE}/eksk8s/codebuild-policy.json

create_the_cluster:
runs-on: ubuntu-latest
needs: setup_roles_and_policies
environment:
name: develop
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_PUBLIC_KEY: ${{ secrets.SSH_PUBLIC_KEY }}
GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_TRUST_OWNERS: ${{ secrets.GPG_TRUST_OWNERS }}
RECIPIENT_ID: ${{ secrets.RECIPIENT_ID }}
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Setup the runner
run: |
sh ${GITHUB_WORKSPACE}/.github/scripts/eksctl-install.sh
sh ${GITHUB_WORKSPACE}/.github/scripts/gpg-install.sh

- name: Setup the keys used to create the k8s cluster
run: |
mkdir ${HOME}/.ssh/
echo ${SSH_PRIVATE_KEY} > ${HOME}/.ssh/k8s
echo ${SSH_PUBLIC_KEY} > ${HOME}/.ssh/k8s.pub

- name: Import the gpg components
run: |
echo ${GPG_TRUST_OWNERS} | base64 --decode > trust-file
gpg --import-ownertrust < trust-file
echo ${GPG_PUBLIC_KEY} | base64 --decode | gpg --import
echo ${GPG_PRIVATE_KEY} | base64 --decode | gpg --import --batch

- name: Creates the k8s cluster using eksctl
run: eksctl create cluster -f ${GITHUB_WORKSPACE}/eksk8s/cluster-config.yaml

- name: Encrypts the kubeconfig file
run: gpg --encrypt -r ${RECIPIENT_ID} --output kube_config.gpg ${HOME}/.kube/config

- name: Pushes kubeconfig artifact
uses: actions/[email protected]
with:
name: kube_config.gpg
path: ${{ github.workspace }}
45 changes: 45 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy app to AWS
on:
push:
branches:
- develop
jobs:
get_k8s_config:
runs-on: ubuntu-latest
environment:
name: develop
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
CLUSTER_ROLE_NAME: cv-eks-cluster-role
CLUSTER_POLICY_NAME: cv-eks-cluster-policy
NODEGROUP_ROLE_NAME: cv-eks-nodegroup-role
NODEGROUP_POLICY_NAME: cv-eks-nodegroup-policy
PASSPHRASE: ${{ secrets.PASSPHRASE }}
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Setup the runner
run: sh $GITHUB_WORKSPACE/.github/scripts/kubectl-install.sh

- name: Setup AWS credentials
run: |
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID}
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY}
aws configure set default.region us-west-1

- name: Download Artifact
uses: dawidd6/[email protected]
with:
workflow: cv-infrastructure.yml
name: kube_config.enc

- name: Restore the kubeconfig file
run: |
mkdir $HOME/.kube/
openssl enc -d -aes-256-cbc -in kube_config.enc -out $HOME/.kube/config -k ${PASSPHRASE}
cat $HOME/.kube/config

- name: Get awsauth config map
run: kubectl get -n kube-system configmap/aws-auth -o yaml > aws-auth-patch.yml
19 changes: 0 additions & 19 deletions .github/workflows/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,3 @@ jobs:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}

- name: Create NEW JIRA ticket
id: create
uses: atlassian/gajira-create@master
with:
project: CONUPDATE
issuetype: Task
summary: |
Github PR - nd0044 - Full Stack Nanodegree C4 | Repo: ${{ github.repository }} | PR# ${{github.event.number}}
description: |
Repo link: https://github.com/${{ github.repository }}
PR no. ${{ github.event.pull_request.number }}
PR title: ${{ github.event.pull_request.title }}
PR description: ${{ github.event.pull_request.description }}
In addition, please resolve other issues, if any.
fields: '{"components": [{"name":"nd0044 - Full Stack Nanodegree"}], "customfield_16449":"https://classroom.udacity.com/nanodegrees/nd0044/dashboard/overview", "customfield_16450":"Resolve the PR", "labels": ["github"], "priority":{"id": "4"}}'

- name: Log created issue
run: echo "Issue ${{ steps.create.outputs.issue }} was created"
128 changes: 128 additions & 0 deletions .github/workflows/secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Create AWS infrastructure
on:
push:
branches:
- infrastructure
jobs:
setup_roles_and_policies:
if: false
runs-on: ubuntu-latest
environment:
name: develop
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
CLUSTER_ROLE_NAME: cv-eks-cluster-role
CLUSTER_POLICY_NAME: cv-eks-cluster-policy
NODEGROUP_ROLE_NAME: cv-eks-nodegroup-role
NODEGROUP_POLICY_NAME: cv-eks-nodegroup-policy
CODEPIPELINE_ROLE_NAME: cv-codepipeline-role
CODEPIPELINE_POLICY_NAME: cv-codepipeline-policy
CODEBUILD_ROLE_NAME: cv-codebuild-role
CODEBUILD_POLICY_NAME: cv-codebuild-policy
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Setup AWS credentials
run: |
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID}
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY}
aws configure set default.region us-west-1

- name: Creates the role that will assume the trust policy to deal with the cluster
run: aws iam create-role --role-name ${CLUSTER_ROLE_NAME} --assume-role-policy-document file://${GITHUB_WORKSPACE}/eksk8s/eks-cluster-trust-policy.json

- name: Attaches the policy to the cluster role
run: aws iam put-role-policy --role-name ${CLUSTER_ROLE_NAME} --policy-name ${CLUSTER_POLICY_NAME} --policy-document file://${GITHUB_WORKSPACE}/eksk8s/eks-cluster-policy.json

- name: Creates the role that will assume the trust policy to deal with the node-group
run: aws iam create-role --role-name ${NODEGROUP_ROLE_NAME} --assume-role-policy-document file://${GITHUB_WORKSPACE}/eksk8s/eks-nodegroup-trust-policy.json

- name: Attaches the policy for the node-group role
run: aws iam put-role-policy --role-name ${NODEGROUP_ROLE_NAME} --policy-name ${NODEGROUP_POLICY_NAME} --policy-document file://${GITHUB_WORKSPACE}/eksk8s/eks-nodegroup-policy.json

- name: Create the role that will assume the trust policy to deal with the codepipeline service
run: aws iam create-role --role-name ${CODEPIPELINE_ROLE_NAME} --assume-role-policy-document file://${GITHUB_WORKSPACE}/eksk8s/codepipeline-trust-policy.json

- name: Attaches the policy for the codepipeline role
run: aws iam put-role-policy --role-name ${CODEPIPELINE_ROLE_NAME} --policy-name ${CODEPIPELINE_POLICY_NAME} --policy-document file://${GITHUB_WORKSPACE}/eksk8s/codepipeline-policy.json

- name: Create the role that will assume the trust policy to deal with the codebuild service
run: aws iam create-role --role-name ${CODEBUILD_ROLE_NAME} --assume-role-policy-document file://${GITHUB_WORKSPACE}/eksk8s/codebuild-trust-policy.json

- name: Attaches the policy for the codebuild role
run: aws iam put-role-policy --role-name ${CODEBUILD_ROLE_NAME} --policy-name ${CODEBUILD_POLICY_NAME} --policy-document file://${GITHUB_WORKSPACE}/eksk8s/codebuild-policy.json

create_the_cluster:
if: false
runs-on: ubuntu-latest
# needs: setup_roles_and_policies
environment:
name: develop
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_PUBLIC_KEY: ${{ secrets.SSH_PUBLIC_KEY }}
GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_TRUST_OWNERS: ${{ secrets.GPG_TRUST_OWNERS }}
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Setup the runner
run: |
sh ${GITHUB_WORKSPACE}/.github/scripts/eksctl-install.sh
sh ${GITHUB_WORKSPACE}/.github/scripts/gpg-install.sh

- name: Setup the keys used to create the k8s cluster
if: false
run: |
mkdir ${HOME}/.ssh/
echo ${SSH_PRIVATE_KEY} > ${HOME}/.ssh/k8s
echo ${SSH_PUBLIC_KEY} > ${HOME}/.ssh/k8s.pub

- name: Creates the k8s cluster using eksctl
if: false
run: eksctl create cluster -f ${GITHUB_WORKSPACE}/eksk8s/cluster-config.yaml

- name: Import the gpg components
run: |
echo ${GPG_TRUST_OWNERS} | base64 --decode > trust-file
gpg --import-ownertrust < trust-file
echo ${GPG_PUBLIC_KEY} | base64 --decode | gpg --import
echo ${GPG_PRIVATE_KEY} | base64 --decode | gpg --import --batch

- name: Creates fake kubeconfig file
run: |
mkdir ${HOME}/.kube/
cat << EOF > ${HOME}/.kube/config
Line1
EOF

- name: Encrypts the kubeconfig file
run: gpg --encrypt -r [email protected] --output kube_config.gpg ${HOME}/.kube/config

- name: Pushes kubeconfig artifact
uses: actions/[email protected]
with:
name: kube_config.gpg
path: ${{ github.workspace }}

manages_aws_secrets:
runs-on: ubuntu-latest
needs: create_the_cluster
if: false
environment:
name: develop
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
CODEPIPELINE_ROLE_NAME: cv-codepipeline-role
CODEPIPELINE_POLICY_NAME: cv-codepipeline-policy
steps:
- name: Stores the GH_TOKEN in AWS Systems Manager Parameter Store
run: aws ssm put-parameter --name "MySecureStringParameter" --value "MySuperSecretValue" --type "SecureString" --key-id "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ htmlcov/
.envrc
.direnv

.github/**
38 changes: 38 additions & 0 deletions eksk8s/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
With regard to the file eks-cluster-policy.json:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"eks:CreateCluster",
"eks:DescribeCluster",
"eks:UpdateClusterConfig",
"eks:UpdateClusterVersion",
"ssm:GetParameters"
],
"Resource": "*" // * means that the already defined actions could be applied to any EKS cluster in the account
}
]
}

In the file eksk8s/cluster-config.yaml the key nodeGroups.iam.instanceRoleARN has the value=arn:aws:iam::62132xxxx821:role/cv-eks-nodegroup-role. In a real project this file should be created using jinja/cookicutter in a previous step. This file should never have hard-coded values. However, for educational purposes/save time these values are hardcoded in the file.

This key pair was created in aws console. It is possible to do it using the command to create it. This step involves pushing (uploading) the keys to aws via aws cli or somehow.

The subnets were also created by hand in the aws console.

The command `eksctl create cluster -f <file_name>` creates the file `$HOME/.kube/config` This file is the one that has the context to connect to the remote cluster. Then to store this file securely, the file should be encrypted and published in the artifacts list of the github repo. Then, in a linux terminal generate the gpg key with the command `gpg --full-generate-key`. For educational purposes I have not included a passphrase nor expiration date for this gpg key set. After, get the ID of the just created `gpg` with the command: `gpg --list-keys` Then, using the commands: `gpg --export -a KEY_ID | base64 -w 0 > public.asc` and `gpg --export-secret-keys -a KEY_ID | base64 -w 0 > private.asc` export the gpg keys that will be stored as secrets in GitHub actions. After, in the workflow import the gpg key to encrypt the file and then upload as artifact to GitHub actions repo.

#### Note:
For reference on how to deal with base64 and gpg keys use this link: https://dev.to/epam_india_python/how-we-set-up-gpg-keys-as-environment-variables-2f26

In order to sort out the problem: `Fixing GPG "Inappropriate ioctl for device" errors` I run these commands:
`echo "use-agent" >> ${HOME}/.gnupg/gpg.conf
echo "pinentry-mode loopback" >> ${HOME}/.gnupg/gpg.conf
touch ${HOME}/.gnupg/gpg-agent.conf
echo "allow-loopback-pinentry" >> ${HOME}/.gnupg/gpg-agent.conf`

This command: `echo ${GPG_PASSPHRASE} | gpg --batch --yes --passphrase-fd 0 --output ${HOME}/.kube/config --decrypt ${GITHUB_WORKSPACE}/artifacts/kube_config.gpg` sorts out these errors: `gpg: cannot open '/dev/tty': No such device or address` The command avoids the interaction with the command line. In this scenario, Github Actions does not have an interactive environment.

Loading