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 LaunchAgents directory permissions, bail if -install is run with sudo #244

Merged
merged 21 commits into from
Apr 29, 2020

Conversation

nonrational
Copy link
Member

@nonrational nonrational commented Apr 24, 2020

Resolves #141
Resolves #76

  1. The permission bits used to create ~/Library/LaunchAgents (if it doesn't exist) are incorrectly set to 0644 instead of 0755. This PR correctly sets it to 0755.
  2. Since I was already touching setup, decided to knock out puma-dev -install should warn if run under sudo #76 as well. If you try to run puma-dev install under sudo, we bail out immediately.
    image

Changes

  1. Change 0644 to 0755 @ (will_provide_link)
  2. To enable testing, refactor InstallIntoSystem to take a struct for all its arguments.
  3. Add setup_test.go to verify that InstallIntoSystem creates the directory with the correct permissions.
  4. Given we can't test the "live" code without blowing away the ~/Library/LaunchAgents directory locally, write a makefile test that does the assets for us locally.
  5. Write a test that ONLY runs on TravisCI machines that actually exercises the -setup main path. Not sure how that will go... Punting on this. It's hairy.
  6. Ancillary: Limit DNS retry attempts to 3 instead of 10 to enable faster failure.
  7. Ancillary: Add golintci-lint config file
  8. Refuse to allow -install to run with sudo.

@nonrational nonrational requested a review from evanphx April 24, 2020 15:58
return nil
}

func Stop() error {
Copy link
Member Author

@nonrational nonrational Apr 24, 2020

Choose a reason for hiding this comment

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

moved this to dev/stop.go, since it's used in both linux and darwin (and doesn't have anything to do with setup)

LaunchAgentDirPath string
Domains string
Timeout string
}
Copy link
Member Author

Choose a reason for hiding this comment

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

provide args type to approximate named function params.

@@ -44,6 +44,7 @@ func TestServeDNS(t *testing.T) {

return nil
},
retry.Attempts(3),
Copy link
Member Author

Choose a reason for hiding this comment

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

limit retries to 3 in tests to help fail faster. added while debugging another issue.

Domains: *fDomains,
LaunchAgentDirPath: "~/Library/LaunchAgents",
ListenPort: *fInstallPort,
LogfilePath: "~/Library/Logs/puma-dev.log",
Copy link
Member Author

Choose a reason for hiding this comment

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

probably a good idea to pull this out into shared variable, then add something like puma-dev -f logs (similar to heroku -f logs)

Copy link
Member Author

Choose a reason for hiding this comment

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

again, coming in follow-up PR.

@nonrational nonrational changed the title Fix LaunchAgents directory permissions Fix LaunchAgents directory permissions, bail if -install is run with sudo Apr 24, 2020
- uses: actions/upload-artifact@v1
with:
name: go-${{ matrix.go-version }}-${{ matrix.os }}
path: coverage.html
Copy link
Member Author

Choose a reason for hiding this comment

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

given that this uploads to a zip, kinda useless.

timeout: 1m
tests: true
service:
golangci-lint-version: 1.24.x # use the fixed version to not introduce new linters unexpectedly
Copy link
Member Author

Choose a reason for hiding this comment

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

dropping this here to potentially include in CI in future.

./puma-dev -d 'test:localhost:loc.al:puma' -install
test -f "$$HOME/Library/LaunchAgents/io.puma.dev.plist"
sleep 2
test -f "$$HOME/Library/Logs/puma-dev.log"
Copy link
Member Author

Choose a reason for hiding this comment

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

since we can't test the "default" install path inside unit tests, provide this helper to guarantee that files exist as expected.

i have a follow-up PR that reworks this a bit.

Domains: *fDomains,
LaunchAgentDirPath: "~/Library/LaunchAgents",
ListenPort: *fInstallPort,
LogfilePath: "~/Library/Logs/puma-dev.log",
Copy link
Member Author

Choose a reason for hiding this comment

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

again, coming in follow-up PR.

@@ -95,7 +95,21 @@ func Cleanup() {
}
}

func InstallIntoSystem(listenPort, tlsPort int, dir, domains, timeout string) error {
type InstallIntoSystemArgs struct {
Copy link
Member Author

Choose a reason for hiding this comment

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

not sure if convention is to call this -Args or -Params or something else...

plist := homedir.MustExpand("~/Library/LaunchAgents/io.puma.dev.plist")

err = os.MkdirAll(plistDir, 0644)
err = os.MkdirAll(plistDir, 0755)
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the bugfix.

@nonrational nonrational merged commit e264766 into master Apr 29, 2020
@nonrational nonrational deleted the launch-agent-perms branch September 19, 2020 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants