auth: fetch tokens from client side#1660
Conversation
| ts.mu.Lock() | ||
| defer ts.mu.Unlock() | ||
|
|
||
| fp := filepath.Join(ts.dir, ".token_seed") |
There was a problem hiding this comment.
Was hoping to avoid this but couldn't think of a better solution. Afaics if we don't do something like this we always have a possibility for a chosen-plaintext attack from the daemon side. Another possible way would be to use pbkdf/scrypt for the verification but didn't want to take the 100ms+ performance hit for this and waste cpu.
There was a problem hiding this comment.
Worth leaving a comment that describes this?
259df14 to
fa6ce06
Compare
| "golang.org/x/sync/errgroup" | ||
| ) | ||
|
|
||
| type MultiWriter struct { |
There was a problem hiding this comment.
These new progress handling functions are copied from buildx with slight modification. Buildx versions will be removed on next vendor.
fa6ce06 to
715fe26
Compare
| return nil, err | ||
| } | ||
|
|
||
| if err := os.MkdirAll(filepath.Dir(fp), 0701); err != nil { |
There was a problem hiding this comment.
Just double checking, we want anyone to have access to paths inside the dir, but not be able to list the dir? Or is this supposed to be 0700?
There was a problem hiding this comment.
On my machine it is 0755 actually, but cli does not seem to be consistent. The search bit should be set though as not all things in .docker are secret. Eg. it may contain plugins that need to be executable.
FYI @thaJeztah
There was a problem hiding this comment.
In most cases, this would be inside the user's home-directory, which would likely not be accessible to the "world" already, correct? 😅
but cli does not seem to be consistent
Can you elaborate what's not consistent? Something that needs to be fixed?
There was a problem hiding this comment.
eg. https://github.com/docker/cli/blob/master/cli/context/store/metadatastore.go#L31
https://github.com/docker/cli/blob/master/cli/config/configfile/file.go#L187
There's at least one example for both cases
There was a problem hiding this comment.
Opened docker/cli#2727 for tracking on the CLI side.
Would 0755 be problematic if a custom config-directory is specified through --config (potentially outside of ~/ ?
There was a problem hiding this comment.
Not really problematic as the file itself is 0600 and this is just the parent directory. But if you want to be more safe I can put it back to 0700. In 99% of the cases the directory already exists and all this will be ignored.
| return nil, err | ||
| } | ||
|
|
||
| if err := ioutil.WriteFile(fp, dt, 0600); err != nil { |
There was a problem hiding this comment.
WriteFile opens the file w/ O_TRUNC, so if the daemon crashed at the exact wrong time, I think this file could end up existing but be empty, which would cause the json.Unmarshal above to always return an error. Obviously pretty obscure, but if that happened the only recourse would be for the user to manually delete the file.
Maybe if the json unmarshal fails you can just assume the file is empty and start anew?
There was a problem hiding this comment.
Would you prefer a file lock?
There was a problem hiding this comment.
Sure lock would work, or you could write to a new temp file opened w/ O_EXCL and rename(2) it to the final one once done, whichever is easiest
715fe26 to
08b152a
Compare
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
08b152a to
1f94445
Compare
|
This change broke configurations in Kubernetes like this one: It's a common practise that credentials are mount to this directory with Kube secrets. |
|
Hmm... I guess it's a bit of an odd situation where the temp-dir is read-only; is that common? (are temp-dirs always expected to be writable?) ^^ @tonistiigi looks because of https://github.com/moby/buildkit/pull/1660/files#r479909291 Are there paths that are required to be writable? |
Instead of sharing credentials with the daemon use session to request temporary tokens requested from the cli side. The tokens are still reused with resolvers like before and efficiency shouldn't suffer. @sipsma
Marking wip to add client-side progress injection making token requests visible. This turned out to be more complicated and I'm moving code from buildx to buildkit to achieve it.Signed-off-by: Tonis Tiigi tonistiigi@gmail.com