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

Add support for setcap from build command #129

Merged
merged 4 commits into from
Feb 6, 2023
Merged

Conversation

francislavoie
Copy link
Member

Fix #128

Haven't tested this yet. But it should be straight-forwards.

One detail I'm not sure how to handle is sudo. The runDev version of the code uses sudo by default, and that seems reasonable since a dev account is probably a regular user and not root. But this purpose of the runBuild version is to run in Docker, which will be running as root. So having sudo would fail. I just added another env var to cover that case.

Is there a better way to automatically detect whether sudo should be used? I'm not sure how that should be done from Go.

See caddyserver/caddy#5270 where we made this change for Caddy
@abjugard
Copy link

The old doumentation for XCADDY_SETCAP said it only ran while in devmode, I don't see any code changes related to this. I'm not saying it's wrong, this is more of a "did we miss anything?" check than anything hehe.

@francislavoie
Copy link
Member Author

Yeah, that was correct. I'm not sure I understand the question?

It was only in runDev previously, I'm adding it to runBuild as well here.

The difference is runDev is invoked when running xcaddy run --config Caddyfile which builds then runs an ephemeral binary, and runBuild is invoked on xcaddy build which just builds and outputs the binary.

@abjugard
Copy link

Now I feel silly 😅

Copy link
Member

@mohammed90 mohammed90 left a comment

Choose a reason for hiding this comment

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

Thanks for doing this, Francis! About this

But this purpose of the runBuild version is to run in Docker, which will be running as root. So having sudo would fail.

If I'm not mistaken, using sudo while root will just executes the subsequent command normally without errors. Is there a special circumstance in Docker build env that would break it?

cmd/main.go Outdated Show resolved Hide resolved
cmd/main.go Outdated Show resolved Hide resolved
Copy link
Member

@mohammed90 mohammed90 left a comment

Choose a reason for hiding this comment

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

Look great now. Thanks!

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks! Good call on the LookPath too. Sounds like in most cases that should work without even needing to set the env var to toggle sudo.

README.md Outdated Show resolved Hide resolved
cmd/main.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setcap immediately after building
4 participants