Skip to content

Commit 0899f4d

Browse files
iQQBotroboquat
authored andcommitted
Revert "[image-builder-bob] Use separate auth for target and base"
This reverts commit 7b27392.
1 parent 7018064 commit 0899f4d

File tree

2 files changed

+17
-33
lines changed

2 files changed

+17
-33
lines changed

components/image-builder-bob/cmd/proxy.go

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919

2020
var proxyOpts struct {
2121
BaseRef, TargetRef string
22-
BaseAuth string
23-
TargetAuth string
22+
Auth string
23+
AdditionalAuth string
2424
}
2525

2626
// proxyCmd represents the build command
@@ -31,28 +31,15 @@ var proxyCmd = &cobra.Command{
3131
log.Init("bob", "", true, os.Getenv("SUPERVISOR_DEBUG_ENABLE") == "true")
3232
log := log.WithField("command", "proxy")
3333

34-
// Base refers to the user's base image. We prefer user given auth
35-
// for base ref
36-
authBase, err := proxy.NewAuthorizerFromEnvVar(proxyOpts.BaseAuth)
34+
authP, err := proxy.NewAuthorizerFromDockerEnvVar(proxyOpts.Auth)
3735
if err != nil {
38-
log.WithError(err).WithField("auth", proxyOpts.BaseAuth).Fatal("cannot unmarshal authBase")
36+
log.WithError(err).WithField("auth", proxyOpts.Auth).Fatal("cannot unmarshal auth")
3937
}
40-
// Target refers to the target registry where we want to upload the built image.
41-
// We prefer existing configuration for target auth
42-
authTarget, err := proxy.NewAuthorizerFromDockerEnvVar(proxyOpts.TargetAuth)
38+
authA, err := proxy.NewAuthorizerFromEnvVar(proxyOpts.AdditionalAuth)
4339
if err != nil {
44-
log.WithError(err).WithField("auth", proxyOpts.TargetAuth).Fatal("cannot unmarshal authTarget")
45-
}
46-
// fallback: Add missing auth to authTarget from authBase
47-
authTarget = authTarget.AddIfNotExists(authBase)
48-
49-
// Just reuse authBase as authTarget if authTarget has not been supplied
50-
if authBase == nil {
51-
authBase = authTarget
52-
} else {
53-
// fallback: Add missing auth to authBase from authTarget
54-
authBase = authBase.AddIfNotExists(authTarget)
40+
log.WithError(err).WithField("auth", proxyOpts.Auth).Fatal("cannot unmarshal auth")
5541
}
42+
authP = authP.AddIfNotExists(authA)
5643

5744
baseref, err := reference.ParseNormalizedNamed(proxyOpts.BaseRef)
5845
if err != nil {
@@ -71,22 +58,19 @@ var proxyCmd = &cobra.Command{
7158
targettag = r.Tag()
7259
}
7360

74-
authB := func() docker.Authorizer { return docker.NewDockerAuthorizer(docker.WithAuthCreds(authBase.Authorize)) }
75-
authT := func() docker.Authorizer {
76-
return docker.NewDockerAuthorizer(docker.WithAuthCreds(authTarget.Authorize))
77-
}
61+
auth := func() docker.Authorizer { return docker.NewDockerAuthorizer(docker.WithAuthCreds(authP.Authorize)) }
7862
prx, err := proxy.NewProxy(&url.URL{Host: "localhost:8080", Scheme: "http"}, map[string]proxy.Repo{
7963
"base": {
8064
Host: reference.Domain(baseref),
8165
Repo: reference.Path(baseref),
8266
Tag: basetag,
83-
Auth: authB,
67+
Auth: auth,
8468
},
8569
"target": {
8670
Host: reference.Domain(targetref),
8771
Repo: reference.Path(targetref),
8872
Tag: targettag,
89-
Auth: authT,
73+
Auth: auth,
9074
},
9175
})
9276
if err != nil {
@@ -108,6 +92,6 @@ func init() {
10892
// These env vars start with `WORKSPACEKIT_` so that they aren't passed on to ring2
10993
proxyCmd.Flags().StringVar(&proxyOpts.BaseRef, "base-ref", os.Getenv("WORKSPACEKIT_BOBPROXY_BASEREF"), "ref of the base image")
11094
proxyCmd.Flags().StringVar(&proxyOpts.TargetRef, "target-ref", os.Getenv("WORKSPACEKIT_BOBPROXY_TARGETREF"), "ref of the target image")
111-
proxyCmd.Flags().StringVar(&proxyOpts.BaseAuth, "base-auth", os.Getenv("WORKSPACEKIT_BOBPROXY_AUTH"), "authentication to use for base ref")
112-
proxyCmd.Flags().StringVar(&proxyOpts.TargetAuth, "target-auth", os.Getenv("WORKSPACEKIT_BOBPROXY_TARGETAUTH"), "authentication to use for target ref")
95+
proxyCmd.Flags().StringVar(&proxyOpts.Auth, "auth", os.Getenv("WORKSPACEKIT_BOBPROXY_AUTH"), "authentication to use")
96+
proxyCmd.Flags().StringVar(&proxyOpts.AdditionalAuth, "additional-auth", os.Getenv("WORKSPACEKIT_BOBPROXY_ADDITIONALAUTH"), "additional authentication to use")
11397
}

components/image-builder-mk3/pkg/orchestrator/orchestrator.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
330330
bobBaseref += ":latest"
331331
}
332332
wsref, err := reference.ParseNamed(wsrefstr)
333-
var baseRefAuth []byte
333+
var additionalAuth []byte
334334
if err == nil {
335-
baseRefAuth, err = json.Marshal(reqauth.GetImageBuildAuthFor([]string{
335+
additionalAuth, err = json.Marshal(reqauth.GetImageBuildAuthFor([]string{
336336
reference.Domain(wsref),
337337
}))
338338
if err != nil {
@@ -374,15 +374,15 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
374374
{Name: "WORKSPACEKIT_BOBPROXY_BASEREF", Value: baseref},
375375
{Name: "WORKSPACEKIT_BOBPROXY_TARGETREF", Value: wsrefstr},
376376
{
377-
Name: "WORKSPACEKIT_BOBPROXY_TARGETAUTH",
377+
Name: "WORKSPACEKIT_BOBPROXY_AUTH",
378378
Secret: &wsmanapi.EnvironmentVariable_SecretKeyRef{
379379
SecretName: o.Config.PullSecret,
380380
Key: ".dockerconfigjson",
381381
},
382382
},
383383
{
384-
Name: "WORKSPACEKIT_BOBPROXY_AUTH",
385-
Value: string(baseRefAuth),
384+
Name: "WORKSPACEKIT_BOBPROXY_ADDITIONALAUTH",
385+
Value: string(additionalAuth),
386386
},
387387
{Name: "SUPERVISOR_DEBUG_ENABLE", Value: fmt.Sprintf("%v", log.Log.Logger.IsLevelEnabled(logrus.DebugLevel))},
388388
},

0 commit comments

Comments
 (0)