|
| 1 | +# dev env |
| 2 | + |
| 3 | +## caveats |
| 4 | +- localstack (community edition) doesn't enforce IAM |
| 5 | +- k8s version compatibility issue with |
| 6 | + |
| 7 | +## clean up |
| 8 | +``` |
| 9 | +sudo rm -rf ./k8s-pki |
| 10 | +mkdir ./k8s-pki |
| 11 | +``` |
| 12 | + |
| 13 | +## start the k8s cluster |
| 14 | + |
| 15 | +``` |
| 16 | +kind create cluster --config ./kind-config.yml |
| 17 | +sudo chmod 644 ./k8s-pki/sa.* |
| 18 | +``` |
| 19 | + |
| 20 | +- it will create the kubernetes cluster, the `kind` docker network we'll join later, populate the `./k8s-pki/` folder with all the kubernetes pki keys. |
| 21 | +- `kubectl get nodes` should return a `Ready` node. |
| 22 | + |
| 23 | + |
| 24 | +## start the other services |
| 25 | + |
| 26 | +we'll start 3 other services : |
| 27 | +- aws localstack to fake aws |
| 28 | +- hydra to have an oidc provider |
| 29 | +- a local container registry (accessible from the outside at `localhost:5000`, from inside the `kind` network at `local-registry:5000`) |
| 30 | + |
| 31 | +``` |
| 32 | +docker-compose up -d |
| 33 | +``` |
| 34 | + |
| 35 | +2 short-lived containers will : |
| 36 | +- setup hydra's sqlite |
| 37 | +- load the serviceaccount `sa` keys in hydra |
| 38 | + |
| 39 | +### check |
| 40 | + |
| 41 | +a `docker ps` should only return only 3 containers : `hydra`, `aws-localstack` & `kind` |
| 42 | + |
| 43 | +if you see one of the 2 other ones restarting, they have a problem, check their logs : |
| 44 | +- `hydra-db-migrate` logs should print `Successfully applied migrations!` |
| 45 | +- `hydra-add-keys` logs should print `JSON Web Key Set successfully imported!` |
| 46 | + |
| 47 | +``` |
| 48 | +curl https://localhost:4444/.well-known/openid-configuration -k |
| 49 | +curl https://localhost:4444/.well-known/jwks.json -k |
| 50 | +``` |
| 51 | + |
| 52 | +should return no error |
| 53 | + |
| 54 | +## register the oidc provider on aws |
| 55 | + |
| 56 | +register hydra as an oidc provider |
| 57 | + |
| 58 | +``` |
| 59 | +export AWS_ACCESS_KEY_ID=test |
| 60 | +export AWS_SECRET_ACCESS_KEY=test |
| 61 | +export AWS_REGION=us-east-1 |
| 62 | +aws --endpoint-url=http://localhost:4566 iam create-open-id-connect-provider --url https://hydra.local:4444 --client-id-list sts.amazonaws.com --thumbprint-list $(./get-hydra-thumbprint.sh) |
| 63 | +``` |
| 64 | + |
| 65 | +NB : with set the client-id used by AWS to a value provided to the api-server (see ./kind-config.yml) |
| 66 | + |
| 67 | +### check |
| 68 | +``` |
| 69 | +aws --endpoint-url=http://localhost:4566 iam list-open-id-connect-providers |
| 70 | +``` |
| 71 | +should return |
| 72 | + |
| 73 | +``` |
| 74 | +{ |
| 75 | + "OpenIDConnectProviderList": [ |
| 76 | + { |
| 77 | + "Arn": "arn:aws:iam::000000000000:oidc-provider/hydra.local:4444" |
| 78 | + } |
| 79 | + ] |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +you can also get details using |
| 84 | +``` |
| 85 | +aws --endpoint-url=http://localhost:4566 iam get-open-id-connect-provider --open-id-connect-provider-arn arn:aws:iam::000000000000:oidc-provider/hydra.local:4444 |
| 86 | +``` |
| 87 | + |
| 88 | +## aws setup |
| 89 | +create : s3 bucket, upload this README, full-access to s3 bucket policy, role with the oidc provider, attach policy to role |
| 90 | + |
| 91 | +``` |
| 92 | +aws --endpoint-url=http://localhost:4566 s3api create-bucket --bucket irsa-test |
| 93 | +aws --endpoint-url=http://localhost:4566 s3 cp ./README.md s3://irsa-test |
| 94 | +aws --endpoint-url=http://localhost:4566 iam create-policy --policy-name my-test-policy --policy-document file://./test/policy.json |
| 95 | +aws --endpoint-url=http://localhost:4566 iam create-role --role-name my-app-role --assume-role-policy-document file://./test/trust-role.json |
| 96 | +aws --endpoint-url=http://localhost:4566 iam attach-role-policy --role-name my-app-role --policy-arn arn:aws:iam::000000000000:policy/my-test-policy |
| 97 | +``` |
| 98 | + |
| 99 | +## setup the webhook |
| 100 | + |
| 101 | +``` |
| 102 | +cd ./webhook |
| 103 | +./deploy.sh |
| 104 | +cd .. |
| 105 | +``` |
| 106 | + |
| 107 | +## deploy irsa-tester |
| 108 | +``` |
| 109 | +kubectl create -f ./test/irsa-tester.yml |
| 110 | +``` |
| 111 | + |
| 112 | +### check |
| 113 | +``` |
| 114 | +k exec irsa-tester -- env | grep AWS |
| 115 | +``` |
| 116 | + |
| 117 | +should return |
| 118 | +``` |
| 119 | +AWS_ROLE_ARN=arn:aws:iam::000000000000:role/my-app-role |
| 120 | +AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token |
| 121 | +``` |
| 122 | + |
| 123 | + |
| 124 | +## resources |
| 125 | + |
| 126 | +https://blog.mikesir87.io/2020/09/eks-pod-identity-webhook-deep-dive/ |
| 127 | + |
| 128 | +https://www.eksworkshop.com/beginner/110_irsa/ |
| 129 | + |
| 130 | +https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc_verify-thumbprint.html |
0 commit comments