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

Overwrite the aws config instead of appending #17

Closed
wants to merge 4 commits into from

Conversation

rdinardi-bw
Copy link

We have a workflow in which we need to run this action multiple times to login to multiple aws accounts. On the second run, appending another default profile will cause an error.

Overwriting the aws config instead of just appending to it.

We have a workflow in which we need to run this action multiple times to login to multiple aws accounts. On the second run, appending the default profile will cause an error. Overwriting the aws config instead of just appending to it.
@mrchief
Copy link
Owner

mrchief commented Jun 29, 2021

@rdinardi-bw thanks for reporting this. I think overwriting had it's own issues which I can't remember now. However, instead of limiting ourselves, how about we take profile as an optional input (defaults to default if not provided) and then we write to

echo -e "[profile $INPUT_PROFILE]\noutput = json" >>"$config"

In your steps, you can set AWS_PROFILE=<whatever> and AWS commands will use that profile.

@rdinardi-bw
Copy link
Author

@mrchief that sounds like a more robust idea. Will do

@rdinardi-bw rdinardi-bw marked this pull request as draft June 30, 2021 14:45
… env vars based on the most recent profile we fetched creds for
@rdinardi-bw
Copy link
Author

@mrchief I don't think configuring a profile is as easy as we first thought. Any updates to the AWS config/credentials that's done in entrypoint.sh is only accessible within the docker image for the action itself. The workflow doesn't have access to that.

One possibility could be to do something like this when adding the env vars to the $GITHUB_ENV:

echo "${INPUT_AWS_PROFILE}_AWS_ACCESS_KEY_ID=${aws_access_key_id}" >> $GITHUB_ENV

So you'd end up with a set of env vars for each profile.

Another possibility would be to give examples of how to create a profile in the workflow in a subsequent step. This requires more work on the part of the user however. And creating a file for the config and credentials within the workflow wasn't easy when I tried doing something like this:

aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default

aws configure was failing with permissions issues. I tried manually adding the config/credentials files and still ran into permissions.

This same issue exists in the official AWS actions:
aws-actions/configure-aws-credentials#112

I think it would be okay to switch back to the original solution of overwriting the aws configuration within the action since the config/credentials aren't being exposed to the workflow itself. Let me know what you think.

entrypoint.sh Outdated
@@ -8,15 +8,15 @@ config="${awsDir}/config"
credentials="${awsDir}/credentials"

mkdir -p "${awsDir}"
echo -e "[profile default]\noutput = json" >"$config"
echo -e "[profile $INPUT_AWS_PROFILE]\noutput = json" >>"$config"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may have to do something like

Suggested change
echo -e "[profile $INPUT_AWS_PROFILE]\noutput = json" >>"$config"
echo -e "[profile ${INPUT_AWS_PROFILE:-default}]\noutput = json" >>"$config"

but if you have tested it to be working fine, then we're good.

@mrchief
Copy link
Owner

mrchief commented Jun 30, 2021

First of all, excellent PR and I love that you took time to add the docs as well as detailed examples in the docs!

Any updates to the AWS config/credentials that's done in entrypoint.sh is only accessible within the docker image for the action itself.

Yup, this is why we export everything to GITHUB_ENV so the usage becomes something like this

- name: Create First AWS profile
  uses: mrchief/aws-creds-okta@master
  with:
    aws_profile: first-profile
    aws_role_arn: arn:aws:iam::account-id:role/role-name
    okta_username: [email protected]
    okta_password: ${{ secrets.OKTA_PASSWORD }}
    okta_app_url: https://mycompany.okta.com/home/amazon_aws/1234567890abcdefghij/123
    okta_mfa_seed: ${{ secrets.OKTA_MFA_SEED }}

- name: Run AWS Commands as First Profile
  run: |
    aws ec2 describe-instances # runs using AWS_PROFILE=first-profile

- name: Create Second AWS profile
  uses: mrchief/aws-creds-okta@master
  with:
    aws_profile: second-profile
    aws_role_arn: arn:aws:iam::account-id:role/role-name
    okta_username: [email protected]
    okta_password: ${{ secrets.OKTA_PASSWORD }}
    okta_app_url: https://mycompany.okta.com/home/amazon_aws/1234567890abcdefghij/123
    okta_mfa_seed: ${{ secrets.OKTA_MFA_SEED }}

- name: Run AWS Commands as Second Profile
  run: |
    aws ec2 describe-instances # runs using AWS_PROFILE=second-profile

@rdinardi-bw
Copy link
Author

ah okay, I see what you're saying now. I'll clean this up and mark it ready for review again. Appreciate you working through this with me.

@rdinardi-bw
Copy link
Author

@mrchief Should we be forcing the user to provide an aws_profile? From the example above, it doesn't really make a difference what the profile name is.

This goes back to what we were talking about earlier. Since we can't really configure the awscli to use profiles and are just passing back the access key, secret key and session token, it seems to me like we should just overwrite the configuration file each time.

There's no real benefit to keeping all the profiles in the config if we aren't able to switch profiles.

@mrchief
Copy link
Owner

mrchief commented Jul 1, 2021

There's no real benefit to keeping all the profiles in the config if we aren't able to switch profiles.

Actually, you're right. So... we did all this work for nothing? 😄

@rdinardi-bw
Copy link
Author

Actually, you're right. So... we did all this work for nothing? 😄

I think I learned some things, so there may have been some benefit 😆

I'm going to switch it back to overwriting the configuration and I'll mark the pr ready to review!

@rdinardi-bw rdinardi-bw marked this pull request as ready for review July 7, 2021 12:01
@rdinardi-bw rdinardi-bw requested a review from mrchief July 7, 2021 12:01
@rdinardi-bw
Copy link
Author

@mrchief any chance you can take another look at this?

@mrchief
Copy link
Owner

mrchief commented Aug 4, 2021

Mostly a readme update, right? If so, I think we should also add a blurb saying how to go about creating multiple profiles and basically summarize the conversation in this thread (including the possible workaround).

On a related note, I found this https://github.community/t/docker-container-action-how-to-persist-files-in-workspace/18441 so there may be a way to persist the profile if we saved the file to /home/runner/work/_temp/_github_home. Maybe worth a try?

mrmeyers99 added a commit to mrmeyers99/aws-creds-okta-action that referenced this pull request Aug 17, 2021
mrmeyers99 added a commit to mrmeyers99/aws-creds-okta-action that referenced this pull request Aug 17, 2021
mrmeyers99 added a commit to mrmeyers99/aws-creds-okta-action that referenced this pull request Aug 17, 2021
mrmeyers99 added a commit to mrmeyers99/aws-creds-okta-action that referenced this pull request Aug 17, 2021
mrmeyers99 added a commit to mrmeyers99/aws-creds-okta-action that referenced this pull request Aug 17, 2021
mrmeyers99 added a commit to mrmeyers99/aws-creds-okta-action that referenced this pull request Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants