You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2023/01/10 23:16:57 UTC

[GitHub] [trafficcontrol] kdamichie opened a new pull request, #7282: Missing user in logs bug

kdamichie opened a new pull request, #7282:
URL: https://github.com/apache/trafficcontrol/pull/7282

   <!--
   Thank you for contributing! Please be sure to read our contribution guidelines: https://github.com/apache/trafficcontrol/blob/master/CONTRIBUTING.md
   If this closes or relates to an existing issue, please reference it using one of the following:
   
   Closes: #ISSUE
   Related: #ISSUE
   
   If this PR fixes a security vulnerability, DO NOT submit! Instead, contact
   the Apache Traffic Control Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://apache.org/security regarding vulnerability disclosure.
   -->
   
   
   <!-- **^ Add meaningful description above** --><hr/>
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this PR.
   Feel free to add the name of a tool or script that is affected but not on the list.
   -->
   - Documentation
   - Traffic Control Cache Config (`t3c`, formerly ORT)
   - Traffic Control Health Client (tc-health-client)
   - Traffic Control Client <!-- Please specify which (Python, Go, or Java) -->
   - Traffic Monitor
   - Traffic Ops
   - Traffic Portal
   - Traffic Router
   - Traffic Stats
   - Grove
   - CDN in a Box
   - Automation <!-- Please specify which (GitHub Actions, Docker images, Ansible Roles, etc.) -->
   - unknown
   
   ## What is the best way to verify this PR?
   <!-- Please include here ALL the steps necessary to test your PR.
   If your PR has tests (and most should), provide the steps needed to run the tests.
   If not, please provide step-by-step instructions to test the PR manually and explain why your PR does not need tests. -->
   
   
   ## If this is a bugfix, which Traffic Control versions contained the bug?
   <!-- Delete this section if the PR is not a bugfix, or if the bug is only in the master branch.
   Examples:
   - 5.1.2
   - 5.1.3 (RC1)
    -->
   
   
   ## PR submission checklist
   - [x] This PR has tests <!-- If not, please delete this text and explain why this PR does not need tests. -->
   - [x] This PR has documentation <!-- If not, please delete this text and explain why this PR does not need documentation. -->
   - [x] This PR has a CHANGELOG.md entry <!-- A fix for a bug from an ATC release, an improvement, or a new feature should have a changelog entry. -->
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://apache.org/security) for details)
   
   <!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at
   
       http://www.apache.org/licenses/LICENSE-2.0
   
   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] codecov[bot] commented on pull request #7282: Missing user in logs bug

Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #7282:
URL: https://github.com/apache/trafficcontrol/pull/7282#issuecomment-1379013559

   # [Codecov](https://codecov.io/gh/apache/trafficcontrol/pull/7282?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#7282](https://codecov.io/gh/apache/trafficcontrol/pull/7282?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (6cf1586) into [master](https://codecov.io/gh/apache/trafficcontrol/commit/c4444af63e97be99d1f25dfb292ccffddf2f5004?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (c4444af) will **increase** coverage by `0.05%`.
   > The diff coverage is `50.00%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #7282      +/-   ##
   ============================================
   + Coverage     28.23%   28.28%   +0.05%     
     Complexity       98       98              
   ============================================
     Files           617      617              
     Lines         69576    69652      +76     
     Branches         90       90              
   ============================================
   + Hits          19642    19704      +62     
   - Misses        48120    48128       +8     
   - Partials       1814     1820       +6     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | golib_unit | `53.09% <ø> (+0.20%)` | :arrow_up: |
   | grove_unit | `4.60% <ø> (ø)` | |
   | t3c_generate_unit | `24.96% <ø> (ø)` | |
   | traffic_monitor_unit | `20.43% <ø> (-0.01%)` | :arrow_down: |
   | traffic_stats_unit | `10.41% <ø> (ø)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/trafficcontrol/pull/7282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [lib/go-rfc/http.go](https://codecov.io/gh/apache/trafficcontrol/pull/7282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGliL2dvLXJmYy9odHRwLmdv) | `34.09% <ø> (ø)` | |
   | [traffic\_ops/traffic\_ops\_golang/tocookie/cookie.go](https://codecov.io/gh/apache/trafficcontrol/pull/7282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-dHJhZmZpY19vcHMvdHJhZmZpY19vcHNfZ29sYW5nL3RvY29va2llL2Nvb2tpZS5nbw==) | `56.36% <ø> (ø)` | |
   | [.../traffic\_ops\_golang/routing/middleware/wrappers.go](https://codecov.io/gh/apache/trafficcontrol/pull/7282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-dHJhZmZpY19vcHMvdHJhZmZpY19vcHNfZ29sYW5nL3JvdXRpbmcvbWlkZGxld2FyZS93cmFwcGVycy5nbw==) | `65.80% <50.00%> (ø)` | |
   | [lib/go-atscfg/serverunknown.go](https://codecov.io/gh/apache/trafficcontrol/pull/7282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGliL2dvLWF0c2NmZy9zZXJ2ZXJ1bmtub3duLmdv) | `77.96% <0.00%> (-1.70%)` | :arrow_down: |
   | [traffic\_monitor/manager/opsconfig.go](https://codecov.io/gh/apache/trafficcontrol/pull/7282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-dHJhZmZpY19tb25pdG9yL21hbmFnZXIvb3BzY29uZmlnLmdv) | `0.00% <0.00%> (ø)` | |
   | [lib/go-atscfg/remapdotconfig.go](https://codecov.io/gh/apache/trafficcontrol/pull/7282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGliL2dvLWF0c2NmZy9yZW1hcGRvdGNvbmZpZy5nbw==) | `76.17% <0.00%> (+0.09%)` | :arrow_up: |
   | [lib/go-atscfg/headerrewritedotconfig.go](https://codecov.io/gh/apache/trafficcontrol/pull/7282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGliL2dvLWF0c2NmZy9oZWFkZXJyZXdyaXRlZG90Y29uZmlnLmdv) | `57.14% <0.00%> (+1.61%)` | :arrow_up: |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] srijeet0406 commented on a diff in pull request #7282: Missing user in logs bug

Posted by "srijeet0406 (via GitHub)" <gi...@apache.org>.
srijeet0406 commented on code in PR #7282:
URL: https://github.com/apache/trafficcontrol/pull/7282#discussion_r1088237255


##########
traffic_ops/traffic_ops_golang/routing/middleware/wrappers_test.go:
##########
@@ -26,6 +26,8 @@ import (
 	"encoding/json"
 	"flag"
 	"fmt"
+	"github.com/lestrrat-go/jwx/jwa"

Review Comment:
   This is not organized in the correct order.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] srijeet0406 commented on a diff in pull request #7282: Missing user in logs bug

Posted by "srijeet0406 (via GitHub)" <gi...@apache.org>.
srijeet0406 commented on code in PR #7282:
URL: https://github.com/apache/trafficcontrol/pull/7282#discussion_r1085606049


##########
traffic_ops/traffic_ops_golang/routing/middleware/wrappers_test.go:
##########
@@ -440,4 +440,36 @@ func TestNoOpWhenNoPermissionsRequired(t *testing.T) {
 	}
 }
 
-// TODO: TestWrapAccessLog, et. al
+func TestGetCookieToken(t *testing.T) {
+	var cookies []http.Cookie
+	var e bytes.Buffer
+
+	mojoCookie := http.Cookie{Name: "mojolicious", Value: "eyJhdXRoX2RhdGEiOiJhZG1pbiIsImV4cGlyZXMiOjE2NzQyNTY4MjEsImJ5IjoidHJhZmZpY2NvbnRyb2wtZ28tdG9jb29raWUifQ--f7f40f516bfedc888d0ac6bc3c373b21773d1765"}
+	accessToken := http.Cookie{Name: "access_token", Value: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzQyNTY4MjEsIm1vam9Db29raWUiOiJleUpoZFhSb1gyUmhkR0VpT2lKaFpHMXBiaUlzSW1WNGNHbHlaWE1pT2pFMk56UXlOVFk0TWpFc0ltSjVJam9pZEhKaFptWnBZMk52Ym5SeWIyd3RaMjh0ZEc5amIyOXJhV1VpZlEtLWY3ZjQwZjUxNmJmZWRjODg4ZDBhYzZiYzNjMzczYjIxNzczZDE3NjUifQ.41te1VWlSzHCiH77nZjdqtGQNgc-ad6HwRi5cyffTGc"}
+	bearerToken := "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzQ1MjU0OTcsIm1vam9Db29raWUiOiJleUpoZFhSb1gyUmhkR0VpT2lKaFpHMXBiaUlzSW1WNGNHbHlaWE1pT2pFMk56UTFNalUwT1Rjc0ltSjVJam9pZEhKaFptWnBZMk52Ym5SeWIyd3RaMjh0ZEc5amIyOXJhV1VpZlEtLTlmODI1Yzk5MDJhYTU5NDI1ZTQwYzJhYzcyNjhiZTI4NDMyMTg4ZjEifQ.szYraBtmKQ0UB13G6C3WUDcix1kZQyn4uqv27qy0_vY"
+	cookies = append(cookies, mojoCookie, accessToken, http.Cookie{})
+
+	r, err := http.NewRequest("GET", "https://localhost:8888", nil)
+	if err == nil && r != nil {
+		for i := range cookies {
+			if cookies[i].Name != "" {
+				r.AddCookie(&cookies[i])
+				cookie := getCookieToken(r)
+				if cookie != mojoCookie.Value && cookies[i].Name == "mojolicious" {
+					e.WriteString("Error: Unable to get mojolicious cookie. ")
+				} else if cookie != mojoCookie.Value && cookies[i].Name == "access_token" {
+					e.WriteString("Error: Unable to get mojolicious cookie from Access Token. ")
+				}
+			} else {
+				r.Header.Add("Authorization", bearerToken)
+				cookie := getCookieToken(r)
+				if cookie != mojoCookie.Value {
+					e.WriteString("Error: Unable to get cookie from Bearer Token.")
+				}
+			}
+		}
+	}
+	if e.String() != "" {

Review Comment:
   Instead of writing to an error string and then checking it at the end of the tests, you can just use `t.Errorf(...)` like the other tests do.



##########
traffic_ops/traffic_ops_golang/routing/middleware/wrappers_test.go:
##########
@@ -440,4 +440,36 @@ func TestNoOpWhenNoPermissionsRequired(t *testing.T) {
 	}
 }
 
-// TODO: TestWrapAccessLog, et. al
+func TestGetCookieToken(t *testing.T) {
+	var cookies []http.Cookie
+	var e bytes.Buffer
+
+	mojoCookie := http.Cookie{Name: "mojolicious", Value: "eyJhdXRoX2RhdGEiOiJhZG1pbiIsImV4cGlyZXMiOjE2NzQyNTY4MjEsImJ5IjoidHJhZmZpY2NvbnRyb2wtZ28tdG9jb29raWUifQ--f7f40f516bfedc888d0ac6bc3c373b21773d1765"}
+	accessToken := http.Cookie{Name: "access_token", Value: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzQyNTY4MjEsIm1vam9Db29raWUiOiJleUpoZFhSb1gyUmhkR0VpT2lKaFpHMXBiaUlzSW1WNGNHbHlaWE1pT2pFMk56UXlOVFk0TWpFc0ltSjVJam9pZEhKaFptWnBZMk52Ym5SeWIyd3RaMjh0ZEc5amIyOXJhV1VpZlEtLWY3ZjQwZjUxNmJmZWRjODg4ZDBhYzZiYzNjMzczYjIxNzczZDE3NjUifQ.41te1VWlSzHCiH77nZjdqtGQNgc-ad6HwRi5cyffTGc"}
+	bearerToken := "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzQ1MjU0OTcsIm1vam9Db29raWUiOiJleUpoZFhSb1gyUmhkR0VpT2lKaFpHMXBiaUlzSW1WNGNHbHlaWE1pT2pFMk56UTFNalUwT1Rjc0ltSjVJam9pZEhKaFptWnBZMk52Ym5SeWIyd3RaMjh0ZEc5amIyOXJhV1VpZlEtLTlmODI1Yzk5MDJhYTU5NDI1ZTQwYzJhYzcyNjhiZTI4NDMyMTg4ZjEifQ.szYraBtmKQ0UB13G6C3WUDcix1kZQyn4uqv27qy0_vY"
+	cookies = append(cookies, mojoCookie, accessToken, http.Cookie{})
+
+	r, err := http.NewRequest("GET", "https://localhost:8888", nil)
+	if err == nil && r != nil {
+		for i := range cookies {
+			if cookies[i].Name != "" {
+				r.AddCookie(&cookies[i])
+				cookie := getCookieToken(r)
+				if cookie != mojoCookie.Value && cookies[i].Name == "mojolicious" {

Review Comment:
   The aim of this PR is to make sure that the user gets properly parsed in all three auth scenarios. So, IMO, it would make more sense if you extracted the user out of the cookies in each case and made sure that you get back the expected user every time.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] kdamichie commented on a diff in pull request #7282: Missing user in logs bug

Posted by "kdamichie (via GitHub)" <gi...@apache.org>.
kdamichie commented on code in PR #7282:
URL: https://github.com/apache/trafficcontrol/pull/7282#discussion_r1088319095


##########
traffic_ops/traffic_ops_golang/routing/middleware/wrappers_test.go:
##########
@@ -26,6 +26,8 @@ import (
 	"encoding/json"
 	"flag"
 	"fmt"
+	"github.com/lestrrat-go/jwx/jwa"

Review Comment:
   Rearranging



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] srijeet0406 merged pull request #7282: Missing user in logs bug

Posted by "srijeet0406 (via GitHub)" <gi...@apache.org>.
srijeet0406 merged PR #7282:
URL: https://github.com/apache/trafficcontrol/pull/7282


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] kdamichie commented on a diff in pull request #7282: Missing user in logs bug

Posted by "kdamichie (via GitHub)" <gi...@apache.org>.
kdamichie commented on code in PR #7282:
URL: https://github.com/apache/trafficcontrol/pull/7282#discussion_r1087240337


##########
traffic_ops/traffic_ops_golang/routing/middleware/wrappers_test.go:
##########
@@ -440,4 +440,36 @@ func TestNoOpWhenNoPermissionsRequired(t *testing.T) {
 	}
 }
 
-// TODO: TestWrapAccessLog, et. al
+func TestGetCookieToken(t *testing.T) {
+	var cookies []http.Cookie
+	var e bytes.Buffer
+
+	mojoCookie := http.Cookie{Name: "mojolicious", Value: "eyJhdXRoX2RhdGEiOiJhZG1pbiIsImV4cGlyZXMiOjE2NzQyNTY4MjEsImJ5IjoidHJhZmZpY2NvbnRyb2wtZ28tdG9jb29raWUifQ--f7f40f516bfedc888d0ac6bc3c373b21773d1765"}
+	accessToken := http.Cookie{Name: "access_token", Value: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzQyNTY4MjEsIm1vam9Db29raWUiOiJleUpoZFhSb1gyUmhkR0VpT2lKaFpHMXBiaUlzSW1WNGNHbHlaWE1pT2pFMk56UXlOVFk0TWpFc0ltSjVJam9pZEhKaFptWnBZMk52Ym5SeWIyd3RaMjh0ZEc5amIyOXJhV1VpZlEtLWY3ZjQwZjUxNmJmZWRjODg4ZDBhYzZiYzNjMzczYjIxNzczZDE3NjUifQ.41te1VWlSzHCiH77nZjdqtGQNgc-ad6HwRi5cyffTGc"}
+	bearerToken := "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzQ1MjU0OTcsIm1vam9Db29raWUiOiJleUpoZFhSb1gyUmhkR0VpT2lKaFpHMXBiaUlzSW1WNGNHbHlaWE1pT2pFMk56UTFNalUwT1Rjc0ltSjVJam9pZEhKaFptWnBZMk52Ym5SeWIyd3RaMjh0ZEc5amIyOXJhV1VpZlEtLTlmODI1Yzk5MDJhYTU5NDI1ZTQwYzJhYzcyNjhiZTI4NDMyMTg4ZjEifQ.szYraBtmKQ0UB13G6C3WUDcix1kZQyn4uqv27qy0_vY"
+	cookies = append(cookies, mojoCookie, accessToken, http.Cookie{})
+
+	r, err := http.NewRequest("GET", "https://localhost:8888", nil)
+	if err == nil && r != nil {
+		for i := range cookies {
+			if cookies[i].Name != "" {
+				r.AddCookie(&cookies[i])
+				cookie := getCookieToken(r)
+				if cookie != mojoCookie.Value && cookies[i].Name == "mojolicious" {

Review Comment:
   Made those changes



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] srijeet0406 commented on a diff in pull request #7282: Missing user in logs bug

Posted by GitBox <gi...@apache.org>.
srijeet0406 commented on code in PR #7282:
URL: https://github.com/apache/trafficcontrol/pull/7282#discussion_r1068733569


##########
traffic_ops/traffic_ops_golang/routing/middleware/wrappers.go:
##########
@@ -27,6 +27,7 @@ import (
 	"encoding/base64"
 	"errors"
 	"fmt"
+	"github.com/lestrrat-go/jwx/jwt"

Review Comment:
   This is not sorted correctly.



##########
traffic_ops/traffic_ops_golang/routing/middleware/wrappers.go:
##########
@@ -188,19 +189,43 @@ func GetWrapAccessLog(secret string) Middleware {
 	}
 }
 
+func getCookieToken(r *http.Request) string {
+	cookie, err := r.Cookie(tocookie.Name)
+	if err == nil && cookie != nil {
+		return cookie.Value
+	} else if r.Header.Get(rfc.Cookie) != "" && strings.Contains(r.Header.Get(rfc.Cookie), "access_token") {

Review Comment:
   Could you make `access_token` into a constant?



##########
traffic_ops/traffic_ops_golang/routing/middleware/wrappers.go:
##########
@@ -188,19 +189,43 @@ func GetWrapAccessLog(secret string) Middleware {
 	}
 }
 
+func getCookieToken(r *http.Request) string {
+	cookie, err := r.Cookie(tocookie.Name)
+	if err == nil && cookie != nil {
+		return cookie.Value
+	} else if r.Header.Get(rfc.Cookie) != "" && strings.Contains(r.Header.Get(rfc.Cookie), "access_token") {
+		cookie, err := r.Cookie("access_token")
+		if err == nil && cookie != nil {
+			decodedToken, err := jwt.Parse([]byte(cookie.Value))
+			if err == nil && cookie != nil {
+				return fmt.Sprintf("%s", decodedToken.PrivateClaims()["mojoCookie"])
+			}
+		}
+	} else if r.Header.Get(rfc.Authorization) != "" && strings.Contains(r.Header.Get(rfc.Authorization), "Bearer") {
+		givenTokenSplit := strings.Split(r.Header.Get(rfc.Authorization), " ")

Review Comment:
   Same for `Bearer`



##########
traffic_ops/traffic_ops_golang/tocookie/cookie.go:
##########
@@ -26,6 +26,9 @@ import (
 
 const GeneratedByStr = "trafficcontrol-go-tocookie"
 const Name = "mojolicious"
+const MojoCookie = "mojoCookie"

Review Comment:
   Oh I see you already have the constants, just need to use them :) 



##########
traffic_ops/traffic_ops_golang/routing/middleware/wrappers.go:
##########
@@ -188,19 +189,43 @@ func GetWrapAccessLog(secret string) Middleware {
 	}
 }
 
+func getCookieToken(r *http.Request) string {
+	cookie, err := r.Cookie(tocookie.Name)
+	if err == nil && cookie != nil {
+		return cookie.Value
+	} else if r.Header.Get(rfc.Cookie) != "" && strings.Contains(r.Header.Get(rfc.Cookie), "access_token") {
+		cookie, err := r.Cookie("access_token")
+		if err == nil && cookie != nil {
+			decodedToken, err := jwt.Parse([]byte(cookie.Value))
+			if err == nil && cookie != nil {
+				return fmt.Sprintf("%s", decodedToken.PrivateClaims()["mojoCookie"])

Review Comment:
   Same for `mojoCookie`



##########
traffic_ops/traffic_ops_golang/routing/middleware/wrappers.go:
##########
@@ -188,19 +189,43 @@ func GetWrapAccessLog(secret string) Middleware {
 	}
 }
 
+func getCookieToken(r *http.Request) string {
+	cookie, err := r.Cookie(tocookie.Name)
+	if err == nil && cookie != nil {
+		return cookie.Value
+	} else if r.Header.Get(rfc.Cookie) != "" && strings.Contains(r.Header.Get(rfc.Cookie), "access_token") {
+		cookie, err := r.Cookie("access_token")
+		if err == nil && cookie != nil {
+			decodedToken, err := jwt.Parse([]byte(cookie.Value))
+			if err == nil && cookie != nil {
+				return fmt.Sprintf("%s", decodedToken.PrivateClaims()["mojoCookie"])
+			}
+		}
+	} else if r.Header.Get(rfc.Authorization) != "" && strings.Contains(r.Header.Get(rfc.Authorization), "Bearer") {
+		givenTokenSplit := strings.Split(r.Header.Get(rfc.Authorization), " ")
+		if len(givenTokenSplit) < 2 {
+			return ""
+		}
+		decodedToken, err := jwt.Parse([]byte(givenTokenSplit[1]))
+		if err == nil && decodedToken != nil {
+			return fmt.Sprintf("%s", decodedToken.PrivateClaims()["mojoCookie"])
+		}
+		return givenTokenSplit[1]
+	}
+	return ""
+}
+
 // WrapAccessLog takes the cookie secret and a http.Handler, and returns a HandlerFunc which writes to the Access Log (which is the lib/go-log EventLog) after the HandlerFunc finishes.
 // This is not a Middleware, because it needs the secret as a parameter. For a Middleware, see GetWrapAccessLog.
 func WrapAccessLog(secret string, h http.Handler) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
 		var imsType = NONIMS
 		iw := &util.Interceptor{W: w}
 		user := "-"
-		cookie, err := r.Cookie(tocookie.Name)
-		if err == nil && cookie != nil {
-			cookie, userErr, sysErr := tocookie.Parse(secret, cookie.Value)
-			if userErr == nil && sysErr == nil {
-				user = cookie.AuthData
-			}
+		cookieToken := getCookieToken(r)
+		cookie, userErr, sysErr := tocookie.Parse(secret, cookieToken)
+		if userErr == nil && sysErr == nil {

Review Comment:
   We should probably log the errors here, in case they are not nil



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] kdamichie commented on a diff in pull request #7282: Missing user in logs bug

Posted by GitBox <gi...@apache.org>.
kdamichie commented on code in PR #7282:
URL: https://github.com/apache/trafficcontrol/pull/7282#discussion_r1072597623


##########
traffic_ops/traffic_ops_golang/routing/middleware/wrappers.go:
##########
@@ -188,19 +189,43 @@ func GetWrapAccessLog(secret string) Middleware {
 	}
 }
 
+func getCookieToken(r *http.Request) string {
+	cookie, err := r.Cookie(tocookie.Name)
+	if err == nil && cookie != nil {
+		return cookie.Value
+	} else if r.Header.Get(rfc.Cookie) != "" && strings.Contains(r.Header.Get(rfc.Cookie), "access_token") {
+		cookie, err := r.Cookie("access_token")
+		if err == nil && cookie != nil {
+			decodedToken, err := jwt.Parse([]byte(cookie.Value))
+			if err == nil && cookie != nil {
+				return fmt.Sprintf("%s", decodedToken.PrivateClaims()["mojoCookie"])
+			}
+		}
+	} else if r.Header.Get(rfc.Authorization) != "" && strings.Contains(r.Header.Get(rfc.Authorization), "Bearer") {
+		givenTokenSplit := strings.Split(r.Header.Get(rfc.Authorization), " ")
+		if len(givenTokenSplit) < 2 {
+			return ""
+		}
+		decodedToken, err := jwt.Parse([]byte(givenTokenSplit[1]))
+		if err == nil && decodedToken != nil {
+			return fmt.Sprintf("%s", decodedToken.PrivateClaims()["mojoCookie"])
+		}
+		return givenTokenSplit[1]
+	}
+	return ""
+}
+
 // WrapAccessLog takes the cookie secret and a http.Handler, and returns a HandlerFunc which writes to the Access Log (which is the lib/go-log EventLog) after the HandlerFunc finishes.
 // This is not a Middleware, because it needs the secret as a parameter. For a Middleware, see GetWrapAccessLog.
 func WrapAccessLog(secret string, h http.Handler) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
 		var imsType = NONIMS
 		iw := &util.Interceptor{W: w}
 		user := "-"
-		cookie, err := r.Cookie(tocookie.Name)
-		if err == nil && cookie != nil {
-			cookie, userErr, sysErr := tocookie.Parse(secret, cookie.Value)
-			if userErr == nil && sysErr == nil {
-				user = cookie.AuthData
-			}
+		cookieToken := getCookieToken(r)
+		cookie, userErr, sysErr := tocookie.Parse(secret, cookieToken)
+		if userErr == nil && sysErr == nil {

Review Comment:
   Can I get your opinion on my logging?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] kdamichie commented on a diff in pull request #7282: Missing user in logs bug

Posted by "kdamichie (via GitHub)" <gi...@apache.org>.
kdamichie commented on code in PR #7282:
URL: https://github.com/apache/trafficcontrol/pull/7282#discussion_r1085936103


##########
traffic_ops/traffic_ops_golang/routing/middleware/wrappers_test.go:
##########
@@ -440,4 +440,36 @@ func TestNoOpWhenNoPermissionsRequired(t *testing.T) {
 	}
 }
 
-// TODO: TestWrapAccessLog, et. al
+func TestGetCookieToken(t *testing.T) {
+	var cookies []http.Cookie
+	var e bytes.Buffer
+
+	mojoCookie := http.Cookie{Name: "mojolicious", Value: "eyJhdXRoX2RhdGEiOiJhZG1pbiIsImV4cGlyZXMiOjE2NzQyNTY4MjEsImJ5IjoidHJhZmZpY2NvbnRyb2wtZ28tdG9jb29raWUifQ--f7f40f516bfedc888d0ac6bc3c373b21773d1765"}
+	accessToken := http.Cookie{Name: "access_token", Value: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzQyNTY4MjEsIm1vam9Db29raWUiOiJleUpoZFhSb1gyUmhkR0VpT2lKaFpHMXBiaUlzSW1WNGNHbHlaWE1pT2pFMk56UXlOVFk0TWpFc0ltSjVJam9pZEhKaFptWnBZMk52Ym5SeWIyd3RaMjh0ZEc5amIyOXJhV1VpZlEtLWY3ZjQwZjUxNmJmZWRjODg4ZDBhYzZiYzNjMzczYjIxNzczZDE3NjUifQ.41te1VWlSzHCiH77nZjdqtGQNgc-ad6HwRi5cyffTGc"}
+	bearerToken := "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzQ1MjU0OTcsIm1vam9Db29raWUiOiJleUpoZFhSb1gyUmhkR0VpT2lKaFpHMXBiaUlzSW1WNGNHbHlaWE1pT2pFMk56UTFNalUwT1Rjc0ltSjVJam9pZEhKaFptWnBZMk52Ym5SeWIyd3RaMjh0ZEc5amIyOXJhV1VpZlEtLTlmODI1Yzk5MDJhYTU5NDI1ZTQwYzJhYzcyNjhiZTI4NDMyMTg4ZjEifQ.szYraBtmKQ0UB13G6C3WUDcix1kZQyn4uqv27qy0_vY"
+	cookies = append(cookies, mojoCookie, accessToken, http.Cookie{})
+
+	r, err := http.NewRequest("GET", "https://localhost:8888", nil)
+	if err == nil && r != nil {
+		for i := range cookies {
+			if cookies[i].Name != "" {
+				r.AddCookie(&cookies[i])
+				cookie := getCookieToken(r)
+				if cookie != mojoCookie.Value && cookies[i].Name == "mojolicious" {
+					e.WriteString("Error: Unable to get mojolicious cookie. ")
+				} else if cookie != mojoCookie.Value && cookies[i].Name == "access_token" {
+					e.WriteString("Error: Unable to get mojolicious cookie from Access Token. ")
+				}
+			} else {
+				r.Header.Add("Authorization", bearerToken)
+				cookie := getCookieToken(r)
+				if cookie != mojoCookie.Value {
+					e.WriteString("Error: Unable to get cookie from Bearer Token.")
+				}
+			}
+		}
+	}
+	if e.String() != "" {

Review Comment:
   Updated to "fail fast"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org