Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for additional auth in docker build #18604

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions components/image-builder-bob/pkg/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
package builder

import (
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -36,7 +33,6 @@ func GetConfigFromEnv() (*Config, error) {
BaseRef: os.Getenv("BOB_BASE_REF"),
BaseContext: os.Getenv("THEIA_WORKSPACE_ROOT"),
BuildBase: os.Getenv("BOB_BUILD_BASE") == "true",
BaseLayerAuth: os.Getenv("BOB_BASELAYER_AUTH"),
ChevronTango marked this conversation as resolved.
Show resolved Hide resolved
WorkspaceLayerAuth: os.Getenv("BOB_WSLAYER_AUTH"),
Dockerfile: os.Getenv("BOB_DOCKERFILE_PATH"),
ContextDir: os.Getenv("BOB_CONTEXT_DIR"),
Expand Down Expand Up @@ -67,60 +63,5 @@ func GetConfigFromEnv() (*Config, error) {
}
}

var authKey = os.Getenv("BOB_AUTH_KEY")
ChevronTango marked this conversation as resolved.
Show resolved Hide resolved
if authKey != "" {
if len(authKey) != 32 {
return nil, xerrors.Errorf("BOB_AUTH_KEY must be exactly 32 bytes long")
}

// we have an authkey, hence assume that the auth fields are base64 encoded and encrypted
if cfg.BaseLayerAuth != "" {
dec, err := base64.RawStdEncoding.DecodeString(cfg.BaseLayerAuth)
if err != nil {
return nil, xerrors.Errorf("BOB_BASELAYER_AUTH is not base64 encoded but BOB_AUTH_KEY is present")
}
cfg.BaseLayerAuth, err = decrypt(dec, authKey)
if err != nil {
return nil, xerrors.Errorf("cannot decrypt BOB_BASELAYER_AUTH: %w", err)
}
}
if cfg.WorkspaceLayerAuth != "" {
dec, err := base64.RawStdEncoding.DecodeString(cfg.WorkspaceLayerAuth)
if err != nil {
return nil, xerrors.Errorf("BOB_WSLAYER_AUTH is not base64 encoded but BOB_AUTH_KEY is present")
}
cfg.WorkspaceLayerAuth, err = decrypt(dec, authKey)
if err != nil {
return nil, xerrors.Errorf("cannot decrypt BOB_WSLAYER_AUTH: %w", err)
}
}
}

return cfg, nil
}

// source: https://astaxie.gitbooks.io/build-web-application-with-golang/en/09.6.html
func decrypt(ciphertext []byte, key string) (string, error) {
c, err := aes.NewCipher([]byte(key))
if err != nil {
return "", err
}

gcm, err := cipher.NewGCM(c)
if err != nil {
return "", err
}

nonceSize := gcm.NonceSize()
if len(ciphertext) < nonceSize {
return "", xerrors.Errorf("ciphertext too short")
}

nonce, ciphertext := ciphertext[:nonceSize], ciphertext[nonceSize:]
res, err := gcm.Open(nil, nonce, ciphertext, nil)
if err != nil {
return "", err
}

return string(res), nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
{Name: "BOB_BUILD_BASE", Value: buildBase},
{Name: "BOB_DOCKERFILE_PATH", Value: dockerfilePath},
{Name: "BOB_CONTEXT_DIR", Value: contextPath},
{
Name: "BOB_WSLAYER_AUTH",
Value: string(additionalAuth),
},
{Name: "GITPOD_TASKS", Value: `[{"name": "build", "init": "sudo -E /app/bob build"}]`},
{Name: "WORKSPACEKIT_RING2_ENCLAVE", Value: "/app/bob proxy"},
{Name: "WORKSPACEKIT_BOBPROXY_BASEREF", Value: baseref},
Expand Down