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

fix: fixed logic to determine if long-term credentials is used #904

Closed
wants to merge 8 commits into from

Conversation

ponkio-o
Copy link

*Issue #885

Description of changes:

The current logic looks to see if AWS_SESSION_TOKEN is present, which is causing unnecessary warnings when using a self-hosted runner with EC2 instance profile.
Since this warning is originally issued when only AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set, I fixed the logic to determine.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ponkio-o
Copy link
Author

However, this fix doesn't cover all cases. For example, the warning is not displayed when using IAM User as shown below.

      - name: Setup aws credentials
        uses: aws-actions/[email protected]
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ap-northeast-1

To cover these, it is necessary to make sure that no other inputs are set in more upstream functions. Like this

if (
!!roleToAssume &&
!webIdentityTokenFile &&
!AccessKeyId &&
!process.env['ACTIONS_ID_TOKEN_REQUEST_TOKEN'] &&
!roleChaining
) {
core.info(
'It looks like you might be trying to authenticate with OIDC. Did you mean to set the `id-token` permission? ' +
'If you are not trying to authenticate with OIDC and the action is working successfully, you can ignore this message.'
);
}
return (
!!roleToAssume &&
!!process.env['ACTIONS_ID_TOKEN_REQUEST_TOKEN'] &&
!AccessKeyId &&
!webIdentityTokenFile &&
!roleChaining
);
};

@@ -874,6 +874,8 @@ describe('Configure AWS Credentials', () => {

test('prints warning for access key usage and no session token', async () => {
jest.spyOn(core, 'getInput').mockImplementation(mockGetInput(ASSUME_ROLE_INPUTS));
process.env['AWS_ACCESS_KEY_ID'] = FAKE_ACCESS_KEY_ID;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also have another test without these lines you've added to verify that the warning does NOT throw

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your review! I added test check doesn't show warning when using STS access key.
3e570a9

@jplock
Copy link
Contributor

jplock commented Nov 1, 2023

We could also validate the prefix of the access key per https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-unique-ids

@ponkio-o
Copy link
Author

ponkio-o commented Nov 1, 2023

We could also validate the prefix of the access key per
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-unique-ids

+1
It's looks very good! It would be more reliable and simpler to look at prefixes to detect long-term credentials.

// IAM access key starts with 'AKIA' prefix.
// https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-unique-ids
if (accessKey) {
if (accessKey.startsWith('AKIA')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Combine these into one condition separated by &&?

Copy link
Contributor

Choose a reason for hiding this comment

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

I’d also define AKIA as a constant up above with the link to the documentation.

Copy link
Author

Choose a reason for hiding this comment

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

@jplock Thank you for your suggestion!
I fixed using constant and to simplify if condition.
018873b

Copy link
Author

Choose a reason for hiding this comment

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

@ponkio-o ponkio-o requested a review from jplock November 1, 2023 13:53
Copy link
Contributor

@jplock jplock left a comment

Choose a reason for hiding this comment

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

Looks good to me

@peterwoodworth
Copy link
Contributor

Brilliant @jplock, that's a fantastic solution. Thank you both very much for working on this and bringing a solution to the table 🙂

Not a requirement at all, feel free to disagree with this slight nit, I think I would redefine the const as an all caps const at the top of the file, just below the imports. Other than that I think this looks perfect.

I'm not a maintainer here anymore, so I cannot give approval, but I'm sure the current maintainers will have time to take a look relatively soon

@jplock
Copy link
Contributor

jplock commented Nov 1, 2023

+1 I agree with that (constants should be in all caps and defined near the top outside of the function).

@ponkio-o
Copy link
Author

ponkio-o commented Nov 2, 2023

Thank you @jplock and @peterwoodworth!
Please check it out, as I fixed it!
314fe97

@ponkio-o ponkio-o requested a review from jplock November 2, 2023 02:43
@jplock
Copy link
Contributor

jplock commented Nov 3, 2023

@tim-finnigan would you be able to review this PR please?

@tim-finnigan
Copy link
Contributor

Thanks for creating this PR! I think we want to be careful about hard coding prefixes that could change, or may not apply to every intended scenario. But the changes here are probably fine. We are planning to discuss this PR further this week, and will likely also want to confirm our thinking with someone from the IAM team before approving this.

@ponkio-o
Copy link
Author

Hi @tim-finnigan, Do you have any update?

@tim-finnigan
Copy link
Contributor

Hi @ponkio-o thanks for your patience. We discussed this topic further as a team and decided to remove the warning. There are more details in this PR: #926.

Thanks again for working on this PR. While I think the changes here are an improvement to the existing warning conditions, we are hesitant to specify hard-coded IAM prefixes that could also change in the future.

@ponkio-o
Copy link
Author

@tim-finnigan
Thank you for your reply! I agree your approach (to delete this warning). Also, I agree your talk about "Shared Responsibility Model".

So, I will close this PR.

@ponkio-o ponkio-o closed this Nov 22, 2023
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.

4 participants