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 the custom injection on OpenShift #47898

Merged
merged 1 commit into from
Nov 17, 2023

Conversation

jwendell
Copy link
Member

Use of custom injection (i.e., providing a custom istio-proxy container) is broken on OpenShift.

This is because OpenShift sets the RunAs field to be the a pseudo-random value that varies by namespace. We rely on the RunAs field to be a well-known value, and it's calculated upon injection. We should stick with that value. iptables rules were created based on that value.

Even if the user provides another value (i.e., it's not set by OpenShift, but b the user), that's wrong. We should ignore what's in the original pod and use the calculated one, for these two fields only.

@jwendell jwendell requested a review from a team as a code owner November 17, 2023 03:31
@istio-testing istio-testing added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 17, 2023
@@ -49,6 +49,9 @@ spec:
securityContext:
allowPrivilegeEscalation: true
readOnlyRootFilesystem: false
# These should not be removed or ignored, should be honored
runAsUser: 1234
runAsGroup: 1234
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why should we remove user's setting

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, this particular change in the test file was to guarantee we are not changing user values. This PR only changes it in a specific case: OpenShift.

@jwendell jwendell added the cherrypick/release-1.20 Set this label on a PR to auto-merge it to the release-1.20 branch label Nov 17, 2023
Copy link
Member

@linsun linsun left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks for adding the details and release note.

@linsun linsun added the do-not-merge/hold Block automatic merging of a PR. label Nov 17, 2023
@linsun
Copy link
Member

linsun commented Nov 17, 2023

Adding /hold for a day - in case others want to review. Just realized this PR is only out for < 1 day.

// This is likely a scenario in OpenShift when the istio-proxy container with image: auto is parsed, if SecurityContext.RunAsUser
// does not exist, OpenShift automatically assigns a value which is based on an annotation in the namespace. Regardless if the user
// provided that value or if it was assigned by OpenShift, the correct value is the one in the template, as set by the `.ProxyUID` field.
if original.SecurityContext != nil && template.SecurityContext != nil && template.SecurityContext.RunAsUser != nil &&
Copy link
Member

Choose a reason for hiding this comment

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

image: auto and securityContext are unrelated. A user can override the proxy container AND set image: some-explicit-proxy-image

Copy link
Member Author

Choose a reason for hiding this comment

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

that's right.

Copy link
Member Author

Choose a reason for hiding this comment

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

@howardjohn fixed.

Copy link
Member

Choose a reason for hiding this comment

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

LGTM now although the function name is maybeconfusing

Use of custom injection (i.e., providing a custom `istio-proxy`
container) is broken on OpenShift.

This is because OpenShift sets the `RunAs` field to be the a
pseudo-random value that varies by namespace. We rely on the `RunAs`
field to be a well-known value, and it's calculated upon injection. We
should stick with that value. `iptables` rules were created based on
that value.

Even if the user provides another value (i.e., it's not set
by OpenShift, but b the user), that's wrong. We should ignore what's in
the original pod and use the calculated one, for these two fields only.
@jwendell jwendell force-pushed the ignore-original-runasuser branch from fdeffa6 to bd3ca95 Compare November 17, 2023 19:03
// This is likely a scenario in OpenShift when the istio-proxy container with image: auto is parsed, if SecurityContext.RunAsUser
// does not exist, OpenShift automatically assigns a value which is based on an annotation in the namespace. Regardless if the user
// provided that value or if it was assigned by OpenShift, the correct value is the one in the template, as set by the `.ProxyUID` field.
if original.SecurityContext != nil && template.SecurityContext != nil && template.SecurityContext.RunAsUser != nil &&
Copy link
Member

Choose a reason for hiding this comment

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

LGTM now although the function name is maybeconfusing

@jwendell jwendell removed the do-not-merge/hold Block automatic merging of a PR. label Nov 17, 2023
@istio-testing istio-testing merged commit 056d019 into istio:master Nov 17, 2023
@istio-testing
Copy link
Collaborator

In response to a cherrypick label: new pull request created: #47914

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherrypick/release-1.20 Set this label on a PR to auto-merge it to the release-1.20 branch size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants