|
| 1 | +# Setting up AWS environment |
| 2 | + |
| 3 | +You need to have MFA enabled for your AWS user, your `~/.aws/config` shoudl look like this: |
| 4 | +``` |
| 5 | +[profile lfproduct-dev] |
| 6 | +role_arn = arn:aws:iam::395594542180:role/product-contractors-role |
| 7 | +source_profile = lfproduct |
| 8 | +region = us-east-1 |
| 9 | +output = json |
| 10 | +
|
| 11 | +[profile lfproduct-test] |
| 12 | +role_arn = arn:aws:iam::726224182707:role/product-contractors-role |
| 13 | +source_profile = lfproduct |
| 14 | +region = us-east-1 |
| 15 | +output = json |
| 16 | +
|
| 17 | +[profile lfproduct-staging] |
| 18 | +role_arn = arn:aws:iam::844390194980:role/product-contractors-role |
| 19 | +source_profile = lfproduct |
| 20 | +region = us-east-1 |
| 21 | +output = json |
| 22 | +
|
| 23 | +[profile lfproduct-prod] |
| 24 | +role_arn = arn:aws:iam::716487311010:role/product-contractors-role |
| 25 | +source_profile = lfproduct |
| 26 | +region = us-east-1 |
| 27 | +output = json |
| 28 | +
|
| 29 | +[default] |
| 30 | +region = us-east-1 |
| 31 | +output = json |
| 32 | +``` |
| 33 | + |
| 34 | +It defines 4 profiles to use: `dev`, `staging`, `test` and `prod`. |
| 35 | + |
| 36 | +You will be using one of them. |
| 37 | + |
| 38 | + |
| 39 | +Your `~/.aws/credentials` file shoudl initially look like this (replace `redacted`): |
| 40 | +``` |
| 41 | +[lfproduct-long-term] |
| 42 | +aws_secret_access_key = [access_key_redacted] |
| 43 | +aws_access_key_id = [key_id_redacted] |
| 44 | +aws_mfa_device = arn:aws:iam::[arn_number_redacted]:mfa/[your_aws_user_redacted] |
| 45 | +
|
| 46 | +[default] |
| 47 | +aws_access_key_id = [key_id_redacted] |
| 48 | +aws_secret_access_key = [access_key_redacted] |
| 49 | +``` |
| 50 | + |
| 51 | +Now every 36 hours or less you need to refresh your MFA key by calling: `aws-mfa --force --duration 129600 --profile lfproduct`. |
| 52 | + |
| 53 | +When called it adds or replaces the following section (`[lfproduct]` which is used as a source profile for `dev`, `test`, `staging` or `prod` in aws config) in `~/.aws/credentials`: |
| 54 | +``` |
| 55 | +[lfproduct] |
| 56 | +assumed_role = False |
| 57 | +aws_access_key_id = [key_id_redacted] |
| 58 | +aws_secret_access_key = [secret_access_key_redacted] |
| 59 | +aws_session_token = [session_token_redacted] |
| 60 | +aws_security_token = [session_token_redacted] |
| 61 | +expiration = 2024-11-28 16:54:59 [now + 36 hours] |
| 62 | +
|
| 63 | +``` |
| 64 | + |
| 65 | + |
| 66 | +Once you have all of this, you must set a correct set of environment variables to run either `python` or `golang` backends. |
| 67 | + |
| 68 | +To do so you need to get credentials for a specific profile `lfproduct-`: `dev`, `test`, `staging`, `prod`. To see full one-time set of credentials you can call: |
| 69 | +- for `dev`: `` aws sts assume-role --role-arn arn:aws:iam::395594542180:role/product-contractors-role --profile lfproduct --role-session-name lfproduct-dev-session ``. |
| 70 | +- for `prod`: `` aws sts assume-role --role-arn arn:aws:iam::716487311010:role/product-contractors-role --profile lfproduct --role-session-name lfproduct-prod-session ``. |
| 71 | + |
| 72 | +Note - just replace the iam::[number] depending on environment type (`[stage]`) and update `lfproduct-[stage]-name`. |
| 73 | + |
| 74 | +You can set up a script like `setenv.sh` which will set all required variables, example for `dev`: |
| 75 | +``` |
| 76 | +#!/bin/bash |
| 77 | +
|
| 78 | +rm -rf /tmp/aws |
| 79 | +cp -R /root/.aws /tmp/.aws |
| 80 | +
|
| 81 | +data="$(aws sts assume-role --role-arn arn:aws:iam::395594542180:role/product-contractors-role --profile lfproduct --role-session-name lfproduct-dev-session)" |
| 82 | +export AWS_ACCESS_KEY_ID="$(echo "${data}" | jq -r '.Credentials.AccessKeyId')" |
| 83 | +export AWS_SECRET_ACCESS_KEY="$(echo "${data}" | jq -r '.Credentials.SecretAccessKey')" |
| 84 | +export AWS_SESSION_TOKEN="$(echo "${data}" | jq -r '.Credentials.SessionToken')" |
| 85 | +export AWS_SECURITY_TOKEN="$(echo "${data}" | jq -r '.Credentials.SessionToken')" |
| 86 | +
|
| 87 | +export AWS_SDK_LOAD_CONFIG=true |
| 88 | +export AWS_PROFILE='lfproduct-dev' |
| 89 | +export AWS_REGION='us-east-1' |
| 90 | +export AWS_DEFAULT_REGION='us-east-1' |
| 91 | +export DYNAMODB_AWS_REGION='us-east-1' |
| 92 | +export REGION='us-east-1' |
| 93 | +
|
| 94 | +export PRODUCT_DOMAIN='dev.lfcla.com' |
| 95 | +export ROOT_DOMAIN='lfcla.dev.platform.linuxfoundation.org' |
| 96 | +export PORT='5000' |
| 97 | +export STAGE='dev' |
| 98 | +# export STAGE='local' |
| 99 | +export GH_ORG_VALIDATION=false |
| 100 | +export DISABLE_LOCAL_PERMISSION_CHECKS=true |
| 101 | +export COMPANY_USER_VALIDATION=false |
| 102 | +export CLA_SIGNATURE_FILES_BUCKET=cla-signature-files-dev |
| 103 | +``` |
| 104 | + |
| 105 | +Call it via `` . ./setenv.sh `` or `` source setenv.sh `` to execute in the current shell. |
| 106 | + |
| 107 | +You can reset environment variables by exiting the shell session or calling the following `unsetenv.sh` in the current shell via: `` . ./unsetenv.sh `` or `` source unsetenv.sh ``: |
| 108 | +``` |
| 109 | +#!/bin/bash |
| 110 | +rm -rf /tmp/.aws |
| 111 | +unset AWS_PROFILE |
| 112 | +unset AWS_REGION |
| 113 | +unset AWS_ACCESS_KEY_ID |
| 114 | +unset AWS_SECRET_ACCESS_KEY |
| 115 | +unset PRODUCT_DOMAIN |
| 116 | +unset ROOT_DOMAIN |
| 117 | +unset PORT |
| 118 | +unset STAGE |
| 119 | +unset AWS_SESSION_TOKEN |
| 120 | +unset AWS_SECURITY_TOKEN |
| 121 | +unset GH_ORG_VALIDATION |
| 122 | +unset DISABLE_LOCAL_PERMISSION_CHECKS |
| 123 | +unset COMPANY_USER_VALIDATION |
| 124 | +unset CLA_SIGNATURE_FILES_BUCKET |
| 125 | +unset DYNAMODB_AWS_REGION |
| 126 | +unset REGION |
| 127 | +unset AWS_ROLE_ARN |
| 128 | +unset AWS_TOKEN_SERIAL |
| 129 | +unset AWS_SDK_LOAD_CONFIG |
| 130 | +``` |
0 commit comments