{"action":"created","comment":{"url":"https://api.github.com/repos/hashicorp/vault/pulls/comments/58934247","id":58934247,"diff_hunk":"@@ -0,0 +1,492 @@\n+package aws\n+\n+import (\n+\t\"crypto/x509\"\n+\t\"encoding/json\"\n+\t\"encoding/pem\"\n+\t\"fmt\"\n+\t\"time\"\n+\n+\t\"github.com/aws/aws-sdk-go/aws\"\n+\t\"github.com/aws/aws-sdk-go/service/ec2\"\n+\t\"github.com/hashicorp/vault/helper/strutil\"\n+\t\"github.com/hashicorp/vault/logical\"\n+\t\"github.com/hashicorp/vault/logical/framework\"\n+\t\"github.com/vishalnayak/pkcs7\"\n+)\n+\n+func pathLogin(b *backend) *framework.Path {\n+\treturn &framework.Path{\n+\t\tPattern: \"login$\",\n+\t\tFields: map[string]*framework.FieldSchema{\n+\t\t\t\"pkcs7\": &framework.FieldSchema{\n+\t\t\t\tType:        framework.TypeString,\n+\t\t\t\tDescription: \"PKCS7 signature of the identity document.\",\n+\t\t\t},\n+\n+\t\t\t\"nonce\": &framework.FieldSchema{\n+\t\t\t\tType:        framework.TypeString,\n+\t\t\t\tDescription: \"The nonce created by a client of this backend.\",\n+\t\t\t},\n+\t\t},\n+\n+\t\tCallbacks: map[logical.Operation]framework.OperationFunc{\n+\t\t\tlogical.UpdateOperation: b.pathLoginUpdate,\n+\t\t},\n+\n+\t\tHelpSynopsis:    pathLoginSyn,\n+\t\tHelpDescription: pathLoginDesc,\n+\t}\n+}\n+\n+// validateInstanceID queries the status of the EC2 instance using AWS EC2 API and\n+// checks if the instance is running and is healthy.\n+func validateInstanceID(s logical.Storage, instanceID string) error {\n+\t// Create an EC2 client to pull the instance information\n+\tec2Client, err := clientEC2(s)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\t// Get the status of the instance\n+\tinstanceStatus, err := ec2Client.DescribeInstanceStatus(&ec2.DescribeInstanceStatusInput{\n+\t\tInstanceIds: []*string{aws.String(instanceID)},\n+\t})\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\t// Validate the instance through InstanceState, InstanceStatus and SystemStatus\n+\treturn validateInstanceStatus(instanceStatus)\n+}\n+\n+// validateMetadata matches the given client nonce and pending time with the one cached\n+// in the identity whitelist during the previous login.\n+func validateMetadata(clientNonce, pendingTime string, storedIdentity *whitelistIdentity, imageEntry *awsImageEntry) error {\n+\n+\tgivenPendingTime, err := time.Parse(time.RFC3339, pendingTime)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tstoredPendingTime, err := time.Parse(time.RFC3339, storedIdentity.PendingTime)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\t// When the presented client nonce does not match the cached entry, it is\n+\t// either that a rogue client is trying to login or that a valid client\n+\t// suffered a migration. The migration is detected via pendingTime in the","path":"builtin/credential/aws/path_login.go","position":78,"original_position":79,"commit_id":"8ecd0518cdec64ca1e3c966300a43eba77e7a206","original_commit_id":"e612062296c9a09db8ce5a7891ba97559e0cb0a3","user":{"login":"issacg","id":2455054,"avatar_url":"https://avatars.githubusercontent.com/u/2455054?v=3","gravatar_id":"","url":"https://api.github.com/users/issacg","html_url":"https://github.com/issacg","followers_url":"https://api.github.com/users/issacg/followers","following_url":"https://api.github.com/users/issacg/following{/other_user}","gists_url":"https://api.github.com/users/issacg/gists{/gist_id}","starred_url":"https://api.github.com/users/issacg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/issacg/subscriptions","organizations_url":"https://api.github.com/users/issacg/orgs","repos_url":"https://api.github.com/users/issacg/repos","events_url":"https://api.github.com/users/issacg/events{/privacy}","received_events_url":"https://api.github.com/users/issacg/received_events","type":"User","site_admin":false},"body":"> If the attacker comes after the \"normal\" client does, and knows the nonce (because it's duplicated), they can use the combination of the instance metadata and the nonce to pose as the machine and get a new token\r\n\r\nI'm confused.  If the attacker comes with the nonce *after* the \"safe\" code, then wouldn't it not re-issue because the pendingTime in the identity doc matches storedPendingTime?","created_at":"2016-04-07T19:55:13Z","updated_at":"2016-04-07T19:55:13Z","html_url":"https://github.com/hashicorp/vault/pull/1300#discussion_r58934247","pull_request_url":"https://api.github.com/repos/hashicorp/vault/pulls/1300","_links":{"self":{"href":"https://api.github.com/repos/hashicorp/vault/pulls/comments/58934247"},"html":{"href":"https://github.com/hashicorp/vault/pull/1300#discussion_r58934247"},"pull_request":{"href":"https://api.github.com/repos/hashicorp/vault/pulls/1300"}}},"pull_request":{"url":"https://api.github.com/repos/hashicorp/vault/pulls/1300","id":65394703,"html_url":"https://github.com/hashicorp/vault/pull/1300","diff_url":"https://github.com/hashicorp/vault/pull/1300.diff","patch_url":"https://github.com/hashicorp/vault/pull/1300.patch","issue_url":"https://api.github.com/repos/hashicorp/vault/issues/1300","number":1300,"state":"open","locked":false,"title":"AWS EC2 instances authentication backend","user":{"login":"vishalnayak","id":3053672,"avatar_url":"https://avatars.githubusercontent.com/u/3053672?v=3","gravatar_id":"","url":"https://api.github.com/users/vishalnayak","html_url":"https://github.com/vishalnayak","followers_url":"https://api.github.com/users/vishalnayak/followers","following_url":"https://api.github.com/users/vishalnayak/following{/other_user}","gists_url":"https://api.github.com/users/vishalnayak/gists{/gist_id}","starred_url":"https://api.github.com/users/vishalnayak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vishalnayak/subscriptions","organizations_url":"https://api.github.com/users/vishalnayak/orgs","repos_url":"https://api.github.com/users/vishalnayak/repos","events_url":"https://api.github.com/users/vishalnayak/events{/privacy}","received_events_url":"https://api.github.com/users/vishalnayak/received_events","type":"User","site_admin":false},"body":"Pending testing and documentation.\r\nDo not merge.\r\n\r\nThis supersedes #805, #828, and #948 in that this is the backend that we will be officially supporting and enhancing going forward.","created_at":"2016-04-06T00:44:33Z","updated_at":"2016-04-07T19:55:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"23b6aa109334254540eda2fee8494673f1c9bcfe","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hashicorp/vault/pulls/1300/commits","review_comments_url":"https://api.github.com/repos/hashicorp/vault/pulls/1300/comments","review_comment_url":"https://api.github.com/repos/hashicorp/vault/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hashicorp/vault/issues/1300/comments","statuses_url":"https://api.github.com/repos/hashicorp/vault/statuses/8ecd0518cdec64ca1e3c966300a43eba77e7a206","head":{"label":"hashicorp:aws-auth-backend","ref":"aws-auth-backend","sha":"8ecd0518cdec64ca1e3c966300a43eba77e7a206","user":{"login":"hashicorp","id":761456,"avatar_url":"https://avatars.githubusercontent.com/u/761456?v=3","gravatar_id":"","url":"https://api.github.com/users/hashicorp","html_url":"https://github.com/hashicorp","followers_url":"https://api.github.com/users/hashicorp/followers","following_url":"https://api.github.com/users/hashicorp/following{/other_user}","gists_url":"https://api.github.com/users/hashicorp/gists{/gist_id}","starred_url":"https://api.github.com/users/hashicorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hashicorp/subscriptions","organizations_url":"https://api.github.com/users/hashicorp/orgs","repos_url":"https://api.github.com/users/hashicorp/repos","events_url":"https://api.github.com/users/hashicorp/events{/privacy}","received_events_url":"https://api.github.com/users/hashicorp/received_events","type":"Organization","site_admin":false},"repo":{"id":31288958,"name":"vault","full_name":"hashicorp/vault","owner":{"login":"hashicorp","id":761456,"avatar_url":"https://avatars.githubusercontent.com/u/761456?v=3","gravatar_id":"","url":"https://api.github.com/users/hashicorp","html_url":"https://github.com/hashicorp","followers_url":"https://api.github.com/users/hashicorp/followers","following_url":"https://api.github.com/users/hashicorp/following{/other_user}","gists_url":"https://api.github.com/users/hashicorp/gists{/gist_id}","starred_url":"https://api.github.com/users/hashicorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hashicorp/subscriptions","organizations_url":"https://api.github.com/users/hashicorp/orgs","repos_url":"https://api.github.com/users/hashicorp/repos","events_url":"https://api.github.com/users/hashicorp/events{/privacy}","received_events_url":"https://api.github.com/users/hashicorp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hashicorp/vault","description":"A tool for managing secrets.","fork":false,"url":"https://api.github.com/repos/hashicorp/vault","forks_url":"https://api.github.com/repos/hashicorp/vault/forks","keys_url":"https://api.github.com/repos/hashicorp/vault/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hashicorp/vault/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hashicorp/vault/teams","hooks_url":"https://api.github.com/repos/hashicorp/vault/hooks","issue_events_url":"https://api.github.com/repos/hashicorp/vault/issues/events{/number}","events_url":"https://api.github.com/repos/hashicorp/vault/events","assignees_url":"https://api.github.com/repos/hashicorp/vault/assignees{/user}","branches_url":"https://api.github.com/repos/hashicorp/vault/branches{/branch}","tags_url":"https://api.github.com/repos/hashicorp/vault/tags","blobs_url":"https://api.github.com/repos/hashicorp/vault/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hashicorp/vault/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hashicorp/vault/git/refs{/sha}","trees_url":"https://api.github.com/repos/hashicorp/vault/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hashicorp/vault/statuses/{sha}","languages_url":"https://api.github.com/repos/hashicorp/vault/languages","stargazers_url":"https://api.github.com/repos/hashicorp/vault/stargazers","contributors_url":"https://api.github.com/repos/hashicorp/vault/contributors","subscribers_url":"https://api.github.com/repos/hashicorp/vault/subscribers","subscription_url":"https://api.github.com/repos/hashicorp/vault/subscription","commits_url":"https://api.github.com/repos/hashicorp/vault/commits{/sha}","git_commits_url":"https://api.github.com/repos/hashicorp/vault/git/commits{/sha}","comments_url":"https://api.github.com/repos/hashicorp/vault/comments{/number}","issue_comment_url":"https://api.github.com/repos/hashicorp/vault/issues/comments{/number}","contents_url":"https://api.github.com/repos/hashicorp/vault/contents/{+path}","compare_url":"https://api.github.com/repos/hashicorp/vault/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hashicorp/vault/merges","archive_url":"https://api.github.com/repos/hashicorp/vault/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hashicorp/vault/downloads","issues_url":"https://api.github.com/repos/hashicorp/vault/issues{/number}","pulls_url":"https://api.github.com/repos/hashicorp/vault/pulls{/number}","milestones_url":"https://api.github.com/repos/hashicorp/vault/milestones{/number}","notifications_url":"https://api.github.com/repos/hashicorp/vault/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hashicorp/vault/labels{/name}","releases_url":"https://api.github.com/repos/hashicorp/vault/releases{/id}","deployments_url":"https://api.github.com/repos/hashicorp/vault/deployments","created_at":"2015-02-25T00:15:59Z","updated_at":"2016-04-07T19:54:23Z","pushed_at":"2016-04-07T18:30:56Z","git_url":"git://github.com/hashicorp/vault.git","ssh_url":"git@github.com:hashicorp/vault.git","clone_url":"https://github.com/hashicorp/vault.git","svn_url":"https://github.com/hashicorp/vault","homepage":"https://www.vaultproject.io/","size":14408,"stargazers_count":4369,"watchers_count":4369,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":392,"mirror_url":null,"open_issues_count":158,"forks":392,"open_issues":158,"watchers":4369,"default_branch":"master"}},"base":{"label":"hashicorp:master","ref":"master","sha":"70c137f1d9cb84311f4af696cc059144d1926e7b","user":{"login":"hashicorp","id":761456,"avatar_url":"https://avatars.githubusercontent.com/u/761456?v=3","gravatar_id":"","url":"https://api.github.com/users/hashicorp","html_url":"https://github.com/hashicorp","followers_url":"https://api.github.com/users/hashicorp/followers","following_url":"https://api.github.com/users/hashicorp/following{/other_user}","gists_url":"https://api.github.com/users/hashicorp/gists{/gist_id}","starred_url":"https://api.github.com/users/hashicorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hashicorp/subscriptions","organizations_url":"https://api.github.com/users/hashicorp/orgs","repos_url":"https://api.github.com/users/hashicorp/repos","events_url":"https://api.github.com/users/hashicorp/events{/privacy}","received_events_url":"https://api.github.com/users/hashicorp/received_events","type":"Organization","site_admin":false},"repo":{"id":31288958,"name":"vault","full_name":"hashicorp/vault","owner":{"login":"hashicorp","id":761456,"avatar_url":"https://avatars.githubusercontent.com/u/761456?v=3","gravatar_id":"","url":"https://api.github.com/users/hashicorp","html_url":"https://github.com/hashicorp","followers_url":"https://api.github.com/users/hashicorp/followers","following_url":"https://api.github.com/users/hashicorp/following{/other_user}","gists_url":"https://api.github.com/users/hashicorp/gists{/gist_id}","starred_url":"https://api.github.com/users/hashicorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hashicorp/subscriptions","organizations_url":"https://api.github.com/users/hashicorp/orgs","repos_url":"https://api.github.com/users/hashicorp/repos","events_url":"https://api.github.com/users/hashicorp/events{/privacy}","received_events_url":"https://api.github.com/users/hashicorp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hashicorp/vault","description":"A tool for managing secrets.","fork":false,"url":"https://api.github.com/repos/hashicorp/vault","forks_url":"https://api.github.com/repos/hashicorp/vault/forks","keys_url":"https://api.github.com/repos/hashicorp/vault/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hashicorp/vault/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hashicorp/vault/teams","hooks_url":"https://api.github.com/repos/hashicorp/vault/hooks","issue_events_url":"https://api.github.com/repos/hashicorp/vault/issues/events{/number}","events_url":"https://api.github.com/repos/hashicorp/vault/events","assignees_url":"https://api.github.com/repos/hashicorp/vault/assignees{/user}","branches_url":"https://api.github.com/repos/hashicorp/vault/branches{/branch}","tags_url":"https://api.github.com/repos/hashicorp/vault/tags","blobs_url":"https://api.github.com/repos/hashicorp/vault/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hashicorp/vault/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hashicorp/vault/git/refs{/sha}","trees_url":"https://api.github.com/repos/hashicorp/vault/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hashicorp/vault/statuses/{sha}","languages_url":"https://api.github.com/repos/hashicorp/vault/languages","stargazers_url":"https://api.github.com/repos/hashicorp/vault/stargazers","contributors_url":"https://api.github.com/repos/hashicorp/vault/contributors","subscribers_url":"https://api.github.com/repos/hashicorp/vault/subscribers","subscription_url":"https://api.github.com/repos/hashicorp/vault/subscription","commits_url":"https://api.github.com/repos/hashicorp/vault/commits{/sha}","git_commits_url":"https://api.github.com/repos/hashicorp/vault/git/commits{/sha}","comments_url":"https://api.github.com/repos/hashicorp/vault/comments{/number}","issue_comment_url":"https://api.github.com/repos/hashicorp/vault/issues/comments{/number}","contents_url":"https://api.github.com/repos/hashicorp/vault/contents/{+path}","compare_url":"https://api.github.com/repos/hashicorp/vault/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hashicorp/vault/merges","archive_url":"https://api.github.com/repos/hashicorp/vault/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hashicorp/vault/downloads","issues_url":"https://api.github.com/repos/hashicorp/vault/issues{/number}","pulls_url":"https://api.github.com/repos/hashicorp/vault/pulls{/number}","milestones_url":"https://api.github.com/repos/hashicorp/vault/milestones{/number}","notifications_url":"https://api.github.com/repos/hashicorp/vault/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hashicorp/vault/labels{/name}","releases_url":"https://api.github.com/repos/hashicorp/vault/releases{/id}","deployments_url":"https://api.github.com/repos/hashicorp/vault/deployments","created_at":"2015-02-25T00:15:59Z","updated_at":"2016-04-07T19:54:23Z","pushed_at":"2016-04-07T18:30:56Z","git_url":"git://github.com/hashicorp/vault.git","ssh_url":"git@github.com:hashicorp/vault.git","clone_url":"https://github.com/hashicorp/vault.git","svn_url":"https://github.com/hashicorp/vault","homepage":"https://www.vaultproject.io/","size":14408,"stargazers_count":4369,"watchers_count":4369,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":392,"mirror_url":null,"open_issues_count":158,"forks":392,"open_issues":158,"watchers":4369,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hashicorp/vault/pulls/1300"},"html":{"href":"https://github.com/hashicorp/vault/pull/1300"},"issue":{"href":"https://api.github.com/repos/hashicorp/vault/issues/1300"},"comments":{"href":"https://api.github.com/repos/hashicorp/vault/issues/1300/comments"},"review_comments":{"href":"https://api.github.com/repos/hashicorp/vault/pulls/1300/comments"},"review_comment":{"href":"https://api.github.com/repos/hashicorp/vault/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hashicorp/vault/pulls/1300/commits"},"statuses":{"href":"https://api.github.com/repos/hashicorp/vault/statuses/8ecd0518cdec64ca1e3c966300a43eba77e7a206"}}}}