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

If OXIDE_HOST is not set, we choose a random host from the user's config #301

Closed
jgallagher opened this issue Jul 20, 2023 · 12 comments
Closed
Assignees
Labels
known issue To include in customer documentation and training
Milestone

Comments

@jgallagher
Copy link
Contributor

In

(Err(_), Ok(token)) => {
let Some((host, _)) = config.hosts.hosts.iter().next() else {
return Ok(None);
};
(host.clone(), token)
}
(Err(_), Err(_)) => {
let Some((host, host_entry)) = config.hosts.hosts.iter().next() else {
return Ok(None);
};
(host.clone(), host_entry.token.clone())
}
, if OXIDE_HOST is not set, we choose a host by taking the "next" house out of a hashmap, which results in effectively a random host being chosen on each invocation (if the user has multiple host entries). This can create confusing results where the same command may succeed in one invocation and fail in the next, if the command was intended to be used with one of the specific hosts.

@jgallagher
Copy link
Contributor Author

Closing as a dup of #302.

@karencfv
Copy link
Contributor

Related: #6

@ahl
Copy link
Collaborator

ahl commented Jul 21, 2023

Agreed that this behavior is lousy. What do we want to do here? I don't love $OXIDE_HOST as a primary interface

@karencfv
Copy link
Contributor

Having the environment variables take precedence over the config file is not uncommon (AWS CLI does this as well).

It would be nice to be able to set a host as default though. My thinking is that having profiles (#6) is the best way to go long term, but perhaps not something that can just be whipped up and shipped quickly. Perhaps having the user have to choose a host from the list through a flag if they are logged in to more than one silo can be a start?

$ oxide some-command
Error: You are logged in to more than one host. Use the --host flag to select a host from your config file.

$ oxide some-command --host <host>
success

@ahl
Copy link
Collaborator

ahl commented Jul 21, 2023

Having the environment variables take precedence over the config file is not uncommon (AWS CLI does this as well).

Yes! I'm just saying that it's lousy as the primary mechanism.

@askfongjojo
Copy link

Bumping this since our own folks run into this a lot and we can expect fleet admin who operates in a multi-tenant environment may hit the issue as well.
Note: We didn't think this was high priority previously because the most likely situation for this to happen was during initial setup - when the fleet admin has to make CLI requests against the recovery silo and then the one user silo they would create and keep using. At this time, we simply tell the user to set environment variables or manually edit the hosts.toml file to get rid of the recovery silo entry.

There are some suggestions on the desired behavior:

  1. Error out - inform user that the endpoint/token setting is ambiguous, and that they can either set the environment variables or remove entries from the toml. (For the latter, we can provide a new CLI command to manage host entries so they don't mess up the config file due to typos.)
  2. Prompt user to pass a --host parameter if there are multiple hosts in the toml file, as Karen already mentioned above. It may become annoying enough that user will eventually do one of the two things mentioned in 1.
  3. Support the setting of a default host entry, e.g. by including a flag in each of the toml entries to keep track of the default.
  4. Implement support named "profiles" #6.

@david-crespo
Copy link
Contributor

Erroring out in case of ambiguity is something we could do immediately while deciding between fancier solutions.

@askfongjojo askfongjojo added the known issue To include in customer documentation and training label Mar 9, 2024
@askfongjojo
Copy link

We have a customer who will be using multiple silos to partition dev and prod workloads. The change will likely cause many end-users to have multiple silo endpoint/tokens in their host config file. This CLI issue is going to be hit a lot more frequently (right now, it affects just the fleet admin user so we've been prioritizing it low).

@ahl - We need to bump up the priority of resolving this issue somehow.

@ahl
Copy link
Collaborator

ahl commented Mar 16, 2024

Confirmed; I have a plan that I'll prototype ASAP for feedback.

@morlandi7 morlandi7 modified the milestones: 7, 8 Apr 25, 2024
@david-crespo david-crespo modified the milestones: 8, 9 May 10, 2024
@augustuswm
Copy link
Contributor

Independent of the any end user configuration I think we could resolve the non-determinism by using a BTreeMap instead of HashMap when defining the Hosts struct. This would at least ensure that consecutive calls to the cli target the same host. Any reason not to make this change:

pub struct Hosts {
#[serde(flatten)]
pub hosts: HashMap<String, Host>,
}

@david-crespo
Copy link
Contributor

Only reason not to is if @ahl is planning on fixing this in the next few days anyway.

@ahl
Copy link
Collaborator

ahl commented Jul 17, 2024

I believe this is addressed by #727. Please open a new issue if that's not the case.

@ahl ahl closed this as completed Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
known issue To include in customer documentation and training
Projects
None yet
Development

No branches or pull requests

8 participants