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: Fix repeated 403 due to app namespace being undefined (#20699) #20819

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andrii-korotkov-verkada
Copy link
Contributor

@andrii-korotkov-verkada andrii-korotkov-verkada commented Nov 18, 2024

Fixes #20699

Constructor may not get called every time the application changes, so previous this.appNamespace could be stale. But the update to use this.props.match.params.appnamespace could also fail if it's undefined. As a fix, create and use a helper function getAppNamespace which has a special case handling for undefined.

Also, use a namespaced endpoint when namespace is not undefined.

It needs to be cherry-picked to v2.11-2.13.

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).
  • The title of the PR conforms to the Toolchain Guide
  • 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.
  • 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).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

Copy link

bunnyshell bot commented Nov 18, 2024

✅ Preview Environment deployed on Bunnyshell

Component Endpoints
argocd https://argocd-m3vpi2.bunnyenv.com/
argocd-ttyd https://argocd-web-cli-m3vpi2.bunnyenv.com/

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔴 /bns:stop to stop the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@andrii-korotkov-verkada andrii-korotkov-verkada force-pushed the 20699-fix-repeated-403-due-to-app-namespace-undefined branch from 7f93899 to 99c2819 Compare November 18, 2024 05:20
@andrii-korotkov-verkada andrii-korotkov-verkada force-pushed the 20699-fix-repeated-403-due-to-app-namespace-undefined branch 3 times, most recently from 163d59e to d9d7110 Compare November 18, 2024 15:51
…20699)

Fixes argoproj#20699

Constructor may not get called every time the application changes, so previous this.appNamespace could be stale. But the update to use `this.props.match.params.appnamespace` could also fail if it's undefined.
As a fix, create and use a helper function `getAppNamespace` which has a special case handling for undefined.

Also, use a namespaced endpoint when namespace is not undefined.

It needs to be cherry-picked to v2.11-2.13.

Signed-off-by: Andrii Korotkov <andrii.korotkov@verkada.com>
@andrii-korotkov-verkada andrii-korotkov-verkada force-pushed the 20699-fix-repeated-403-due-to-app-namespace-undefined branch from d9d7110 to 2c04134 Compare November 18, 2024 16:02
@andrii-korotkov-verkada
Copy link
Contributor Author

✅ Preview Environment deployed on Bunnyshell

Component Endpoints
argocd https://argocd-m3vpi2.bunnyenv.com/
argocd-ttyd https://argocd-web-cli-m3vpi2.bunnyenv.com/

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

* 🔴 `/bns:stop` to stop the environment

* 🚀 `/bns:deploy` to redeploy the environment

* ❌ `/bns:delete` to remove the environment

/bns:deploy

@crenshaw-dev
Copy link
Member

✅ Preview Environment deployed on Bunnyshell

Component Endpoints
argocd https://argocd-m3vpi2.bunnyenv.com/
argocd-ttyd https://argocd-web-cli-m3vpi2.bunnyenv.com/
See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔴 /bns:stop to stop the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

/bns:deploy

@andrii-korotkov-verkada
Copy link
Contributor Author

I've checked Bunnyshell and didn't get any 403 while inspecting network stuff. The resource tree endpoint returns 200.

@pasha-codefresh
Copy link
Member

Asked UI team to help with review. Thanks Andrii for fixing it, once we cherry-pick it , i will create release

@andrii-korotkov-verkada
Copy link
Contributor Author

@pasha-codefresh, let's also include argoproj/gitops-engine#640 and follow-up PR to use it. That's another nasty bug that should be fixed in 2.13.1

onClick={e =>
ctx.navigation.goto(
typeof app.metadata.namespace !== 'undefined'
? `/applications/${app.metadata.namespace}/${app.metadata.name}`
Copy link
Contributor

@oleksandr-codefresh oleksandr-codefresh Nov 19, 2024

Choose a reason for hiding this comment

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

I see these links in two places, so it's better to move this logic into dedicated function

let targetUrl;
// Use not namespaced endpoint if namespace is undefined
if (typeof applications[selectedApp].metadata.namespace !== 'undefined') {
targetUrl = `/applications/${applications[selectedApp].metadata.namespace}/${applications[selectedApp].metadata.name}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

re-use dedicated function for that

ctx.navigation.goto(`applications/${app.metadata.namespace}/${app.metadata.name}`, {view: pref.appDetails.view}, {event: e})
ctx.navigation.goto(
typeof app.metadata.namespace !== 'undefined'
? `/applications/${app.metadata.namespace}/${app.metadata.name}`
Copy link
Contributor

Choose a reason for hiding this comment

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

re-use dedicated function for that

onClick={() =>
ctx.navigation.goto(
// Use not namespaced endpoint if namespace is undefined
typeof app.metadata.namespace !== 'undefined'
Copy link
Contributor

Choose a reason for hiding this comment

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

use isUndefined from lodash

private getAppNamespace() {
if (typeof this.props.match.params.appnamespace === 'undefined') {
return '';
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to wrap it it else {}
just return

@@ -116,6 +110,14 @@ export class ApplicationDetails extends React.Component<RouteComponentProps<{app
services.extensions.removeEventListener('topBar', this.onExtensionsUpdate);
}

private getAppNamespace() {
if (typeof this.props.match.params.appnamespace === 'undefined') {
Copy link
Contributor

@oleksandr-codefresh oleksandr-codefresh Nov 19, 2024

Choose a reason for hiding this comment

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

use isUndefined from lodash in all places

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for final review
Development

Successfully merging this pull request may close these issues.

appNamespace=undefined
4 participants