这是indexloc提供的服务,不要输入任何密码
Skip to content

Create unix domain socket file in temp directory #9211

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

Merged
merged 2 commits into from
Aug 30, 2020

Conversation

nak3
Copy link
Contributor

@nak3 nak3 commented Aug 30, 2020

Currently queue-proxy creates unix domain socket file in the "current"
directory, where is /ko-app/ in upstream.

It works when root user runs queue-proxy or when the directory has
runtime user's permission. In other words, /ko-app/ dir must have
runtime user's permission when nonroot users run queue-proxy.

It is a pain that the directory permission must be cared.

To solve the permission problem, this patch changes to create the
socket file under temp directory.

/lint

/cc @julz @mattmoor @vagababov

Release Note

NONE

Currently queue-proxy creates unix domain socket file in the "current"
directory, where is /ko-app/ in upstream.

It works when root user runs queue-proxy or when the directory has
runtime user's permission. In other words, `/ko-app/` dir must have
runtime user's permission when nonroot users run queue-proxy.

It is a pain that the directory permission must be cared.

To solve the permission problems, this patch changes to create the
socket file under temp directory.
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Aug 30, 2020
@knative-prow-robot knative-prow-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. area/autoscale area/networking labels Aug 30, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@nak3: 0 warnings.

In response to this:

Currently queue-proxy creates unix domain socket file in the "current"
directory, where is /ko-app/ in upstream.

It works when root user runs queue-proxy or when the directory has
runtime user's permission. In other words, /ko-app/ dir must have
runtime user's permission when nonroot users run queue-proxy.

It is a pain that the directory permission must be cared.

To solve the permission problem, this patch changes to create the
socket file under temp directory.

/lint

/cc @julz @mattmoor @vagababov

Release Note

NONE

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.

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 30, 2020
@nak3
Copy link
Contributor Author

nak3 commented Aug 30, 2020

For example, downstream (OpenShift) runs queue-proxy with nonroot user
and gets error listen unix queue.sock: bind: permission denied. Log file.

Our current permission is like this:

$ oc exec -it -c queue-proxy hello-example-wbsxk-1-deployment-59ccc99586-8ptbx sh

sh-4.2$ ls -alh /ko-app/
total 48M
drwxr-xr-x. 2 root root  19 Aug 11 06:20 .
drwxr-xr-x. 1 root root   6 Aug 30 15:06 ..
-rwxrwxr-x. 1 root root 48M Aug 11 06:18 queue

sh-4.2$ ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
65532          1  0.2  0.3 797072 30248 ?        Ssl  15:02   0:00 /ko-app/queue
65532        147  0.0  0.0  11836  2908 pts/0    Ss   15:02   0:00 sh
65532        242  0.0  0.0  51768  3472 pts/0    R+   15:02   0:00 ps aux

I have verified that the permission issue does not happen when socket
file is created in temp directory.

Copy link
Member

@julz julz left a comment

Choose a reason for hiding this comment

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

couple nits but generally seems legit, I'm a little confused why the /ko-app/ directory isn't writable by the user.. shouldn't it be part of the ko contract that the user can write to its own home dir? Is the actual problem here that openshift is running as a non-root user but isn't actually building the images with the rootless ko base image?

@@ -201,7 +201,7 @@ func main() {
// when we're actually in the same container.
transport := &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("unix", unixSocketPath)
return net.Dial("unix", os.TempDir()+unixSocketPath)
Copy link
Member

Choose a reason for hiding this comment

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

nit, but better to do filepath.Join here I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. Fixed.

@@ -63,7 +63,7 @@ const (
// reportingPeriod is the interval of time between reporting stats by queue proxy.
reportingPeriod = 1 * time.Second

unixSocketPath = "queue.sock"
unixSocketPath = "/queue.sock"
Copy link
Member

Choose a reason for hiding this comment

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

we should probably call this unixSocketName since this isn't the path any more

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and I changed it to var unixSocketPath = filepath.Join(os.TempDir(), "queue.sock").

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 30, 2020
@mattmoor
Copy link
Member

/hold

Just saw @julz comments

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 30, 2020
Copy link
Member

@julz julz left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: julz, mattmoor, nak3

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

@julz
Copy link
Member

julz commented Aug 30, 2020

I think my comments are all addressed, I'm interested why this doesn't "just work" in openshift (guessing it's just changing user and not changing base image to match?), but it seems like a reasonable fix either way

@mattmoor
Copy link
Member

/unhold

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 30, 2020
@knative-prow-robot knative-prow-robot merged commit 4c2ae65 into knative:master Aug 30, 2020
@nak3
Copy link
Contributor Author

nak3 commented Aug 31, 2020

I'm interested why this doesn't "just work" in openshift (guessing it's just changing user and not changing base image to match?),

Yes, I think your guessing is currect. Our base image is this:

https://github.com/openshift/knative-serving/blob/master/openshift/ci-operator/knative-images/queue/Dockerfile

And the binary is pushed by this:

https://github.com/openshift/release/blob/master/ci-operator/config/openshift/knative-serving/openshift-knative-serving-release-next__4.6.yaml#L52-L59

So I think we also could solve the issue by setting the permission to /ko-app/ in base image.

@nak3 nak3 deleted the use-tmpdir-unixdomain branch August 31, 2020 09:52
@julz
Copy link
Member

julz commented Aug 31, 2020

thanks for the follow-up @nak3, makes sense!

arturenault pushed a commit to arturenault/serving that referenced this pull request Aug 31, 2020
* Create unix domain socket file in temp directory

Currently queue-proxy creates unix domain socket file in the "current"
directory, where is /ko-app/ in upstream.

It works when root user runs queue-proxy or when the directory has
runtime user's permission. In other words, `/ko-app/` dir must have
runtime user's permission when nonroot users run queue-proxy.

It is a pain that the directory permission must be cared.

To solve the permission problems, this patch changes to create the
socket file under temp directory.

* Use filepath.Join
arturenault pushed a commit to arturenault/serving that referenced this pull request Aug 31, 2020
* Create unix domain socket file in temp directory

Currently queue-proxy creates unix domain socket file in the "current"
directory, where is /ko-app/ in upstream.

It works when root user runs queue-proxy or when the directory has
runtime user's permission. In other words, `/ko-app/` dir must have
runtime user's permission when nonroot users run queue-proxy.

It is a pain that the directory permission must be cared.

To solve the permission problems, this patch changes to create the
socket file under temp directory.

* Use filepath.Join
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. area/autoscale area/networking cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants