Revert "TBR: Revert "IPC implementation of agentd. The client library supports both IPC and RPC for now.""
This reverts commit 8b59ca39c5f4b98d07a4f7473fdd6e1d585cd275.
Change-Id: Ia5ce2249229955fc6ced331cacdf4181b847c905
diff --git a/test/modules/exec.go b/test/modules/exec.go
index 9088dea..44a6a1a 100644
--- a/test/modules/exec.go
+++ b/test/modules/exec.go
@@ -20,7 +20,6 @@
"v.io/x/ref/internal/logger"
vexec "v.io/x/ref/lib/exec"
"v.io/x/ref/lib/mgmt"
- "v.io/x/ref/services/agent/agentlib"
"v.io/x/ref/test/expect"
)
@@ -114,7 +113,7 @@
return newargs, envvar.MapToSlice(newenv)
}
-func (eh *execHandle) start(sh *Shell, agentfd *os.File, opts *StartOpts, env []string, args []string) (*execHandle, error) {
+func (eh *execHandle) start(sh *Shell, agentPath string, opts *StartOpts, env []string, args []string) (*execHandle, error) {
eh.mu.Lock()
defer eh.mu.Unlock()
eh.sh = sh
@@ -160,11 +159,8 @@
return nil, err
}
config.MergeFrom(serialized)
- if agentfd != nil {
- childfd := len(cmd.ExtraFiles) + vexec.FileOffset
- config.Set(mgmt.SecurityAgentEndpointConfigKey, agentlib.AgentEndpoint(childfd))
- cmd.ExtraFiles = append(cmd.ExtraFiles, agentfd)
- defer agentfd.Close()
+ if agentPath != "" {
+ config.Set(mgmt.SecurityAgentPathConfigKey, agentPath)
}
execOpts = append(execOpts, vexec.ConfigOpt{Config: config})
}
diff --git a/test/modules/shell.go b/test/modules/shell.go
index 0f4106a..4b3400e 100644
--- a/test/modules/shell.go
+++ b/test/modules/shell.go
@@ -138,6 +138,7 @@
"io"
"io/ioutil"
"os"
+ "path/filepath"
"sync"
"syscall"
"time"
@@ -152,6 +153,7 @@
"v.io/x/ref"
"v.io/x/ref/internal/logger"
"v.io/x/ref/lib/exec"
+ "v.io/x/ref/services/agent"
"v.io/x/ref/services/agent/agentlib"
"v.io/x/ref/services/agent/keymgr"
"v.io/x/ref/test/expect"
@@ -184,7 +186,7 @@
tempCredDir string
config exec.Config
principal security.Principal
- agent *keymgr.Agent
+ agent agent.KeyManager
ctx *context.T
logger logging.Logger
sessionVerbosity bool
@@ -230,7 +232,7 @@
if sh.tempCredDir, err = ioutil.TempDir("", "shell_credentials-"); err != nil {
return nil, err
}
- if sh.agent, err = keymgr.NewLocalAgent(ctx, sh.tempCredDir, nil); err != nil {
+ if sh.agent, err = keymgr.NewLocalAgent(sh.tempCredDir, nil); err != nil {
return nil, err
}
sh.principal = p
@@ -253,9 +255,8 @@
// CustomCredentials encapsulates a Principal which can be shared with
// one or more processes run by a Shell.
type CustomCredentials struct {
- p security.Principal
- agent *keymgr.Agent
- id []byte
+ p security.Principal
+ path string
}
// Principal returns the Principal.
@@ -263,11 +264,10 @@
return c.p
}
-// File returns a socket which can be used to connect to the agent
-// managing this principal. Typically you would pass this to a child
-// process.
-func (c *CustomCredentials) File() (*os.File, error) {
- return c.agent.NewConnection(c.id)
+// Path returns the path to the credential's agent.
+// Typically you would pass this to a child process in EnvAgentPath.
+func (c *CustomCredentials) Path() string {
+ return c.path
}
func dup(conn *os.File) (int, error) {
@@ -289,26 +289,23 @@
if sh.ctx == nil {
return nil, nil
}
- id, conn, err := sh.agent.NewPrincipal(sh.ctx, true)
+ id, err := sh.agent.NewPrincipal(true)
if err != nil {
return nil, err
}
- fd, err := dup(conn)
- conn.Close()
+ dir, err := ioutil.TempDir(sh.tempCredDir, "agent")
if err != nil {
return nil, err
}
- ep, err := v23.NewEndpoint(agentlib.AgentEndpoint(fd))
- if err != nil {
- syscall.Close(fd)
+ path := filepath.Join(dir, "sock")
+ if err := sh.agent.ServePrincipal(id, path); err != nil {
return nil, err
}
- p, err := agentlib.NewAgentPrincipal(sh.ctx, ep, v23.GetClient(sh.ctx))
+ p, err := agentlib.NewAgentPrincipalX(path)
if err != nil {
- syscall.Close(fd)
return nil, err
}
- return &CustomCredentials{p, sh.agent, id}, nil
+ return &CustomCredentials{p, path}, nil
}
// NewChildCredentials creates a new principal, served via the security agent
@@ -549,16 +546,13 @@
}
}
- var p *os.File
+ var agentPath string
if opts.Credentials != nil {
- p, err = opts.Credentials.File()
- if err != nil {
- return nil, err
- }
+ agentPath = opts.Credentials.Path()
}
handle := info.factory()
- h, err := handle.start(sh, p, &opts, sh.setupProgramEnv(env), sh.expand(args))
+ h, err := handle.start(sh, agentPath, &opts, sh.setupProgramEnv(env), sh.expand(args))
if err != nil {
return h, err
}
@@ -730,6 +724,7 @@
// by the shell's VeyronCredentials.
delete(m1, ref.EnvCredentials)
delete(m1, ref.EnvAgentEndpoint)
+ delete(m1, ref.EnvAgentPath)
m2 := envvar.MergeMaps(m1, evmap)
return envvar.MapToSlice(m2)
diff --git a/test/v23tests/v23tests.go b/test/v23tests/v23tests.go
index 165749d..75abecb 100644
--- a/test/v23tests/v23tests.go
+++ b/test/v23tests/v23tests.go
@@ -24,7 +24,6 @@
"v.io/v23/security"
"v.io/x/ref"
- "v.io/x/ref/services/agent/agentlib"
"v.io/x/ref/test"
"v.io/x/ref/test/modules"
"v.io/x/ref/test/testutil"
@@ -347,11 +346,9 @@
return
}
- var agentFile *os.File
+ var agentPath string
if creds, err := t.shell.NewChildCredentials("debug"); err == nil {
- if agentFile, err = creds.File(); err != nil {
- t.ctx.Errorf("WARNING: failed to obtain credentials for the debug shell: %v", err)
- }
+ agentPath = creds.Path()
} else {
t.ctx.Errorf("WARNING: failed to obtain credentials for the debug shell: %v", err)
}
@@ -362,8 +359,7 @@
Dir: cwd,
}
// Set up agent for Child.
- attr.Files = append(attr.Files, agentFile)
- attr.Env = append(attr.Env, fmt.Sprintf("%s=%v", ref.EnvAgentEndpoint, agentlib.AgentEndpoint(len(attr.Files)-1)))
+ attr.Env = append(attr.Env, fmt.Sprintf("%s=%v", ref.EnvAgentPath, agentPath))
// Set up environment for Child.
for _, v := range t.shell.Env() {