2018-12-04 05:34:12 +01:00
|
|
|
From 229a891b45b996a2cd10f5a71541d124e884556e Mon Sep 17 00:00:00 2001
|
2017-03-08 10:03:15 +01:00
|
|
|
From: Aleksa Sarai <asarai@suse.de>
|
|
|
|
Date: Wed, 8 Mar 2017 11:43:29 +1100
|
|
|
|
Subject: [PATCH 2/2] SUSE: implement SUSE container secrets
|
|
|
|
|
|
|
|
This allows for us to pass in host credentials to a container, allowing
|
|
|
|
for SUSEConnect to work with containers.
|
|
|
|
|
|
|
|
THIS PATCH IS NOT TO BE UPSTREAMED, DUE TO THE FACT THAT IT IS
|
|
|
|
SUSE-SPECIFIC, AND UPSTREAM DOES NOT APPROVE OF THIS CONCEPT BECAUSE IT
|
|
|
|
MAKES BUILDS NOT ENTIRELY REPRODUCIBLE.
|
|
|
|
|
2018-08-15 09:09:12 +02:00
|
|
|
SUSE-Bugs: bsc#1057743 bsc#1055676 bsc#1030702
|
2017-03-08 10:03:15 +01:00
|
|
|
Signed-off-by: Aleksa Sarai <asarai@suse.de>
|
|
|
|
---
|
2018-02-13 12:34:28 +01:00
|
|
|
components/engine/daemon/start.go | 5 +
|
2018-08-15 09:09:12 +02:00
|
|
|
components/engine/daemon/suse_secrets.go | 396 +++++++++++++++++++++++
|
|
|
|
2 files changed, 401 insertions(+)
|
2018-02-13 12:34:28 +01:00
|
|
|
create mode 100644 components/engine/daemon/suse_secrets.go
|
2017-03-08 10:03:15 +01:00
|
|
|
|
2018-02-13 12:34:28 +01:00
|
|
|
diff --git a/components/engine/daemon/start.go b/components/engine/daemon/start.go
|
2018-08-15 09:09:12 +02:00
|
|
|
index c00bd9ceb22b..aa705888df39 100644
|
2018-02-13 12:34:28 +01:00
|
|
|
--- a/components/engine/daemon/start.go
|
|
|
|
+++ b/components/engine/daemon/start.go
|
2018-08-15 09:09:12 +02:00
|
|
|
@@ -151,6 +151,11 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
|
2017-03-08 10:03:15 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // SUSE:secrets -- inject the SUSE secret store
|
|
|
|
+ if err := daemon.injectSuseSecretStore(container); err != nil {
|
2018-08-15 09:09:12 +02:00
|
|
|
+ return errdefs.System(err)
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
spec, err := daemon.createSpec(container)
|
|
|
|
if err != nil {
|
2018-08-15 09:09:12 +02:00
|
|
|
return errdefs.System(err)
|
2018-02-13 12:34:28 +01:00
|
|
|
diff --git a/components/engine/daemon/suse_secrets.go b/components/engine/daemon/suse_secrets.go
|
2017-03-08 10:03:15 +01:00
|
|
|
new file mode 100644
|
2018-12-04 05:34:12 +01:00
|
|
|
index 000000000000..087c877015a7
|
2017-03-08 10:03:15 +01:00
|
|
|
--- /dev/null
|
2018-02-13 12:34:28 +01:00
|
|
|
+++ b/components/engine/daemon/suse_secrets.go
|
2018-08-15 09:09:12 +02:00
|
|
|
@@ -0,0 +1,396 @@
|
2017-03-08 10:03:15 +01:00
|
|
|
+/*
|
|
|
|
+ * suse-secrets: patch for Docker to implement SUSE secrets
|
|
|
|
+ * Copyright (C) 2017 SUSE LLC.
|
|
|
|
+ *
|
|
|
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
+ * you may not use this file except in compliance with the License.
|
|
|
|
+ * You may obtain a copy of the License at
|
|
|
|
+ *
|
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
+ *
|
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
|
+ * limitations under the License.
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+package daemon
|
|
|
|
+
|
|
|
|
+import (
|
2017-10-18 06:27:06 +02:00
|
|
|
+ "archive/tar"
|
|
|
|
+ "bytes"
|
2017-03-08 10:03:15 +01:00
|
|
|
+ "fmt"
|
2017-10-18 06:27:06 +02:00
|
|
|
+ "io"
|
2017-03-08 10:03:15 +01:00
|
|
|
+ "io/ioutil"
|
|
|
|
+ "os"
|
|
|
|
+ "path/filepath"
|
2017-11-30 12:49:12 +01:00
|
|
|
+ "strings"
|
2017-03-08 10:03:15 +01:00
|
|
|
+ "syscall"
|
|
|
|
+
|
|
|
|
+ "github.com/docker/docker/container"
|
2017-10-18 06:27:06 +02:00
|
|
|
+ "github.com/docker/docker/pkg/archive"
|
2017-09-04 15:03:50 +02:00
|
|
|
+ "github.com/docker/docker/pkg/idtools"
|
2017-05-29 14:37:19 +02:00
|
|
|
+ "github.com/opencontainers/go-digest"
|
2017-12-19 04:42:51 +01:00
|
|
|
+ "github.com/sirupsen/logrus"
|
2017-03-08 10:03:15 +01:00
|
|
|
+
|
|
|
|
+ swarmtypes "github.com/docker/docker/api/types/swarm"
|
|
|
|
+ swarmexec "github.com/docker/swarmkit/agent/exec"
|
|
|
|
+ swarmapi "github.com/docker/swarmkit/api"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+func init() {
|
|
|
|
+ // Output to tell us in logs that SUSE:secrets is enabled.
|
|
|
|
+ logrus.Infof("SUSE:secrets :: enabled")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Creating a fake file.
|
|
|
|
+type SuseFakeFile struct {
|
|
|
|
+ Path string
|
|
|
|
+ Uid int
|
|
|
|
+ Gid int
|
|
|
|
+ Mode os.FileMode
|
|
|
|
+ Data []byte
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s SuseFakeFile) id() string {
|
2017-11-10 08:15:19 +01:00
|
|
|
+ // NOTE: It is _very_ important that this string always has a prefix of
|
|
|
|
+ // "suse". This is how we can ensure that we can operate on
|
|
|
|
+ // SecretReferences with a confidence that it was made by us.
|
2017-10-18 06:27:06 +02:00
|
|
|
+ return fmt.Sprintf("suse_%s_%s", digest.FromBytes(s.Data).Hex(), s.Path)
|
2017-03-08 10:03:15 +01:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s SuseFakeFile) toSecret() *swarmapi.Secret {
|
|
|
|
+ return &swarmapi.Secret{
|
|
|
|
+ ID: s.id(),
|
|
|
|
+ Internal: true,
|
|
|
|
+ Spec: swarmapi.SecretSpec{
|
|
|
|
+ Data: s.Data,
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
2018-12-04 05:34:12 +01:00
|
|
|
+func (s SuseFakeFile) toSecretReference(idMaps *idtools.IdentityMapping) *swarmtypes.SecretReference {
|
2017-09-04 15:03:50 +02:00
|
|
|
+ // Figure out the host-facing {uid,gid} based on the provided maps. Fall
|
|
|
|
+ // back to root if the UID/GID don't match (we are guaranteed that root is
|
|
|
|
+ // mapped).
|
2018-12-04 05:34:12 +01:00
|
|
|
+ ctrUser := idtools.Identity{UID: s.Uid, GID: s.Gid}
|
2017-10-18 06:27:06 +02:00
|
|
|
+ hostUser := idMaps.RootPair()
|
2017-11-10 08:15:19 +01:00
|
|
|
+ if user, err := idMaps.ToHost(ctrUser); err == nil {
|
2017-10-18 06:27:06 +02:00
|
|
|
+ hostUser = user
|
2017-09-04 15:03:50 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Return the secret reference as a file target.
|
2017-03-08 10:03:15 +01:00
|
|
|
+ return &swarmtypes.SecretReference{
|
|
|
|
+ SecretID: s.id(),
|
|
|
|
+ SecretName: s.id(),
|
|
|
|
+ File: &swarmtypes.SecretReferenceFileTarget{
|
|
|
|
+ Name: s.Path,
|
2017-10-18 06:27:06 +02:00
|
|
|
+ UID: fmt.Sprintf("%d", hostUser.UID),
|
|
|
|
+ GID: fmt.Sprintf("%d", hostUser.GID),
|
2017-03-08 10:03:15 +01:00
|
|
|
+ Mode: s.Mode,
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
2017-10-18 06:27:06 +02:00
|
|
|
+// readDir will recurse into a directory prefix/dir, and return the set of
|
|
|
|
+// secrets in that directory (as a tar archive that is packed inside the "data"
|
|
|
|
+// field). The Path attribute of each has the prefix stripped. Symlinks are
|
|
|
|
+// dereferenced.
|
2017-03-08 10:03:15 +01:00
|
|
|
+func readDir(prefix, dir string) ([]*SuseFakeFile, error) {
|
|
|
|
+ var suseFiles []*SuseFakeFile
|
|
|
|
+
|
|
|
|
+ path := filepath.Join(prefix, dir)
|
|
|
|
+ fi, err := os.Stat(path)
|
|
|
|
+ if err != nil {
|
|
|
|
+ // Ignore dangling symlinks.
|
|
|
|
+ if os.IsNotExist(err) {
|
|
|
|
+ logrus.Warnf("SUSE:secrets :: dangling symlink: %s", path)
|
2017-10-18 06:27:06 +02:00
|
|
|
+ return nil, nil
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
|
|
|
+ return nil, err
|
2017-10-18 06:27:06 +02:00
|
|
|
+ } else if !fi.IsDir() {
|
|
|
|
+ // Just to be safe.
|
|
|
|
+ logrus.Warnf("SUSE:secrets :: expected %q to be a directory, but was a file", path)
|
|
|
|
+ return readFile(prefix, dir)
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
2017-10-18 06:27:06 +02:00
|
|
|
+ path, err = filepath.EvalSymlinks(path)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
|
|
|
+
|
2017-10-18 06:27:06 +02:00
|
|
|
+ // Construct a tar archive of the source directory. We tar up the prefix
|
|
|
|
+ // directory and add dir as an IncludeFiles specifically so that we
|
|
|
|
+ // preserve the name of the directory itself.
|
|
|
|
+ tarStream, err := archive.TarWithOptions(path, &archive.TarOptions{
|
|
|
|
+ Compression: archive.Uncompressed,
|
|
|
|
+ IncludeSourceDir: true,
|
2017-03-08 10:03:15 +01:00
|
|
|
+ })
|
|
|
|
+ if err != nil {
|
2017-10-18 06:27:06 +02:00
|
|
|
+ return nil, fmt.Errorf("SUSE:secrets :: failed to tar source directory %q: %v", path, err)
|
|
|
|
+ }
|
|
|
|
+ tarStreamBytes, err := ioutil.ReadAll(tarStream)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, fmt.Errorf("SUSE:secrets :: failed to read full tar archive: %v", err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Get a list of the symlinks in the tar archive.
|
|
|
|
+ var symlinks []string
|
|
|
|
+ tmpTr := tar.NewReader(bytes.NewBuffer(tarStreamBytes))
|
|
|
|
+ for {
|
|
|
|
+ hdr, err := tmpTr.Next()
|
|
|
|
+ if err == io.EOF {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, fmt.Errorf("SUSE:secrets :: failed to read through tar reader: %v", err)
|
|
|
|
+ }
|
|
|
|
+ if hdr.Typeflag == tar.TypeSymlink {
|
|
|
|
+ symlinks = append(symlinks, hdr.Name)
|
|
|
|
+ }
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
|
|
|
+
|
2017-10-18 06:27:06 +02:00
|
|
|
+ // Symlinks aren't dereferenced in the above archive, so we explicitly do a
|
|
|
|
+ // rewrite of the tar archive to include all symlinks to files. We cannot
|
|
|
|
+ // do directories here, but lower-level directory symlinks aren't supported
|
|
|
|
+ // by zypper so this isn't an issue.
|
|
|
|
+ symlinkModifyMap := map[string]archive.TarModifierFunc{}
|
|
|
|
+ for _, sym := range symlinks {
|
|
|
|
+ logrus.Debugf("SUSE:secrets: archive(%q) %q is a need-to-rewrite symlink", path, sym)
|
|
|
|
+ symlinkModifyMap[sym] = func(tarPath string, hdr *tar.Header, r io.Reader) (*tar.Header, []byte, error) {
|
|
|
|
+ logrus.Debugf("SUSE:secrets: archive(%q) mapping for symlink %q", path, tarPath)
|
|
|
|
+ tarFullPath := filepath.Join(path, tarPath)
|
|
|
|
+
|
|
|
|
+ // Get a copy of the original byte stream.
|
|
|
|
+ oldContent, err := ioutil.ReadAll(r)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, nil, fmt.Errorf("suse_rewrite: failed to read archive entry %q: %v", tarPath, err)
|
|
|
|
+ }
|
2017-03-08 10:03:15 +01:00
|
|
|
+
|
2017-10-18 06:27:06 +02:00
|
|
|
+ // Check that the file actually exists.
|
|
|
|
+ fi, err := os.Stat(tarFullPath)
|
2017-03-08 10:03:15 +01:00
|
|
|
+ if err != nil {
|
2017-10-18 06:27:06 +02:00
|
|
|
+ logrus.Warnf("suse_rewrite: failed to stat archive entry %q: %v", tarFullPath, err)
|
|
|
|
+ return hdr, oldContent, nil
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
2017-10-18 06:27:06 +02:00
|
|
|
+
|
|
|
|
+ // Read the actual contents.
|
|
|
|
+ content, err := ioutil.ReadFile(tarFullPath)
|
2017-03-08 10:03:15 +01:00
|
|
|
+ if err != nil {
|
2017-10-18 06:27:06 +02:00
|
|
|
+ logrus.Warnf("suse_rewrite: failed to read %q: %v", tarFullPath, err)
|
|
|
|
+ return hdr, oldContent, nil
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
2017-10-18 06:27:06 +02:00
|
|
|
+
|
|
|
|
+ newHdr, err := tar.FileInfoHeader(fi, "")
|
|
|
|
+ if err != nil {
|
|
|
|
+ // Fake the header.
|
|
|
|
+ newHdr = &tar.Header{
|
|
|
|
+ Typeflag: tar.TypeReg,
|
|
|
|
+ Mode: 0644,
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Update the key fields.
|
|
|
|
+ hdr.Typeflag = newHdr.Typeflag
|
|
|
|
+ hdr.Mode = newHdr.Mode
|
|
|
|
+ hdr.Linkname = ""
|
|
|
|
+ return hdr, content, nil
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
2017-10-18 06:27:06 +02:00
|
|
|
+ // Create the rewritten tar stream.
|
|
|
|
+ tarStream = archive.ReplaceFileTarWrapper(ioutil.NopCloser(bytes.NewBuffer(tarStreamBytes)), symlinkModifyMap)
|
|
|
|
+ tarStreamBytes, err = ioutil.ReadAll(tarStream)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, fmt.Errorf("SUSE:secrets :: failed to read rewritten archive: %v", err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Add the tar stream as a "file".
|
|
|
|
+ suseFiles = append(suseFiles, &SuseFakeFile{
|
|
|
|
+ Path: dir,
|
|
|
|
+ Mode: fi.Mode(),
|
|
|
|
+ Data: tarStreamBytes,
|
|
|
|
+ })
|
2017-03-08 10:03:15 +01:00
|
|
|
+ return suseFiles, nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// readFile returns a secret given a file under a given prefix.
|
|
|
|
+func readFile(prefix, file string) ([]*SuseFakeFile, error) {
|
|
|
|
+ path := filepath.Join(prefix, file)
|
|
|
|
+ fi, err := os.Stat(path)
|
|
|
|
+ if err != nil {
|
|
|
|
+ // Ignore dangling symlinks.
|
|
|
|
+ if os.IsNotExist(err) {
|
|
|
|
+ logrus.Warnf("SUSE:secrets :: dangling symlink: %s", path)
|
2017-10-18 06:27:06 +02:00
|
|
|
+ return nil, nil
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
|
|
|
+ return nil, err
|
2017-10-18 06:27:06 +02:00
|
|
|
+ } else if fi.IsDir() {
|
|
|
|
+ // Just to be safe.
|
|
|
|
+ logrus.Warnf("SUSE:secrets :: expected %q to be a file, but was a directory", path)
|
|
|
|
+ return readDir(prefix, file)
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ stat, ok := fi.Sys().(*syscall.Stat_t)
|
|
|
|
+ if !ok {
|
|
|
|
+ logrus.Warnf("SUSE:secrets :: failed to cast file stat_t: defaulting to owned by root:root: %s", path)
|
|
|
|
+ }
|
|
|
|
+
|
2017-10-18 06:27:06 +02:00
|
|
|
+ bytes, err := ioutil.ReadFile(path)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
|
|
|
+
|
2017-10-18 06:27:06 +02:00
|
|
|
+ var suseFiles []*SuseFakeFile
|
|
|
|
+ suseFiles = append(suseFiles, &SuseFakeFile{
|
|
|
|
+ Path: file,
|
|
|
|
+ Uid: int(stat.Uid),
|
|
|
|
+ Gid: int(stat.Gid),
|
|
|
|
+ Mode: fi.Mode(),
|
|
|
|
+ Data: bytes,
|
|
|
|
+ })
|
2017-03-08 10:03:15 +01:00
|
|
|
+ return suseFiles, nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// getHostSuseSecretData returns the list of SuseFakeFiles the need to be added
|
|
|
|
+// as SUSE secrets.
|
|
|
|
+func getHostSuseSecretData() ([]*SuseFakeFile, error) {
|
|
|
|
+ secrets := []*SuseFakeFile{}
|
|
|
|
+
|
|
|
|
+ credentials, err := readDir("/etc/zypp", "credentials.d")
|
|
|
|
+ if err != nil {
|
|
|
|
+ if os.IsNotExist(err) {
|
|
|
|
+ credentials = []*SuseFakeFile{}
|
|
|
|
+ } else {
|
|
|
|
+ logrus.Errorf("SUSE:secrets :: error while reading zypp credentials: %s", err)
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ secrets = append(secrets, credentials...)
|
|
|
|
+
|
|
|
|
+ suseConnect, err := readFile("/etc", "SUSEConnect")
|
|
|
|
+ if err != nil {
|
|
|
|
+ if os.IsNotExist(err) {
|
|
|
|
+ suseConnect = []*SuseFakeFile{}
|
|
|
|
+ } else {
|
|
|
|
+ logrus.Errorf("SUSE:secrets :: error while reading /etc/SUSEConnect: %s", err)
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ secrets = append(secrets, suseConnect...)
|
|
|
|
+
|
|
|
|
+ return secrets, nil
|
|
|
|
+}
|
|
|
|
+
|
2017-11-30 12:49:12 +01:00
|
|
|
+// To fake an empty store, in the case where we are operating on a container
|
|
|
|
+// that was created pre-swarmkit. Otherwise segfaults and other fun things
|
|
|
|
+// happen. See bsc#1057743.
|
|
|
|
+type (
|
|
|
|
+ suseEmptyStore struct{}
|
|
|
|
+ suseEmptySecret struct{}
|
|
|
|
+ suseEmptyConfig struct{}
|
|
|
|
+)
|
|
|
|
+
|
2017-03-08 10:03:15 +01:00
|
|
|
+// In order to reduce the amount of code touched outside of this file, we
|
2017-10-18 06:27:06 +02:00
|
|
|
+// implement the swarm API for DependencyGetter. This asserts that this
|
2017-11-30 12:49:12 +01:00
|
|
|
+// requirement will always be matched. In addition, for the case of the *empty*
|
|
|
|
+// getters this reduces memory usage by having a global instance.
|
|
|
|
+var (
|
|
|
|
+ _ swarmexec.DependencyGetter = &suseDependencyStore{}
|
|
|
|
+ emptyStore swarmexec.DependencyGetter = suseEmptyStore{}
|
|
|
|
+ emptySecret swarmexec.SecretGetter = suseEmptySecret{}
|
|
|
|
+ emptyConfig swarmexec.ConfigGetter = suseEmptyConfig{}
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+var errSuseEmptyStore = fmt.Errorf("SUSE:secrets :: tried to get a resource from empty store [this is a bug]")
|
|
|
|
+
|
|
|
|
+func (_ suseEmptyConfig) Get(_ string) (*swarmapi.Config, error) { return nil, errSuseEmptyStore }
|
|
|
|
+func (_ suseEmptySecret) Get(_ string) (*swarmapi.Secret, error) { return nil, errSuseEmptyStore }
|
|
|
|
+func (_ suseEmptyStore) Secrets() swarmexec.SecretGetter { return emptySecret }
|
|
|
|
+func (_ suseEmptyStore) Configs() swarmexec.ConfigGetter { return emptyConfig }
|
2017-03-08 10:03:15 +01:00
|
|
|
+
|
2017-10-18 06:27:06 +02:00
|
|
|
+type suseDependencyStore struct {
|
|
|
|
+ dfl swarmexec.DependencyGetter
|
2017-03-08 10:03:15 +01:00
|
|
|
+ secrets map[string]*swarmapi.Secret
|
|
|
|
+}
|
|
|
|
+
|
2017-11-30 12:49:12 +01:00
|
|
|
+// The following are effectively dumb wrappers that return ourselves, or the
|
|
|
|
+// default.
|
2017-10-18 06:27:06 +02:00
|
|
|
+func (s *suseDependencyStore) Secrets() swarmexec.SecretGetter { return s }
|
|
|
|
+func (s *suseDependencyStore) Configs() swarmexec.ConfigGetter { return s.dfl.Configs() }
|
|
|
|
+
|
|
|
|
+// Get overrides the underlying DependencyGetter with our own secrets (falling
|
|
|
|
+// through to the underlying DependencyGetter if the secret isn't present).
|
|
|
|
+func (s *suseDependencyStore) Get(id string) (*swarmapi.Secret, error) {
|
|
|
|
+ logrus.Debugf("SUSE:secrets :: id=%s requested from suseDependencyGetter", id)
|
2017-03-08 10:03:15 +01:00
|
|
|
+
|
|
|
|
+ secret, ok := s.secrets[id]
|
|
|
|
+ if !ok {
|
|
|
|
+ // fallthrough
|
2017-10-18 06:27:06 +02:00
|
|
|
+ return s.dfl.Secrets().Get(id)
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
2017-10-18 06:27:06 +02:00
|
|
|
+ return secret, nil
|
2017-03-08 10:03:15 +01:00
|
|
|
+}
|
|
|
|
+
|
2017-11-30 12:49:12 +01:00
|
|
|
+// removeSuseSecrets removes any SecretReferences which were added by us
|
|
|
|
+// explicitly (this is detected by checking that the prefix has a 'suse'
|
|
|
|
+// prefix). See bsc#1057743.
|
|
|
|
+func removeSuseSecrets(c *container.Container) {
|
|
|
|
+ var without []*swarmtypes.SecretReference
|
|
|
|
+ for _, secret := range c.SecretReferences {
|
|
|
|
+ if strings.HasPrefix(secret.SecretID, "suse") {
|
|
|
|
+ logrus.Warnf("SUSE:secrets :: removing 'old' suse secret %q from container %q", secret.SecretID, c.ID)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ without = append(without, secret)
|
|
|
|
+ }
|
|
|
|
+ c.SecretReferences = without
|
|
|
|
+}
|
|
|
|
+
|
2017-03-08 10:03:15 +01:00
|
|
|
+func (daemon *Daemon) injectSuseSecretStore(c *container.Container) error {
|
2017-10-18 06:27:06 +02:00
|
|
|
+ newDependencyStore := &suseDependencyStore{
|
|
|
|
+ dfl: c.DependencyStore,
|
2017-03-08 10:03:15 +01:00
|
|
|
+ secrets: make(map[string]*swarmapi.Secret),
|
|
|
|
+ }
|
2017-11-30 12:49:12 +01:00
|
|
|
+ // Handle old containers. See bsc#1057743.
|
|
|
|
+ if newDependencyStore.dfl == nil {
|
|
|
|
+ newDependencyStore.dfl = emptyStore
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // We drop any "old" SUSE secrets, as it appears that old containers (when
|
|
|
|
+ // restarted) could still have references to old secrets. The .id() of all
|
|
|
|
+ // secrets have a prefix of "suse" so this is much easier. See bsc#1057743
|
|
|
|
+ // for details on why this could cause issues.
|
|
|
|
+ removeSuseSecrets(c)
|
2017-03-08 10:03:15 +01:00
|
|
|
+
|
|
|
|
+ secrets, err := getHostSuseSecretData()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
2018-12-04 05:34:12 +01:00
|
|
|
+ idMaps := daemon.idMapping
|
2017-03-08 10:03:15 +01:00
|
|
|
+ for _, secret := range secrets {
|
2017-10-18 06:27:06 +02:00
|
|
|
+ newDependencyStore.secrets[secret.id()] = secret.toSecret()
|
|
|
|
+ c.SecretReferences = append(c.SecretReferences, secret.toSecretReference(idMaps))
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
|
|
|
+
|
2017-10-18 06:27:06 +02:00
|
|
|
+ c.DependencyStore = newDependencyStore
|
2017-11-30 12:49:12 +01:00
|
|
|
+
|
|
|
|
+ // bsc#1057743 -- In older versions of Docker we added volumes explicitly
|
|
|
|
+ // to the mount list. This causes clashes because of duplicate namespaces.
|
|
|
|
+ // If we see an existing mount that will clash with the in-built secrets
|
|
|
|
+ // mount we assume it's our fault.
|
2018-08-15 09:09:12 +02:00
|
|
|
+ intendedMounts, err := c.SecretMounts()
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.Warnf("SUSE:secrets :: fetching old secret mounts: %v", err)
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ for _, intendedMount := range intendedMounts {
|
2017-11-30 12:49:12 +01:00
|
|
|
+ mountPath := intendedMount.Destination
|
|
|
|
+ if volume, ok := c.MountPoints[mountPath]; ok {
|
|
|
|
+ logrus.Debugf("SUSE:secrets :: removing pre-existing %q mount: %#v", mountPath, volume)
|
|
|
|
+ delete(c.MountPoints, mountPath)
|
|
|
|
+ }
|
|
|
|
+ }
|
2017-03-08 10:03:15 +01:00
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
--
|
2018-12-04 05:34:12 +01:00
|
|
|
2.19.2
|
2017-03-08 10:03:15 +01:00
|
|
|
|