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

Include IAM role in ec2 data (issue #1524) #1525

Merged
merged 1 commit into from
Oct 14, 2020

Conversation

kcbraunschweig
Copy link
Contributor

Description

Currently the ohai ec2 plugin reads from the AWS metadata service but strips out all IAM data to prevent leaking security credentials. Change modifies this filtering slightly to still include the IAM role-name which is part of the metadata at:
iam/security-credentials/role-name
see: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-categories.html
Don't include the data returned in the document under role-name as that includes actually includes credentials, but the name part isn't a security concern and is useful to people to know the IAM identity of the instance where chef is running.

In the solution i'm being fairly paranoid checking explicitly for the security-credentials key and that it has exactly 1 key below it. As far as I can tell 'security-credentials' will only exist at all if there's an associated role, in fact if there's no role 'iam' won't exist at all and there can only be 1 associated role at any one time ever. So in reality if the IAM key exists at all, then there should be exactly 1 role name for us to find always. But yay paranoia, happy to do it however people like.

Related Issue

#1524

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

@kcbraunschweig kcbraunschweig requested review from a team as code owners October 8, 2020 00:21
@kcbraunschweig
Copy link
Contributor Author

those test failures don't seem related to this change but lmk if there's something I need to do there.

@phiggins
Copy link
Contributor

phiggins commented Oct 8, 2020

This seems like a good addition, but it makes me wonder if there's more relevant information here or a more complete way to handle this. In other words I'm suspicious that this satisfies one use case and could lead to a creeping addition of more things.

@phiggins
Copy link
Contributor

phiggins commented Oct 8, 2020

those test failures don't seem related to this change but lmk if there's something I need to do there.

You're correct, the CI failures are unrelated.

@kcbraunschweig
Copy link
Contributor Author

kcbraunschweig commented Oct 8, 2020

This seems like a good addition, but it makes me wonder if there's more relevant information here or a more complete way to handle this. In other words I'm suspicious that this satisfies one use case and could lead to a creeping addition of more things.

This is the full structure:

  "iam": {
    "info": {
      "Code": "Success",
      "LastUpdated": "2020-10-07T18:44:07Z",
      "InstanceProfileArn": "arn:aws:iam::123456789:instance-profile/foo",
      "InstanceProfileId": "AAAAAAAAAAAAAFCK"
    },
    "security-credentials": {
      "foo": {
        "Code": "Success",
        "LastUpdated": "2020-10-07T18:43:37Z",
        "Type": "AWS-HMAC",
        "AccessKeyId": "VERYSECRET",
        "SecretAccessKey": "j+VERYSECRETSETUFF",
        "Token": "IQo/VERYSECRETSTUFFQ==",
        "Expiration": "2020-10-08T01:10:52Z"
      }
    }
  }

The only other bits that seem potentially interesting to me are InstanceProfileArn and InstanceProfileId. It could change if they added something in the future but I'm wary of trying to future proof because they might add something new that we want to exclude.

@jaymzh
Copy link
Collaborator

jaymzh commented Oct 8, 2020

It feels to me like keeping all of info is harmless and useful. I agree that blacklisting is bad, they could add "additional_creds" or some such, so we should whitelist... but thoughts on grabbing info ?

@kcbraunschweig
Copy link
Contributor Author

lmk how you like this. grabs info. moves role_name under an iam key as well. If anything additional is desired in the future, it can be added to the select.

Copy link
Contributor

@phiggins phiggins left a comment

Choose a reason for hiding this comment

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

The code seems good to me 👍

In order to merge this PR all commits will need a DCO signoff though.

Copy link
Collaborator

@jaymzh jaymzh left a comment

Choose a reason for hiding this comment

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

As @phiggins says you need to fix your DCO. Just squash them all together and forcepush, or amend your last commit and forcepush, either way.

Signed-off-by: KC Braunschweig <[email protected]>

Co-authored-by: pete higgins <[email protected]>
@jaymzh
Copy link
Collaborator

jaymzh commented Oct 9, 2020

Looks good, thanks. I'll wait for someone internal to merge, or ping me tomorrow to merge if they haven't.

@jaymzh
Copy link
Collaborator

jaymzh commented Oct 13, 2020

Hey @lamont-granquist @tas50 @phiggins ... forgot I'm an approver, not an owner, so I don't have access to merge. Can one of you click the button?

@tas50 tas50 merged commit 75d4610 into chef:master Oct 14, 2020
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