Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@williamhpark
Copy link
Contributor

@williamhpark williamhpark commented Feb 13, 2023

Summary

Build a new shell plugin for the IBM Cloud CLI.

Addresses: #163

Testing

Setup

  1. Create an IBM Cloud account here.
  2. Install the IBM Cloud CLI following these instructions.
  3. Build and test the IBM Cloud plugin locally according to these instructions, i.e. make ibmcloud/build.

Importer

  1. Go to https://cloud.ibm.com/iam/apikeys, create a new API key, and copy/download it.
  2. Initialize the IBM Cloud plugin and import credentials by entering the API key manually in the terminal. The credentials should be saved in 1Password successfully.

Provisioner

  1. After initializing the IBM Cloud plugin and having your credential saved in 1Password, run ibmcloud login. You should be automatically authenticated with the API key stored in 1Password.
  2. Run ibmcloud login with each of the below flags (descriptions can be found here). You should not be prompted to authenticate through the 1Password CLI. The use cases for the flags are described below as well. Most of the flags would be passed if the user wants to authenticate using a method besides an API key, in which case we want to let the user authenticate manually to avoid confusion and potential conflict between credentials.

Wants to authenticate with username (email)/password:

-u
-p

Wants to potentially authenticate with an API key that's different from the one saved in 1Password:

--apikey

Wants to authenticate with a compute resource token or as a VPC VSI compute resource identity:

--cr-token
--vpc-cri
--profile

Wants to authenticate with a one-time passcode:

--sso

Wants to authenticate to a specific account or no account. Since an API key is linked to a specific account, both cases should only work if the user provides their authentication credentials manually, or else there could be conflicts:

-c
--no-account

Wants help or version information:

--help
--version
  1. Run just ibmcloud with no arguments. You should not be prompted to authenticate through the 1Password CLI.

@williamhpark williamhpark marked this pull request as draft February 13, 2023 19:38
@williamhpark williamhpark changed the title Draft: New plugin: IBM Cloud CLI New plugin: IBM Cloud CLI Feb 13, 2023
@williamhpark
Copy link
Contributor Author

williamhpark commented Feb 14, 2023

Currently, there are a few things I'm unsure about with regards to my implementation.

  1. IBM Cloud does create a configuration file at ~/.bluemix/config.json when the CLI is set up, however, from what I know there's no mechanism through which API keys are ever automatically saved to this config file through the IBM CLI. I wrote a file importer so that if a user were to manually enter their API key in ~/.bluemix/config.json with APIKey as the key, it could be imported into 1Password. However, if this is too much of a stretch I could remove the file importer altogether.
  2. With the current implementation, in order to authenticate you need to run ibmcloud login. If you were to run ibmcloud account list before authenticating with ibmcloud login first, for example, the command would fail. If the user isn't authenticated and they run a command besides ibmcloud login, do we want to run ibmcloud login under the hood first so that the command doesn't fail? If this is the desired behaviour, could I get some guidance on how to implement this?

@williamhpark williamhpark marked this pull request as ready for review February 14, 2023 01:04
@SimonBarendse
Copy link
Member

IBM Cloud does create a configuration file at ~/.bluemix/config.json when the CLI is set up, however, from what I know there's no mechanism through which API keys are ever automatically saved to this config file through the IBM CLI. I wrote a file importer so that if a user were to manually enter their API key in ~/.bluemix/config.json with APIKey as the key, it could be imported into 1Password. However, if this is too much of a stretch I could remove the file importer altogether.

Does the IBM CLI read the API key from said config file? I'm asking because that would be a reason for users to manually add it.

@SimonBarendse
Copy link
Member

With the current implementation, in order to authenticate you need to run ibmcloud login. If you were to run ibmcloud account list before authenticating with ibmcloud login first, for example, the command would fail. If the user isn't authenticated and they run a command besides ibmcloud login, do we want to run ibmcloud login under the hood first so that the command doesn't fail? If this is the desired behaviour, could I get some guidance on how to implement this?

Your current implementation is a great first version, that's already super valuable. It allows users to remove the API key from plaintext on disk, and instead load it through 1Password when and where needed. Not having to run ibmcloud login first would be a great additional improvement, but it shouldn't block this current implementation from moving forward already.

Copy link
Member

@SimonBarendse SimonBarendse left a comment

Choose a reason for hiding this comment

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

Love it! ☁️ I have left one comment to further look into and one small suggestion to help future readers of this code.

@williamhpark
Copy link
Contributor Author

Does the IBM CLI read the API key from said config file? I'm asking because that would be a reason for users to manually add it.

@SimonBarendse No there aren't any instances where the CLI reads the API key directly from the config file from what I know. The CLI stores a bearer and refresh token in the config file to authenticate, which may contain information extracted or derived from the API key, but it never reads an API key directly.

After some more thought, I feel like removing the file importer may be the right choice. Most likely, the user would be storing their API key in some other unknown location on their local disk since there isn't even a recommended location that IBM suggests users keep their API key. So in most cases, scanning the config file for an API key would probably not be useful. Can I get your thoughts on this @SimonBarendse?

@williamhpark
Copy link
Contributor Author

Added one more small change to skip auth through 1Password when user runs ibmcloud logout, to avoid the edge case where a user runs ibmcloud logout in a new terminal session and needs to authenticate through 1Password only to be logged out right away.

@SimonBarendse
Copy link
Member

If the way to pass the key is through an envvar and not through the config file, the envvar importer will be sufficient.

Most likely users are storing the key in their ~/.zshrc or equivalent to set the environment.

@AndyTitu AndyTitu marked this pull request as draft February 20, 2023 13:22
@AndyTitu
Copy link
Contributor

So the current approach we are taking in this PR will not work. Last time I checked we were waiting on IBM's team to introduce support for an env var in ibmcloud. The reason why we can't use a file provisioner here is because the ibmcloud cli keeps writing back to the config file and this will block our FIFO indeterminately. Since none of this issue have an ETA on their solutions, I will go ahead and close this PR for the time being.

@AndyTitu AndyTitu closed this Apr 26, 2023
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