2024-04-24 23:20:41 +02:00
|
|
|
From 2b0fd7dedddd24c2e5d3e177d3b339eca5ac71fd 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 12:41:54 +1100
|
2024-02-20 09:51:39 +01:00
|
|
|
Subject: [PATCH 1/5] SECRETS: daemon: allow directory creation in /run/secrets
|
2017-03-08 10:03:15 +01:00
|
|
|
|
|
|
|
Since FileMode can have the directory bit set, allow a SecretStore
|
|
|
|
implementation to return secrets that are actually directories. This is
|
|
|
|
useful for creating directories and subdirectories of secrets.
|
|
|
|
|
2017-05-29 14:37:19 +02:00
|
|
|
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
|
2017-03-08 10:03:15 +01:00
|
|
|
Signed-off-by: Aleksa Sarai <asarai@suse.de>
|
|
|
|
---
|
2023-04-26 08:31:24 +02:00
|
|
|
daemon/container_operations_unix.go | 23 ++++++++++++++++++++---
|
|
|
|
1 file changed, 20 insertions(+), 3 deletions(-)
|
2017-03-08 10:03:15 +01:00
|
|
|
|
2021-01-30 02:14:10 +01:00
|
|
|
diff --git a/daemon/container_operations_unix.go b/daemon/container_operations_unix.go
|
2024-04-24 23:20:41 +02:00
|
|
|
index 4dedc1b21c87..b7c310493e79 100644
|
2021-01-30 02:14:10 +01:00
|
|
|
--- a/daemon/container_operations_unix.go
|
|
|
|
+++ b/daemon/container_operations_unix.go
|
2024-02-20 09:51:39 +01:00
|
|
|
@@ -3,6 +3,7 @@
|
2018-08-15 09:09:12 +02:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2017-04-11 14:13:39 +02:00
|
|
|
|
2017-10-18 06:27:06 +02:00
|
|
|
import (
|
|
|
|
+ "bytes"
|
2024-02-20 09:51:39 +01:00
|
|
|
"context"
|
2017-10-18 06:27:06 +02:00
|
|
|
"fmt"
|
2021-11-19 01:09:22 +01:00
|
|
|
"os"
|
2024-02-20 09:51:39 +01:00
|
|
|
@@ -16,6 +17,7 @@ import (
|
2017-10-18 06:27:06 +02:00
|
|
|
"github.com/docker/docker/daemon/links"
|
2018-08-15 09:09:12 +02:00
|
|
|
"github.com/docker/docker/errdefs"
|
2023-04-26 08:31:24 +02:00
|
|
|
"github.com/docker/docker/libnetwork"
|
2017-10-18 06:27:06 +02:00
|
|
|
+ "github.com/docker/docker/pkg/archive"
|
|
|
|
"github.com/docker/docker/pkg/idtools"
|
2023-06-15 22:02:17 +02:00
|
|
|
"github.com/docker/docker/pkg/process"
|
2017-10-18 06:27:06 +02:00
|
|
|
"github.com/docker/docker/pkg/stringid"
|
2024-04-24 23:20:41 +02:00
|
|
|
@@ -240,9 +242,6 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
2017-10-18 06:27:06 +02:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "unable to get secret from secret store")
|
2017-03-08 10:03:15 +01:00
|
|
|
}
|
2023-04-26 08:31:24 +02:00
|
|
|
- if err := os.WriteFile(fPath, secret.Spec.Data, s.File.Mode); err != nil {
|
2017-03-08 10:03:15 +01:00
|
|
|
- return errors.Wrap(err, "error injecting secret")
|
2017-05-29 14:37:19 +02:00
|
|
|
- }
|
|
|
|
|
|
|
|
uid, err := strconv.Atoi(s.File.UID)
|
|
|
|
if err != nil {
|
2024-04-24 23:20:41 +02:00
|
|
|
@@ -253,6 +252,24 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
2017-05-29 14:37:19 +02:00
|
|
|
return err
|
|
|
|
}
|
2017-10-18 06:27:06 +02:00
|
|
|
|
2017-03-08 10:03:15 +01:00
|
|
|
+ if s.File.Mode.IsDir() {
|
2017-10-18 06:27:06 +02:00
|
|
|
+ if err := os.Mkdir(fPath, s.File.Mode); err != nil {
|
|
|
|
+ return errors.Wrap(err, "error creating secretdir")
|
|
|
|
+ }
|
|
|
|
+ if secret.Spec.Data != nil {
|
|
|
|
+ // If the "file" is a directory, then s.File.Data is actually a tar
|
|
|
|
+ // archive of the directory. So we just do a tar extraction here.
|
|
|
|
+ if err := archive.UntarUncompressed(bytes.NewBuffer(secret.Spec.Data), fPath, &archive.TarOptions{
|
2023-04-26 08:31:24 +02:00
|
|
|
+ IDMap: daemon.idMapping,
|
2017-10-18 06:27:06 +02:00
|
|
|
+ }); err != nil {
|
|
|
|
+ return errors.Wrap(err, "error injecting secretdir")
|
|
|
|
+ }
|
2017-03-08 10:03:15 +01:00
|
|
|
+ }
|
|
|
|
+ } else {
|
2023-04-26 08:31:24 +02:00
|
|
|
+ if err := os.WriteFile(fPath, secret.Spec.Data, s.File.Mode); err != nil {
|
2017-03-08 10:03:15 +01:00
|
|
|
+ return errors.Wrap(err, "error injecting secret")
|
|
|
|
+ }
|
2017-05-29 14:37:19 +02:00
|
|
|
+ }
|
2017-10-18 06:27:06 +02:00
|
|
|
if err := os.Chown(fPath, rootIDs.UID+uid, rootIDs.GID+gid); err != nil {
|
2017-05-29 14:37:19 +02:00
|
|
|
return errors.Wrap(err, "error setting ownership for secret")
|
2017-03-08 10:03:15 +01:00
|
|
|
}
|
|
|
|
--
|
2024-04-24 23:20:41 +02:00
|
|
|
2.44.0
|
2017-03-08 10:03:15 +01:00
|
|
|
|