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

Bug 1878953: Fix RBAC with upload form and golden images #7685

Merged
merged 1 commit into from Jan 6, 2021

Conversation

glekner
Copy link
Contributor

@glekner glekner commented Dec 31, 2020

No description provided.

@openshift-ci-robot openshift-ci-robot added bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. labels Dec 31, 2020
@openshift-ci-robot
Copy link
Contributor

@glekner: This pull request references Bugzilla bug 1878953, which is invalid:

  • expected the bug to target the "4.7.0" release, but it targets "---" instead

Comment /bugzilla refresh to re-evaluate validity if changes to the Bugzilla bug are made, or edit the title of this pull request to link to a different bug.

In response to this:

Bug 1878953: Fix RBAC with upload form and golden images

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added component/core Related to console core functionality component/kubevirt Related to kubevirt-plugin labels Dec 31, 2020
@glekner
Copy link
Contributor Author

glekner commented Dec 31, 2020

/bugzilla refresh

@openshift-ci-robot openshift-ci-robot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Dec 31, 2020
@openshift-ci-robot
Copy link
Contributor

@glekner: This pull request references Bugzilla bug 1878953, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.7.0) matches configured target release for branch (4.7.0)
  • bug is in the state NEW, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

/bugzilla refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot removed the bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. label Dec 31, 2020
@glekner glekner force-pushed the fix-1878953 branch 3 times, most recently from c6d9533 to 4e0753b Compare January 5, 2021 11:50
Comment on lines 547 to 564
const goldenNamespaces = React.useMemo(() => {
return [
...new Set(
(commonTemplates || [])
.map((template) => getParameterValue(template, TEMPLATE_BASE_IMAGE_NAMESPACE_PARAMETER))
.filter((ns) => !!ns),
),
];
}, [commonTemplates]);

const goldenNamespacesResources = React.useMemo(() => {
return goldenNamespaces.map((ns) => ({
group: DataVolumeModel.apiGroup,
resource: DataVolumeModel.plural,
verb: 'create' as K8sVerb,
namespace: ns,
}));
}, [goldenNamespaces]);
Copy link
Contributor

Choose a reason for hiding this comment

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

can be done in one useMemo

export const useMultipleAccessReviews = (
multipleResourceAttributes: AccessReviewResourceAttributes[],
impersonate?,
): [{ resourceAttributes: AccessReviewResourceAttributes; allowed: boolean }[], boolean] => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would extract this { resourceAttributes: AccessReviewResourceAttributes; allowed: boolean } as separate type as it can be reused later - ie type AccessReviewsResult = { resourceAttributes: AccessReviewResourceAttributes; allowed: boolean }; but feel free to pick a better name.

impersonate?,
): [{ resourceAttributes: AccessReviewResourceAttributes; allowed: boolean }[], boolean] => {
const [loading, setLoading] = React.useState(true);
const [allowedArr, setAllowedArr] = React.useState([]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const [allowedArr, setAllowedArr] = React.useState([]);
const [allowedArr, setAllowedArr] = React.useState<AccessReviewsResult[]>([]);

Comment on lines 135 to 154
const promises = multipleResourceAttributes.map((resourceAttributes) => {
const {
group = '',
resource = '',
subresource = '',
verb = '' as K8sVerb,
name = '',
namespace = '',
} = resourceAttributes;
const impersonateKey = getImpersonateKey(impersonate);
return checkAccessInternal(
group,
resource,
subresource,
verb,
name,
namespace,
impersonateKey,
);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

you can reuse checkAccess

Suggested change
const promises = multipleResourceAttributes.map((resourceAttributes) => {
const {
group = '',
resource = '',
subresource = '',
verb = '' as K8sVerb,
name = '',
namespace = '',
} = resourceAttributes;
const impersonateKey = getImpersonateKey(impersonate);
return checkAccessInternal(
group,
resource,
subresource,
verb,
name,
namespace,
impersonateKey,
);
});
const promises = multipleResourceAttributes.map((resourceAttributes) =>
checkAccess(resourceAttributes, impersonate),
);

Promise.all(promises)
.then((values) => {
setLoading(false);
const updatedAllowedArr = (values || []).map((result: SelfSubjectAccessReviewKind) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think you need [] fallback. You also dont need to specify result: SelfSubjectAccessReviewKind as that is correctly infered from promises.

I would also prefer to specify generic for map as AccessReviewsResult

Suggested change
const updatedAllowedArr = (values || []).map((result: SelfSubjectAccessReviewKind) => ({
const updatedAllowedArr = (values).map<AccessReviewsResult>((result) => ({

setLoading(false);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [multipleResourceAttributes]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should not ignore impersonate as dependency. (and delete // eslint-disable-next-line react-hooks/exhaustive-deps above it)

@@ -124,6 +124,55 @@ export const useAccessReview2 = (
return [isAllowed, loading];
};

export const useMultipleAccessReviews = (
multipleResourceAttributes: AccessReviewResourceAttributes[],
impersonate?,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
impersonate?,
impersonate?: boolean,

@rawagner
Copy link
Contributor

rawagner commented Jan 5, 2021

/lgtm

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: glekner, rawagner

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 5, 2021
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

7 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 6, 2021

@glekner: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/kubevirt-plugin 63d8fa9 link /test kubevirt-plugin

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 55cf4fa into openshift:master Jan 6, 2021
@openshift-ci-robot
Copy link
Contributor

@glekner: All pull requests linked via external trackers have merged:

Bugzilla bug 1878953 has been moved to the MODIFIED state.

In response to this:

Bug 1878953: Fix RBAC with upload form and golden images

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@spadgett spadgett added this to the v4.7 milestone Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. component/core Related to console core functionality component/kubevirt Related to kubevirt-plugin lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants