-
Notifications
You must be signed in to change notification settings - Fork 43
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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.`) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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 |
||||||
} else { | ||||||
Comment on lines
+36
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review: will move this inside |
||||||
_, _ = fmt.Fprintln(os.Stderr, `WARNING: Not running as PID 1, so exiting IMMEDIATELY!`) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
_, _ = 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.`) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
os.Exit(1) | ||||||
} | ||||||
} | ||||||
|
||||||
var sendLogs func(ctx context.Context, log ...agentsdk.Log) error | ||||||
agentURL := os.Getenv("CODER_AGENT_URL") | ||||||
|
There was a problem hiding this comment.
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).