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

auth: fetch tokens from client side #1660

Merged
merged 1 commit into from
Oct 12, 2020
Merged

Conversation

tonistiigi
Copy link
Member

@tonistiigi tonistiigi commented Aug 31, 2020

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

ts.mu.Lock()
defer ts.mu.Unlock()

fp := filepath.Join(ts.dir, ".token_seed")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth leaving a comment that describes this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tonistiigi tonistiigi marked this pull request as ready for review September 3, 2020 06:12
"golang.org/x/sync/errgroup"
)

type MultiWriter struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new progress handling functions are copied from buildx with slight modification. Buildx versions will be removed on next vendor.

return nil, err
}

if err := os.MkdirAll(filepath.Dir(fp), 0701); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

@tonistiigi tonistiigi Sep 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to 0755

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ~/ ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer a file lock?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added file lock

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
@tonistiigi tonistiigi merged commit 4177e7c into moby:master Oct 12, 2020
@mkasprzyk
Copy link

mkasprzyk commented Oct 13, 2020

This change broke configurations in Kubernetes like this one:

  containers:
  - name: buildkit
    image: moby/buildkit:master-rootless
    env:
      - name: BUILDKITD_FLAGS
        value: --oci-worker-no-process-sandbox
      - name: DOCKER_CONFIG
        value: /tmp/.docker
    tty: true
    command:
    - cat
    volumeMounts:
      - name: jenkins-docker
        mountPath: /tmp/.docker

It's a common practise that credentials are mount to this directory with Kube secrets.

ERROR: rpc error: code = Unknown desc = open /tmp/.docker/.token_seed.lock: read-only file system

@thaJeztah
Copy link
Member

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? XDG_CACHE_HOME, XDG_RUNTIME_DIR or one of the other XDG dirs (or their equivalent)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants