Skip to content

Commit 9d54933

Browse files
authored
Add proxy support for hook-bootkit and hook-docker (#162)
## Description Add support for pulling docker images and specifically the tink-worker image via a proxy by configuring appropriate proxy variables via Boots. ## Why is this needed Currently a user cannot use a proxy to pull tink-worker and container images for workflows. This PR enables proxy support for this. A user will have to pass HTTP_PROXY, HTTPS_PROXY and NO_PROXY to Boots as cli args or environment variables. These values in Boots, [extra kernel args](https://github.com/tinkerbell/boots/blob/c92674c5f39f7005602bc6882afd035dc0f13d0c/cmd/boots/main.go#L371), get populated in Hook's `/proc/cmdline` file. hook-bootkit and hook-docker will pick up those variables and set them as an environment variables in order to pull tink-worker and workflow images from a proxy server. Fixes: # ## How Has This Been Tested? I have tested this changes by creating a baremetal machines using the proxy settings. ## How are existing users impacted? What migration steps/scripts do we need? No changes are required for existing user. ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
2 parents b8d4c1f + 873a88b commit 9d54933

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

hook-bootkit/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type tinkConfig struct {
4040

4141
// tinkServerTLS is whether or not to use TLS for tink-server communication.
4242
tinkServerTLS string
43+
httpProxy string
44+
httpsProxy string
45+
noProxy string
4346
}
4447

4548
const maxRetryAttempts = 20
@@ -83,6 +86,9 @@ func main() {
8386
fmt.Sprintf("TINKERBELL_TLS=%s", cfg.tinkServerTLS),
8487
fmt.Sprintf("WORKER_ID=%s", cfg.workerID),
8588
fmt.Sprintf("ID=%s", cfg.workerID),
89+
fmt.Sprintf("HTTP_PROXY=%s", cfg.httpProxy),
90+
fmt.Sprintf("HTTPS_PROXY=%s", cfg.httpsProxy),
91+
fmt.Sprintf("NO_PROXY=%s", cfg.noProxy),
8692
},
8793
AttachStdout: true,
8894
AttachStderr: true,
@@ -126,6 +132,10 @@ func main() {
126132
time.Sleep(time.Second * 3)
127133
fmt.Println("Starting Communication with Docker Engine")
128134

135+
os.Setenv("HTTP_PROXY", cfg.httpProxy)
136+
os.Setenv("HTTPS_PROXY", cfg.httpsProxy)
137+
os.Setenv("NO_PROXY", cfg.noProxy)
138+
129139
// Create Docker client with API (socket)
130140
ctx := context.Background()
131141
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
@@ -204,6 +214,12 @@ func parseCmdLine(cmdLines []string) (cfg tinkConfig) {
204214
cfg.tinkWorkerImage = cmdLine[1]
205215
case "tinkerbell_tls":
206216
cfg.tinkServerTLS = cmdLine[1]
217+
case "HTTP_PROXY":
218+
cfg.httpProxy = cmdLine[1]
219+
case "HTTPS_PROXY":
220+
cfg.httpsProxy = cmdLine[1]
221+
case "NO_PROXY":
222+
cfg.noProxy = cmdLine[1]
207223
}
208224
}
209225
return cfg

hook-docker/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313
type tinkConfig struct {
1414
syslogHost string
1515
insecureRegistries []string
16+
httpProxy string
17+
httpsProxy string
18+
noProxy string
1619
}
1720

1821
type dockerConfig struct {
@@ -58,6 +61,14 @@ func main() {
5861
cmd := exec.Command("/usr/local/bin/docker-init", "/usr/local/bin/dockerd")
5962
cmd.Stdout = os.Stdout
6063
cmd.Stderr = os.Stderr
64+
65+
myEnvs := make([]string, 0, 3)
66+
myEnvs = append(myEnvs, fmt.Sprintf("HTTP_PROXY=%s", cfg.httpProxy))
67+
myEnvs = append(myEnvs, fmt.Sprintf("HTTPS_PROXY=%s", cfg.httpsProxy))
68+
myEnvs = append(myEnvs, fmt.Sprintf("NO_PROXY=%s", cfg.noProxy))
69+
70+
cmd.Env = append(os.Environ(), myEnvs...)
71+
6172
err = cmd.Run()
6273
if err != nil {
6374
panic(err)
@@ -90,6 +101,12 @@ func parseCmdLine(cmdLines []string) (cfg tinkConfig) {
90101
cfg.syslogHost = cmdLine[1]
91102
case "insecure_registries":
92103
cfg.insecureRegistries = strings.Split(cmdLine[1], ",")
104+
case "HTTP_PROXY":
105+
cfg.httpProxy = cmdLine[1]
106+
case "HTTPS_PROXY":
107+
cfg.httpsProxy = cmdLine[1]
108+
case "NO_PROXY":
109+
cfg.noProxy = cmdLine[1]
93110
}
94111
}
95112
return cfg

0 commit comments

Comments
 (0)