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 2022/02/09 23:12:16 UTC

[GitHub] [trafficcontrol] ericholguin opened a new pull request #6552: Validate type in topology using current cache group name

ericholguin opened a new pull request #6552:
URL: https://github.com/apache/trafficcontrol/pull/6552


   <!--
   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.
   -->
   Closes: #6551 
   
   Validates that cache group type is not being changed if it is used in a topology, using previous object name, instead of the requested name.
   
   <!-- **^ 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.
   -->
   
   - Traffic Ops
   
   
   ## 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. -->
   
   Try updating the type of a cache group which belongs to a topology, should fail
   Try updating the type and name of a cache group which belongs to a topology, should fail
   
   ## 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)
    -->
   
   - 5.1.x
   - 6.0.x
   - 6.1.x
   
   
   ## PR submission checklist
   - [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] ericholguin edited a comment on pull request #6552: Validate type in topology using current cache group name

Posted by GitBox <gi...@apache.org>.
ericholguin edited a comment on pull request #6552:
URL: https://github.com/apache/trafficcontrol/pull/6552#issuecomment-1034361900


   This change will only fix the issue for Traffic Portal. The code performs a check against the requested body, so if in the request body there is a change to the name, the validation will perform a query against that new name and will not find that newly named cache group in any topology, hence allowing it to update and succeed. Changing the code to use the previous or current name, fixes this, as it will find the topology relationship.
   
   However, in Traffic Ops, the type can be changed regardless of the name or any other field changes, if there is no id field in the request body. This is because the validation uses the cache group id in the query to get previous type and now this newly added query for previous name. The way validation is structured, is that it will only use the requested body, and in the case of this endpoint id is in the url path. If the user omits the id, the validation will be querying using an empty id value resulting in no real validation being made.
   
   ~~Not sure what the fix is, without changing the Validate functionality. Or unless id is required in the request body when updating a cache group.~~
   
   Fix is calling the ValidateTypeInTopology() inside of (TOCacheGroup) Update where the Cache Group id has already been set by the Update Handler


-- 
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] zrhoffman merged pull request #6552: Validate type in topology using current cache group name

Posted by GitBox <gi...@apache.org>.
zrhoffman merged pull request #6552:
URL: https://github.com/apache/trafficcontrol/pull/6552


   


-- 
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] zrhoffman commented on a change in pull request #6552: Validate type in topology using current cache group name

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #6552:
URL: https://github.com/apache/trafficcontrol/pull/6552#discussion_r805059964



##########
File path: traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
##########
@@ -188,14 +188,30 @@ func (cg *TOCacheGroup) ValidateTypeInTopology() error {
 		return nil
 	}
 
+	// language=SQL
+	const previousNameQuery = `
+	SELECT name
+	FROM cachegroup c
+	WHERE c.id = $1
+	`
+	var previousName string
+	err = cg.ReqInfo.Tx.QueryRow(previousNameQuery, *cg.ID).Scan(&previousName)
+	if err == sql.ErrNoRows {
+		return nil
+	}
+	if err != nil {
+		log.Errorf("%s: getting the previous name of cachegroup %s: %s", userErr.Error(), *cg.Name, err.Error())

Review comment:
       oh, true




-- 
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] ericholguin commented on pull request #6552: Validate type in topology using current cache group name

Posted by GitBox <gi...@apache.org>.
ericholguin commented on pull request #6552:
URL: https://github.com/apache/trafficcontrol/pull/6552#issuecomment-1034361900


   This change will only fix the issue for Traffic Portal. The code performs a check against the requested body, so if in the request body there is a change to the name, the validation will perform a query against that new name and will not find that newly named cache group in any topology, hence allowing it to update and succeed. Changing the code to use the previous or current name, fixes this, as it will find the topology relationship.
   
   However, in Traffic Ops, the type can be changed regardless of the name or any other field changes, if there is no id field in the request body. This is because the validation uses the cache group id in the query to get previous type and now this newly added query for previous name. The way validation is structured, is that it will only use the requested body, and in the case of this endpoint id is in the url path. If the user omits the id, the validation will be querying using an empty id value resulting in no real validation being made.
   
   Not sure what the fix is, without changing the Validate functionality. Or unless id is required in the request body when updating a cache group.


-- 
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] zrhoffman commented on pull request #6552: Validate type in topology using current cache group name

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on pull request #6552:
URL: https://github.com/apache/trafficcontrol/pull/6552#issuecomment-1036748162


   > I'm not sure if adding that requirement would be a breaking change to the API versions or other implications since the Update Handler simply uses the url path to set the id key in the object
   
   Good point, it would be.


-- 
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] ericholguin commented on a change in pull request #6552: Validate type in topology using current cache group name

Posted by GitBox <gi...@apache.org>.
ericholguin commented on a change in pull request #6552:
URL: https://github.com/apache/trafficcontrol/pull/6552#discussion_r805057755



##########
File path: traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
##########
@@ -188,14 +188,30 @@ func (cg *TOCacheGroup) ValidateTypeInTopology() error {
 		return nil
 	}
 
+	// language=SQL
+	const previousNameQuery = `
+	SELECT name
+	FROM cachegroup c
+	WHERE c.id = $1
+	`
+	var previousName string
+	err = cg.ReqInfo.Tx.QueryRow(previousNameQuery, *cg.ID).Scan(&previousName)
+	if err == sql.ErrNoRows {
+		return nil
+	}
+	if err != nil {
+		log.Errorf("%s: getting the previous name of cachegroup %s: %s", userErr.Error(), *cg.Name, err.Error())

Review comment:
       Doesn't this line prevent that?
   https://github.com/apache/trafficcontrol/blob/c0b747c18799952a4db7566c5a0f5dd9a5989c95/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go#L164
   




-- 
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] zrhoffman commented on a change in pull request #6552: Validate type in topology using current cache group name

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #6552:
URL: https://github.com/apache/trafficcontrol/pull/6552#discussion_r805055372



##########
File path: traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
##########
@@ -188,14 +188,30 @@ func (cg *TOCacheGroup) ValidateTypeInTopology() error {
 		return nil
 	}
 
+	// language=SQL
+	const previousNameQuery = `
+	SELECT name
+	FROM cachegroup c
+	WHERE c.id = $1
+	`
+	var previousName string
+	err = cg.ReqInfo.Tx.QueryRow(previousNameQuery, *cg.ID).Scan(&previousName)
+	if err == sql.ErrNoRows {
+		return nil
+	}
+	if err != nil {
+		log.Errorf("%s: getting the previous name of cachegroup %s: %s", userErr.Error(), *cg.Name, err.Error())

Review comment:
       This line panics  if `userErr` is nil. Changing `userErr.Error()` to `userErr` would fix that




-- 
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] ericholguin commented on pull request #6552: Validate type in topology using current cache group name

Posted by GitBox <gi...@apache.org>.
ericholguin commented on pull request #6552:
URL: https://github.com/apache/trafficcontrol/pull/6552#issuecomment-1036742536


   > Sounds like `id` should be required in PUT requests
   
   Calling `ValidateTypeInTopology()` in  `(TOCacheGroup) Update` fixes this issue without the need to add an additional requirement to the PUT /cachegroups/{id} endpoint, I'm not sure if adding that requirement would be a breaking change to the API versions or other implications since the Update Handler simply uses the url path to set the id key in the object


-- 
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