-
Notifications
You must be signed in to change notification settings - Fork 225
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
nixcache: configure auth with devbox cache configure
#1961
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`nix.DaemonVersion` attempts to connect to the Nix daemon and returns its version string. Devbox will use the error from this function when configuring cache authentication: - If the nix daemon is running, we need to update ~root/.aws/config so that it can authenticate with the private devbox cache. This requires a sudo prompt. - If it's not running, then it's probably a single-user install without a daemon. We won't need sudo.
The `devbox cache credentials` subcommand prints out short-lived AWS STS credentials that grant access to the user's Nix cache. The output follows the format described in `aws help config-vars` under `Sourcing Credentials From External Processes`. This allows the AWS CLI/SDKs to obtain credentials from Devbox. For example: [default] credential_process = /usr/local/bin/devbox cache credentials Because Nix uses the AWS SDK's default credential chain, this allows it to automatically authenticate with private Devbox caches. Note: this can be improved by using the newer credentials-only API endpoint, which is faster.
gcurtis
force-pushed
the
gcurtis/cache-auth
branch
from
April 8, 2024 15:55
f2c29c9
to
c82359b
Compare
Add a hidden `devbox cache configure` command that sets up Nix so it can authenticate with a private Devbox cache. This is a first step. Ultimately, we'd like to do this configuration automatically before building. We just need to make sure we don't re-prompt the user for sudo or slow down commands like `devbox run` or `devbox shell`. Configuring auth goes as follows: 1. Check to see if the Nix daemon is running. If it isn't, we don't need to do anything. 2. Otherwise, we check to see if `~root/.aws/config` exists. If it does, we assume that we've already configured the root user's AWS credentials. This won't handle situations where the user already has a root AWS config and can be improved. 3. If the AWS config doesn't exist, prompt the user to escalate to root. If they say yes, relaunch `devbox cache configure`. 4. The new devbox process running as root writes an AWS config file that tells the AWS CLI/SDKs to authenticate by running `devbox cache credentials`. Note that we need to use the default AWS profile. There's a bug in Nix where non-default profiles (specified in the S3 URI with ?profile=devbox) don't use the default credential chain. If this gets fixed, we should use a separate profile so that we don't interfere with any AWS options set by the user (although hopefully this is rare for root).
gcurtis
force-pushed
the
gcurtis/cache-auth
branch
from
April 8, 2024 15:59
c82359b
to
70886b0
Compare
mikeland73
approved these changes
Apr 8, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For followup:
- We should save the configure state to a place that the user can access so devbox can remember if it's already been configured. Specifically, for a non-root user in a multi user install, the cache wont work at all if they haven't configured. Since we don't want to ask for sudo every time, saving some state to non a non root location (maybe XDG config) so that we can warn the user they need to configure if they have not previously done so.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Depends on #1959 and #1960. The diff contains commits from those PRs.
Add a hidden
devbox cache configure
command that sets up Nix so it can authenticate with a private Devbox cache. This is a first step. Ultimately, we'd like to do this configuration automatically before building. We just need to make sure we don't re-prompt the user for sudo or slow down commands likedevbox run
ordevbox shell
.Configuring auth goes as follows:
~root/.aws/config
exists. If it does, we assume that we've already configured the root user's AWS credentials. This won't handle situations where the user already has a root AWS config and can be improved.devbox cache configure
.devbox cache credentials
.Note that we need to use the default AWS profile. There's a bug in Nix where non-default profiles (specified in the S3 URI with ?profile=devbox) don't use the default credential chain. If this gets fixed, we should use a separate profile so that we don't interfere with any AWS options set by the user (although hopefully this is rare for root).