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

fix: UI can now get clusters with slashes in name (#9812) #9813

Merged
merged 2 commits into from Nov 17, 2022

Conversation

erhudy
Copy link
Contributor

@erhudy erhudy commented Jun 28, 2022

Fixes #9812

If a cluster name has a slash in it, the API would not be able
to fetch that cluster and would display "in-cluster (undefined)"
for that application. This fixes that issue by URI-encoding
the cluster name on the UI side and URI-decoding the cluster name
on the API side.

Signed-off-by: Edmund Rhudy erhudy@users.noreply.github.com

Note on DCO:

If the DCO action in the integration test fails, one or more of your commits are not signed off. Please click on the Details link next to the DCO action for instructions on how to resolve this.

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • Optional. My organization is added to USERS.md.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).

@codecov
Copy link

codecov bot commented Jun 28, 2022

Codecov Report

Base: 45.60% // Head: 45.63% // Increases project coverage by +0.02% 🎉

Coverage data is based on head (688e58a) compared to base (e21a82f).
Patch coverage: 60.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9813      +/-   ##
==========================================
+ Coverage   45.60%   45.63%   +0.02%     
==========================================
  Files         239      239              
  Lines       28973    28978       +5     
==========================================
+ Hits        13214    13224      +10     
+ Misses      13940    13933       -7     
- Partials     1819     1821       +2     
Impacted Files Coverage Δ
server/cluster/cluster.go 39.39% <60.00%> (+3.55%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@erhudy erhudy force-pushed the fix-clusters-with-slashes branch 3 times, most recently from e22dc27 to a70a9b1 Compare June 29, 2022 14:48
@ashutosh16
Copy link
Contributor

@erhudy I tried to reproduce the issue by adding slash in the cluster name in-cluster and tested your fix in my local with URL but I'm still getting 403. However with type q.Id.Type = url, i'm getting the valid response.
Screen Shot 2022-07-26 at 9 19 14 PM

@erhudy
Copy link
Contributor Author

erhudy commented Jul 27, 2022

What was the full URL sent to the API server? My fix just urlencodes the cluster name before sending it to the API, and the API urldecodes the cluster name, so if you looked up like /api/v1/clusters/in/cluster, that won't work, but in%2fcluster would.

@ashutosh16
Copy link
Contributor

What was the full URL sent to the API server? My fix just urlencodes the cluster name before sending it to the API, and the API urldecodes the cluster name, so if you looked up like /api/v1/clusters/in/cluster, that won't work, but in%2fcluster would.

URL encode works well with cluster name API. Changes LGTM!

Copy link
Contributor

@ashutosh16 ashutosh16 left a comment

Choose a reason for hiding this comment

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

LG

Copy link
Member

@pasha-codefresh pasha-codefresh left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -144,7 +145,11 @@ func (s *Server) getCluster(ctx context.Context, q *cluster.ClusterQuery) (*appv
q.Server = ""
q.Name = ""
if q.Id.Type == "name" {
q.Name = q.Id.Value
name, err := url.QueryUnescape(q.Id.Value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would be a breaking API change for all clusters for which url.QueryUnescape(name) != name. For example, if my cluster were named (for some weird reason) in%40cluster, I'd now get a 403 when requesting that cluster unless I did so with the UI.

Could we introduce a new name_escaped to solve the bug and still support other use cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, I changed the UI to submit with type name_escaped instead and adjusted the backend side of things to handle that appropriately while still preserving the original behavior. I also duplicated the test to check that clusters where something in their name could be interpreted as escaped will pass through unmodified.

Fixes argoproj#9812

If a cluster name has a slash in it, the API would not be able
to fetch that cluster and would display "in-cluster (undefined)"
for that application. This fixes that issue by URI-encoding
the cluster name on the UI side and URI-decoding the cluster name
on the API side.

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>
Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>
@erhudy
Copy link
Contributor Author

erhudy commented Nov 14, 2022

I built another internal image with the updated PR and deployed it. Everything seems good, continues to handle cluster names properly that do and don't have / in them. @crenshaw-dev could I get your reconsideration?

Copy link
Collaborator

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

Love it. Thanks for your patience, @erhudy!

@crenshaw-dev crenshaw-dev changed the title fix: #9812 UI can now get clusters with slashes in name fix: UI can now get clusters with slashes in name (#9812) Nov 17, 2022
@crenshaw-dev crenshaw-dev added cherry-pick/2.3 Candidate for cherry picking into the 2.3 release branch cherry-pick/2.4 Candidate for cherry picking into the 2.4 release branch cherry-pick/2.5 labels Nov 17, 2022
@crenshaw-dev crenshaw-dev merged commit c1b0c7b into argoproj:master Nov 17, 2022
crenshaw-dev pushed a commit that referenced this pull request Nov 17, 2022
* fix: #9812 UI can now get clusters with slashes in name

Fixes #9812

If a cluster name has a slash in it, the API would not be able
to fetch that cluster and would display "in-cluster (undefined)"
for that application. This fixes that issue by URI-encoding
the cluster name on the UI side and URI-decoding the cluster name
on the API side.

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>

* Retrigger CI pipeline

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>
crenshaw-dev pushed a commit that referenced this pull request Nov 17, 2022
* fix: #9812 UI can now get clusters with slashes in name

Fixes #9812

If a cluster name has a slash in it, the API would not be able
to fetch that cluster and would display "in-cluster (undefined)"
for that application. This fixes that issue by URI-encoding
the cluster name on the UI side and URI-decoding the cluster name
on the API side.

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>

* Retrigger CI pipeline

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>
crenshaw-dev pushed a commit that referenced this pull request Nov 17, 2022
* fix: #9812 UI can now get clusters with slashes in name

Fixes #9812

If a cluster name has a slash in it, the API would not be able
to fetch that cluster and would display "in-cluster (undefined)"
for that application. This fixes that issue by URI-encoding
the cluster name on the UI side and URI-decoding the cluster name
on the API side.

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>

* Retrigger CI pipeline

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>
@crenshaw-dev
Copy link
Collaborator

Cherry-picked onto release-2.5 for 2.5.3, release-2.4 for 2.4.18, and release-2.3 for 2.3.12.

ashutosh16 pushed a commit to ashutosh16/argo-cd that referenced this pull request Nov 23, 2022
…goproj#9813)

* fix: argoproj#9812 UI can now get clusters with slashes in name

Fixes argoproj#9812

If a cluster name has a slash in it, the API would not be able
to fetch that cluster and would display "in-cluster (undefined)"
for that application. This fixes that issue by URI-encoding
the cluster name on the UI side and URI-decoding the cluster name
on the API side.

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>

* Retrigger CI pipeline

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>
emirot pushed a commit to emirot/argo-cd that referenced this pull request Jan 27, 2023
…goproj#9813)

* fix: argoproj#9812 UI can now get clusters with slashes in name

Fixes argoproj#9812

If a cluster name has a slash in it, the API would not be able
to fetch that cluster and would display "in-cluster (undefined)"
for that application. This fixes that issue by URI-encoding
the cluster name on the UI side and URI-decoding the cluster name
on the API side.

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>

* Retrigger CI pipeline

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>

Signed-off-by: Edmund Rhudy <erhudy@users.noreply.github.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick/2.3 Candidate for cherry picking into the 2.3 release branch cherry-pick/2.4 Candidate for cherry picking into the 2.4 release branch cherry-pick/2.5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clusters with slashes in name cannot be fetched by UI
5 participants