@@ -2,6 +2,7 @@ package jail
2
2
3
3
import (
4
4
"context"
5
+ cryptotls "crypto/tls"
5
6
"fmt"
6
7
"log/slog"
7
8
"os/exec"
@@ -10,7 +11,6 @@ import (
10
11
11
12
"github.com/coder/jail/namespace"
12
13
"github.com/coder/jail/proxy"
13
- "github.com/coder/jail/tls"
14
14
)
15
15
16
16
type Commander interface {
@@ -19,19 +19,23 @@ type Commander interface {
19
19
Close () error
20
20
}
21
21
22
+ type CertificateManager interface {
23
+ SetupTLSAndWriteCACert () (* cryptotls.Config , string , string , error )
24
+ }
25
+
22
26
type Config struct {
23
27
RuleEngine proxy.RuleEvaluator
24
28
Auditor proxy.Auditor
25
- CertManager * tls. CertificateManager
29
+ CertManager CertificateManager
26
30
Logger * slog.Logger
27
31
}
28
32
29
33
type Jail struct {
30
- commandExecutor Commander
31
- proxyServer * proxy.ProxyServer
32
- logger * slog.Logger
33
- ctx context.Context
34
- cancel context.CancelFunc
34
+ commander Commander
35
+ proxyServer * proxy.ProxyServer
36
+ logger * slog.Logger
37
+ ctx context.Context
38
+ cancel context.CancelFunc
35
39
}
36
40
37
41
func New (ctx context.Context , config Config ) (* Jail , error ) {
@@ -75,17 +79,17 @@ func New(ctx context.Context, config Config) (*Jail, error) {
75
79
ctx , cancel := context .WithCancel (ctx )
76
80
77
81
return & Jail {
78
- commandExecutor : commander ,
79
- proxyServer : proxyServer ,
80
- logger : config .Logger ,
81
- ctx : ctx ,
82
- cancel : cancel ,
82
+ commander : commander ,
83
+ proxyServer : proxyServer ,
84
+ logger : config .Logger ,
85
+ ctx : ctx ,
86
+ cancel : cancel ,
83
87
}, nil
84
88
}
85
89
86
90
func (j * Jail ) Start () error {
87
91
// Open the command executor (network namespace)
88
- err := j .commandExecutor .Start ()
92
+ err := j .commander .Start ()
89
93
if err != nil {
90
94
return fmt .Errorf ("failed to open command executor: %v" , err )
91
95
}
@@ -105,7 +109,7 @@ func (j *Jail) Start() error {
105
109
}
106
110
107
111
func (j * Jail ) Command (command []string ) * exec.Cmd {
108
- return j .commandExecutor .Command (command )
112
+ return j .commander .Command (command )
109
113
}
110
114
111
115
func (j * Jail ) Close () error {
@@ -118,7 +122,7 @@ func (j *Jail) Close() error {
118
122
}
119
123
120
124
// Close command executor
121
- return j .commandExecutor .Close ()
125
+ return j .commander .Close ()
122
126
}
123
127
124
128
// newCommander creates a new NetJail instance for the current platform
0 commit comments