{"action":"created","comment":{"url":"https://api.github.com/repos/flynn/flynn/pulls/comments/44226672","id":44226672,"diff_hunk":"@@ -9,16 +10,92 @@ import (\n \t\"net\"\n \t\"net/http\"\n \t\"os\"\n+\t\"strings\"\n \t\"sync/atomic\"\n \t\"time\"\n \n+\t\"github.com/flynn/flynn/controller/utils\"\n \t\"github.com/flynn/flynn/discoverd/cache\"\n \t\"github.com/flynn/flynn/discoverd/client\"\n \t\"github.com/flynn/flynn/pkg/status\"\n )\n \n func main() {\n-\tlog.Fatal(http.ListenAndServe(\":\"+os.Getenv(\"PORT\"), status.Handler(GetStatus)))\n+\thandler := newStatusHandler(status.Handler(GetStatus), os.Getenv(\"AUTH_KEY\"))\n+\tlog.Fatal(http.ListenAndServe(\":\"+os.Getenv(\"PORT\"), handler))\n+}\n+\n+type statusHandler struct {\n+\th         status.Handler\n+\tk         string\n+\twhitelist []*net.IPNet\n+}\n+\n+func newStatusHandler(h status.Handler, k string) *statusHandler {\n+\tn := func(ip net.IP, n *net.IPNet, err error) *net.IPNet {\n+\t\tif err != nil {\n+\t\t\tpanic(err)\n+\t\t}\n+\t\treturn n\n+\t}\n+\twhitelist := []*net.IPNet{\n+\t\tn(net.ParseCIDR(\"10.0.0.0/8\")),      // 10.0.0.0 - 10.255.255.255\n+\t\tn(net.ParseCIDR(\"172.16.0.0/12\")),   // 172.16.0.0 - 172.31.255.255\n+\t\tn(net.ParseCIDR(\"192.168.0.0/16\")),  // 192.168.0.0 - 192.168.255.255\n+\t\tn(net.ParseCIDR(\"127.0.0.0/8\")),     // 127.0.0.0 - 127.255.255.255\n+\t\tn(net.ParseCIDR(\"fd00::/8\")),        // fdxx:xxxx:xxxx...\n+\t\tn(net.ParseCIDR(\"::1/128\")),         // ::1\n+\t\tn(net.ParseCIDR(\"192.0.2.0/24\")),    // TEST-NET (for containers)\n+\t\tn(net.ParseCIDR(\"198.51.100.0/24\")), // TEST-NET (for containers)\n+\t\tn(net.ParseCIDR(\"203.0.113.0/24\")),  // TEST-NET (for containers)\n+\t\tn(net.ParseCIDR(\"100.64.0.0/10\")),   // for containers\n+\t}\n+\treturn &statusHandler{h, k, whitelist}\n+}\n+\n+func (s *statusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {\n+\tif s.k != \"\" {\n+\t\tvar addr string\n+\t\tif fwdFor, ok := r.Header[\"X-Forwarded-For\"]; ok && len(fwdFor) == 1 {\n+\t\t\tif v := strings.Split(fwdFor[0], \", \"); len(v) > 0 {\n+\t\t\t\taddr = strings.TrimSpace(v[len(v)-1])\n+\t\t\t}\n+\t\t}\n+\t\tif addr == \"\" {\n+\t\t\tif clientIP, _, err := net.SplitHostPort(r.RemoteAddr); err == nil {\n+\t\t\t\taddr = clientIP\n+\t\t\t}\n+\t\t}\n+\n+\t\tvar authed bool\n+\t\tif addr != \"\" {\n+\t\t\tif ip := net.ParseIP(addr); ip != nil {","path":"status/status.go","position":72,"original_position":72,"commit_id":"867b9a0310ab0a430bcf9e435a49f95bb6ee4e8d","original_commit_id":"867b9a0310ab0a430bcf9e435a49f95bb6ee4e8d","user":{"login":"titanous","id":13026,"avatar_url":"https://avatars.githubusercontent.com/u/13026?v=3","gravatar_id":"","url":"https://api.github.com/users/titanous","html_url":"https://github.com/titanous","followers_url":"https://api.github.com/users/titanous/followers","following_url":"https://api.github.com/users/titanous/following{/other_user}","gists_url":"https://api.github.com/users/titanous/gists{/gist_id}","starred_url":"https://api.github.com/users/titanous/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/titanous/subscriptions","organizations_url":"https://api.github.com/users/titanous/orgs","repos_url":"https://api.github.com/users/titanous/repos","events_url":"https://api.github.com/users/titanous/events{/privacy}","received_events_url":"https://api.github.com/users/titanous/received_events","type":"User","site_admin":false},"body":"Could probably drop the `addr != \"\"` check since `ip` will be `nil` in that case.\r\n","created_at":"2015-11-08T16:21:47Z","updated_at":"2015-11-08T16:21:47Z","html_url":"https://github.com/flynn/flynn/pull/2103#discussion_r44226672","pull_request_url":"https://api.github.com/repos/flynn/flynn/pulls/2103","_links":{"self":{"href":"https://api.github.com/repos/flynn/flynn/pulls/comments/44226672"},"html":{"href":"https://github.com/flynn/flynn/pull/2103#discussion_r44226672"},"pull_request":{"href":"https://api.github.com/repos/flynn/flynn/pulls/2103"}}},"pull_request":{"url":"https://api.github.com/repos/flynn/flynn/pulls/2103","id":50047597,"html_url":"https://github.com/flynn/flynn/pull/2103","diff_url":"https://github.com/flynn/flynn/pull/2103.diff","patch_url":"https://github.com/flynn/flynn/pull/2103.patch","issue_url":"https://api.github.com/repos/flynn/flynn/issues/2103","number":2103,"state":"open","locked":false,"title":"status: Require key for status endpoint from public IP","user":{"login":"imjorge","id":3089116,"avatar_url":"https://avatars.githubusercontent.com/u/3089116?v=3","gravatar_id":"","url":"https://api.github.com/users/imjorge","html_url":"https://github.com/imjorge","followers_url":"https://api.github.com/users/imjorge/followers","following_url":"https://api.github.com/users/imjorge/following{/other_user}","gists_url":"https://api.github.com/users/imjorge/gists{/gist_id}","starred_url":"https://api.github.com/users/imjorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imjorge/subscriptions","organizations_url":"https://api.github.com/users/imjorge/orgs","repos_url":"https://api.github.com/users/imjorge/repos","events_url":"https://api.github.com/users/imjorge/events{/privacy}","received_events_url":"https://api.github.com/users/imjorge/received_events","type":"User","site_admin":false},"body":"Closes #1787","created_at":"2015-11-07T22:58:35Z","updated_at":"2015-11-08T16:21:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f917199a3fbc3257073587b126c622b78ae9f934","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/flynn/flynn/pulls/2103/commits","review_comments_url":"https://api.github.com/repos/flynn/flynn/pulls/2103/comments","review_comment_url":"https://api.github.com/repos/flynn/flynn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/flynn/flynn/issues/2103/comments","statuses_url":"https://api.github.com/repos/flynn/flynn/statuses/867b9a0310ab0a430bcf9e435a49f95bb6ee4e8d","head":{"label":"imjorge:1787-auth-on-status-endpoint","ref":"1787-auth-on-status-endpoint","sha":"867b9a0310ab0a430bcf9e435a49f95bb6ee4e8d","user":{"login":"imjorge","id":3089116,"avatar_url":"https://avatars.githubusercontent.com/u/3089116?v=3","gravatar_id":"","url":"https://api.github.com/users/imjorge","html_url":"https://github.com/imjorge","followers_url":"https://api.github.com/users/imjorge/followers","following_url":"https://api.github.com/users/imjorge/following{/other_user}","gists_url":"https://api.github.com/users/imjorge/gists{/gist_id}","starred_url":"https://api.github.com/users/imjorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imjorge/subscriptions","organizations_url":"https://api.github.com/users/imjorge/orgs","repos_url":"https://api.github.com/users/imjorge/repos","events_url":"https://api.github.com/users/imjorge/events{/privacy}","received_events_url":"https://api.github.com/users/imjorge/received_events","type":"User","site_admin":false},"repo":{"id":45690676,"name":"flynn","full_name":"imjorge/flynn","owner":{"login":"imjorge","id":3089116,"avatar_url":"https://avatars.githubusercontent.com/u/3089116?v=3","gravatar_id":"","url":"https://api.github.com/users/imjorge","html_url":"https://github.com/imjorge","followers_url":"https://api.github.com/users/imjorge/followers","following_url":"https://api.github.com/users/imjorge/following{/other_user}","gists_url":"https://api.github.com/users/imjorge/gists{/gist_id}","starred_url":"https://api.github.com/users/imjorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imjorge/subscriptions","organizations_url":"https://api.github.com/users/imjorge/orgs","repos_url":"https://api.github.com/users/imjorge/repos","events_url":"https://api.github.com/users/imjorge/events{/privacy}","received_events_url":"https://api.github.com/users/imjorge/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/imjorge/flynn","description":"A next generation open source platform as a service (PaaS)","fork":true,"url":"https://api.github.com/repos/imjorge/flynn","forks_url":"https://api.github.com/repos/imjorge/flynn/forks","keys_url":"https://api.github.com/repos/imjorge/flynn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/imjorge/flynn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/imjorge/flynn/teams","hooks_url":"https://api.github.com/repos/imjorge/flynn/hooks","issue_events_url":"https://api.github.com/repos/imjorge/flynn/issues/events{/number}","events_url":"https://api.github.com/repos/imjorge/flynn/events","assignees_url":"https://api.github.com/repos/imjorge/flynn/assignees{/user}","branches_url":"https://api.github.com/repos/imjorge/flynn/branches{/branch}","tags_url":"https://api.github.com/repos/imjorge/flynn/tags","blobs_url":"https://api.github.com/repos/imjorge/flynn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/imjorge/flynn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/imjorge/flynn/git/refs{/sha}","trees_url":"https://api.github.com/repos/imjorge/flynn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/imjorge/flynn/statuses/{sha}","languages_url":"https://api.github.com/repos/imjorge/flynn/languages","stargazers_url":"https://api.github.com/repos/imjorge/flynn/stargazers","contributors_url":"https://api.github.com/repos/imjorge/flynn/contributors","subscribers_url":"https://api.github.com/repos/imjorge/flynn/subscribers","subscription_url":"https://api.github.com/repos/imjorge/flynn/subscription","commits_url":"https://api.github.com/repos/imjorge/flynn/commits{/sha}","git_commits_url":"https://api.github.com/repos/imjorge/flynn/git/commits{/sha}","comments_url":"https://api.github.com/repos/imjorge/flynn/comments{/number}","issue_comment_url":"https://api.github.com/repos/imjorge/flynn/issues/comments{/number}","contents_url":"https://api.github.com/repos/imjorge/flynn/contents/{+path}","compare_url":"https://api.github.com/repos/imjorge/flynn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/imjorge/flynn/merges","archive_url":"https://api.github.com/repos/imjorge/flynn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/imjorge/flynn/downloads","issues_url":"https://api.github.com/repos/imjorge/flynn/issues{/number}","pulls_url":"https://api.github.com/repos/imjorge/flynn/pulls{/number}","milestones_url":"https://api.github.com/repos/imjorge/flynn/milestones{/number}","notifications_url":"https://api.github.com/repos/imjorge/flynn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/imjorge/flynn/labels{/name}","releases_url":"https://api.github.com/repos/imjorge/flynn/releases{/id}","created_at":"2015-11-06T15:41:41Z","updated_at":"2015-11-06T15:41:44Z","pushed_at":"2015-11-07T23:45:01Z","git_url":"git://github.com/imjorge/flynn.git","ssh_url":"git@github.com:imjorge/flynn.git","clone_url":"https://github.com/imjorge/flynn.git","svn_url":"https://github.com/imjorge/flynn","homepage":"https://flynn.io","size":61248,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"flynn:master","ref":"master","sha":"c7678f1f01d3075f34dd4805323a89fcd65d9013","user":{"login":"flynn","id":4973613,"avatar_url":"https://avatars.githubusercontent.com/u/4973613?v=3","gravatar_id":"","url":"https://api.github.com/users/flynn","html_url":"https://github.com/flynn","followers_url":"https://api.github.com/users/flynn/followers","following_url":"https://api.github.com/users/flynn/following{/other_user}","gists_url":"https://api.github.com/users/flynn/gists{/gist_id}","starred_url":"https://api.github.com/users/flynn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flynn/subscriptions","organizations_url":"https://api.github.com/users/flynn/orgs","repos_url":"https://api.github.com/users/flynn/repos","events_url":"https://api.github.com/users/flynn/events{/privacy}","received_events_url":"https://api.github.com/users/flynn/received_events","type":"Organization","site_admin":false},"repo":{"id":11290232,"name":"flynn","full_name":"flynn/flynn","owner":{"login":"flynn","id":4973613,"avatar_url":"https://avatars.githubusercontent.com/u/4973613?v=3","gravatar_id":"","url":"https://api.github.com/users/flynn","html_url":"https://github.com/flynn","followers_url":"https://api.github.com/users/flynn/followers","following_url":"https://api.github.com/users/flynn/following{/other_user}","gists_url":"https://api.github.com/users/flynn/gists{/gist_id}","starred_url":"https://api.github.com/users/flynn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flynn/subscriptions","organizations_url":"https://api.github.com/users/flynn/orgs","repos_url":"https://api.github.com/users/flynn/repos","events_url":"https://api.github.com/users/flynn/events{/privacy}","received_events_url":"https://api.github.com/users/flynn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flynn/flynn","description":"A next generation open source platform as a service (PaaS)","fork":false,"url":"https://api.github.com/repos/flynn/flynn","forks_url":"https://api.github.com/repos/flynn/flynn/forks","keys_url":"https://api.github.com/repos/flynn/flynn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flynn/flynn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flynn/flynn/teams","hooks_url":"https://api.github.com/repos/flynn/flynn/hooks","issue_events_url":"https://api.github.com/repos/flynn/flynn/issues/events{/number}","events_url":"https://api.github.com/repos/flynn/flynn/events","assignees_url":"https://api.github.com/repos/flynn/flynn/assignees{/user}","branches_url":"https://api.github.com/repos/flynn/flynn/branches{/branch}","tags_url":"https://api.github.com/repos/flynn/flynn/tags","blobs_url":"https://api.github.com/repos/flynn/flynn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flynn/flynn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flynn/flynn/git/refs{/sha}","trees_url":"https://api.github.com/repos/flynn/flynn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flynn/flynn/statuses/{sha}","languages_url":"https://api.github.com/repos/flynn/flynn/languages","stargazers_url":"https://api.github.com/repos/flynn/flynn/stargazers","contributors_url":"https://api.github.com/repos/flynn/flynn/contributors","subscribers_url":"https://api.github.com/repos/flynn/flynn/subscribers","subscription_url":"https://api.github.com/repos/flynn/flynn/subscription","commits_url":"https://api.github.com/repos/flynn/flynn/commits{/sha}","git_commits_url":"https://api.github.com/repos/flynn/flynn/git/commits{/sha}","comments_url":"https://api.github.com/repos/flynn/flynn/comments{/number}","issue_comment_url":"https://api.github.com/repos/flynn/flynn/issues/comments{/number}","contents_url":"https://api.github.com/repos/flynn/flynn/contents/{+path}","compare_url":"https://api.github.com/repos/flynn/flynn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flynn/flynn/merges","archive_url":"https://api.github.com/repos/flynn/flynn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flynn/flynn/downloads","issues_url":"https://api.github.com/repos/flynn/flynn/issues{/number}","pulls_url":"https://api.github.com/repos/flynn/flynn/pulls{/number}","milestones_url":"https://api.github.com/repos/flynn/flynn/milestones{/number}","notifications_url":"https://api.github.com/repos/flynn/flynn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flynn/flynn/labels{/name}","releases_url":"https://api.github.com/repos/flynn/flynn/releases{/id}","created_at":"2013-07-09T18:22:06Z","updated_at":"2015-11-07T20:01:07Z","pushed_at":"2015-11-08T16:10:54Z","git_url":"git://github.com/flynn/flynn.git","ssh_url":"git@github.com:flynn/flynn.git","clone_url":"https://github.com/flynn/flynn.git","svn_url":"https://github.com/flynn/flynn","homepage":"https://flynn.io","size":61248,"stargazers_count":4007,"watchers_count":4007,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":289,"mirror_url":null,"open_issues_count":234,"forks":289,"open_issues":234,"watchers":4007,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/flynn/flynn/pulls/2103"},"html":{"href":"https://github.com/flynn/flynn/pull/2103"},"issue":{"href":"https://api.github.com/repos/flynn/flynn/issues/2103"},"comments":{"href":"https://api.github.com/repos/flynn/flynn/issues/2103/comments"},"review_comments":{"href":"https://api.github.com/repos/flynn/flynn/pulls/2103/comments"},"review_comment":{"href":"https://api.github.com/repos/flynn/flynn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/flynn/flynn/pulls/2103/commits"},"statuses":{"href":"https://api.github.com/repos/flynn/flynn/statuses/867b9a0310ab0a430bcf9e435a49f95bb6ee4e8d"}}}}