Skip to content

feat!: add safety check if not running as PID 1. #153

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ $ vim .devcontainer/Dockerfile

Exit the container, and re-run the `docker run` command... after the build completes, `htop` should exist in the container! 🥳

> **Note:** Envbuilder performs destructive filesystem operations! To guard against accidental data loss, it
> will refuse to run if it detects it is not running as PID 1.
> If you need to bypass this behaviour for any reason, you can bypass this safety check by setting
> `DANGEROUS_BYPASS_PID_CHECK=1`.
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest using the prefix, ENVBUILDER_DANGEROUS_DISABLE_PID_CHECK (also observe bypass/disable used inconsistently).


## Container Registry Authentication

envbuilder uses Kaniko to build containers. You should [follow their instructions](https://github.com/GoogleContainerTools/kaniko#pushing-to-different-registries) to create an authentication configuration.
Expand Down
11 changes: 11 additions & 0 deletions cmd/envbuilder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ func main() {
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
options := envbuilder.OptionsFromEnv(os.LookupEnv)
if os.Getpid() != 1 {
// TODO: rebase once https://github.com/coder/envbuilder/pull/140 is in
if env, found := os.LookupEnv("DANGEROUS_DISABLE_PID_CHECK"); found && env == "1" {
_, _ = fmt.Fprintln(os.Stderr, `Bypassing PID check as DANGEROUS_DISABLE_PID_CHECK=1.`)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_, _ = fmt.Fprintln(os.Stderr, `Bypassing PID check as DANGEROUS_DISABLE_PID_CHECK=1.`)
_, _ = fmt.Fprintln(os.Stderr, `ENVBUILDER_DANGEROUS_DISABLE_PID_CHECK enabled, skipping PID check.`)

I think we're better of not logging the value here. Also, how would you feel about changing it to something not so easily typed? Perhaps even "i_really_know_what_im_doing_please_let_me_brake_my_system". 😂

} else {
Comment on lines +36 to +38
Copy link
Member Author

Choose a reason for hiding this comment

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

review: will move this inside Options once Bruno's PR is in.

_, _ = fmt.Fprintln(os.Stderr, `WARNING: Not running as PID 1, so exiting IMMEDIATELY!`)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_, _ = fmt.Fprintln(os.Stderr, `WARNING: Not running as PID 1, so exiting IMMEDIATELY!`)
_, _ = fmt.Fprintln(os.Stderr, `WARNING: Envbuilder is not running as PID 1, exiting IMMEDIATELY!`)

_, _ = fmt.Fprintln(os.Stderr, `This is a safety check to guard against accidental data loss when run outside of a container.`)
_, _ = fmt.Fprintln(os.Stderr, `To bypass this check, set DANGEROUS_DISABLE_PID_CHECK=1.`)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_, _ = fmt.Fprintln(os.Stderr, `To bypass this check, set DANGEROUS_DISABLE_PID_CHECK=1.`)
_, _ = fmt.Fprintln(os.Stderr, `To skip this check, set ENVBUILDER_DANGEROUS_DISABLE_PID_CHECK=1.`)

os.Exit(1)
}
}

var sendLogs func(ctx context.Context, log ...agentsdk.Log) error
agentURL := os.Getenv("CODER_AGENT_URL")
Expand Down
Loading