packer/plugin: Require the magic cookie to be present to run
This is just a silly check to make sure people aren't executing the plugins directly. If they are, a nicer error message is shown.
This commit is contained in:
parent
e3aada4a2f
commit
3e1d902560
|
@ -205,6 +205,7 @@ func (c *Client) Start() (address string, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
env := []string{
|
env := []string{
|
||||||
|
fmt.Sprintf("%s=%s", MagicCookieKey, MagicCookieValue),
|
||||||
fmt.Sprintf("PACKER_PLUGIN_MIN_PORT=%d", c.config.MinPort),
|
fmt.Sprintf("PACKER_PLUGIN_MIN_PORT=%d", c.config.MinPort),
|
||||||
fmt.Sprintf("PACKER_PLUGIN_MAX_PORT=%d", c.config.MaxPort),
|
fmt.Sprintf("PACKER_PLUGIN_MAX_PORT=%d", c.config.MaxPort),
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
packrpc "github.com/mitchellh/packer/packer/rpc"
|
packrpc "github.com/mitchellh/packer/packer/rpc"
|
||||||
|
@ -21,9 +22,16 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const MagicCookieKey = "PACKER_PLUGIN_MAGIC_COOKIE"
|
||||||
|
const MagicCookieValue = "d602bf8f470bc67ca7faa0386276bbdd4330efaf76d1a219cb4d6991ca9872b2"
|
||||||
|
|
||||||
// This serves a single RPC connection on the given RPC server on
|
// This serves a single RPC connection on the given RPC server on
|
||||||
// a random port.
|
// a random port.
|
||||||
func serve(server *rpc.Server) (err error) {
|
func serve(server *rpc.Server) (err error) {
|
||||||
|
if os.Getenv(MagicCookieKey) != MagicCookieValue {
|
||||||
|
return errors.New("Please do not execute plugins directly. Packer will execute these for you.")
|
||||||
|
}
|
||||||
|
|
||||||
// If there is no explicit number of Go threads to use, then set it
|
// If there is no explicit number of Go threads to use, then set it
|
||||||
if os.Getenv("GOMAXPROCS") == "" {
|
if os.Getenv("GOMAXPROCS") == "" {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
Loading…
Reference in New Issue