diff --git a/cli/packages/cmd/login.go b/cli/packages/cmd/login.go index 0efe7af9e..abf664ed0 100644 --- a/cli/packages/cmd/login.go +++ b/cli/packages/cmd/login.go @@ -122,6 +122,21 @@ func handleAwsIamAuthLogin(cmd *cobra.Command, infisicalClient infisicalSdk.Infi return infisicalClient.Auth().AwsIamAuthLogin(identityId) } +func handleOidcAuthLogin(cmd *cobra.Command, infisicalClient infisicalSdk.InfisicalClientInterface) (credential infisicalSdk.MachineIdentityCredential, e error) { + + identityId, err := util.GetCmdFlagOrEnv(cmd, "machine-identity-id", util.INFISICAL_MACHINE_IDENTITY_ID_NAME) + if err != nil { + return infisicalSdk.MachineIdentityCredential{}, err + } + + jwt, err := util.GetCmdFlagOrEnv(cmd, "oidc-jwt", util.INFISICAL_OIDC_AUTH_JWT_NAME) + if err != nil { + return infisicalSdk.MachineIdentityCredential{}, err + } + + return infisicalClient.Auth().OidcAuthLogin(identityId, jwt) +} + func formatAuthMethod(authMethod string) string { return strings.ReplaceAll(authMethod, "-", " ") } @@ -257,6 +272,7 @@ var loginCmd = &cobra.Command{ util.AuthStrategy.GCP_ID_TOKEN_AUTH: handleGcpIdTokenAuthLogin, util.AuthStrategy.GCP_IAM_AUTH: handleGcpIamAuthLogin, util.AuthStrategy.AWS_IAM_AUTH: handleAwsIamAuthLogin, + util.AuthStrategy.OIDC_AUTH: handleOidcAuthLogin, } credential, err := authStrategies[strategy](cmd, infisicalClient) @@ -456,6 +472,7 @@ func init() { loginCmd.Flags().String("machine-identity-id", "", "machine identity id for kubernetes, azure, gcp-id-token, gcp-iam, and aws-iam auth methods") loginCmd.Flags().String("service-account-token-path", "", "service account token path for kubernetes auth") loginCmd.Flags().String("service-account-key-file-path", "", "service account key file path for GCP IAM auth") + loginCmd.Flags().String("oidc-jwt", "", "JWT for OIDC authentication") } func DomainOverridePrompt() (bool, error) { @@ -616,7 +633,7 @@ func getFreshUserCredentials(email string, password string) (*api.GetLoginOneV2R loginTwoResponseResult, err := api.CallLogin2V2(httpClient, api.GetLoginTwoV2Request{ Email: email, ClientProof: hex.EncodeToString(srpM1), - Password: password, + Password: password, }) if err != nil { diff --git a/cli/packages/util/auth.go b/cli/packages/util/auth.go index d27bbc2c8..cdcd7b50a 100644 --- a/cli/packages/util/auth.go +++ b/cli/packages/util/auth.go @@ -9,6 +9,7 @@ var AuthStrategy = struct { GCP_ID_TOKEN_AUTH AuthStrategyType GCP_IAM_AUTH AuthStrategyType AWS_IAM_AUTH AuthStrategyType + OIDC_AUTH AuthStrategyType }{ UNIVERSAL_AUTH: "universal-auth", KUBERNETES_AUTH: "kubernetes", @@ -16,6 +17,7 @@ var AuthStrategy = struct { GCP_ID_TOKEN_AUTH: "gcp-id-token", GCP_IAM_AUTH: "gcp-iam", AWS_IAM_AUTH: "aws-iam", + OIDC_AUTH: "oidc-auth", } var AVAILABLE_AUTH_STRATEGIES = []AuthStrategyType{ @@ -25,6 +27,7 @@ var AVAILABLE_AUTH_STRATEGIES = []AuthStrategyType{ AuthStrategy.GCP_ID_TOKEN_AUTH, AuthStrategy.GCP_IAM_AUTH, AuthStrategy.AWS_IAM_AUTH, + AuthStrategy.OIDC_AUTH, } func IsAuthMethodValid(authMethod string, allowUserAuth bool) (isValid bool, strategy AuthStrategyType) { diff --git a/cli/packages/util/constants.go b/cli/packages/util/constants.go index bff3c3ab0..84412cf76 100644 --- a/cli/packages/util/constants.go +++ b/cli/packages/util/constants.go @@ -19,6 +19,9 @@ const ( // GCP Auth INFISICAL_GCP_IAM_SERVICE_ACCOUNT_KEY_FILE_PATH_NAME = "INFISICAL_GCP_IAM_SERVICE_ACCOUNT_KEY_FILE_PATH" + // OIDC Auth + INFISICAL_OIDC_AUTH_JWT_NAME = "INFISICAL_OIDC_AUTH_JWT" + // Generic env variable used for auth methods that require a machine identity ID INFISICAL_MACHINE_IDENTITY_ID_NAME = "INFISICAL_MACHINE_IDENTITY_ID" diff --git a/docs/cli/commands/login.mdx b/docs/cli/commands/login.mdx index d97cb4c2b..fb902eb08 100644 --- a/docs/cli/commands/login.mdx +++ b/docs/cli/commands/login.mdx @@ -8,7 +8,8 @@ infisical login ``` ### Description -The CLI uses authentication to verify your identity. When you enter the correct email and password for your account, a token is generated and saved in your system Keyring to allow you to make future interactions with the CLI. + +The CLI uses authentication to verify your identity. When you enter the correct email and password for your account, a token is generated and saved in your system Keyring to allow you to make future interactions with the CLI. To change where the login credentials are stored, visit the [vaults command](./vault). @@ -17,12 +18,12 @@ If you have added multiple users, you can switch between the users by using the When you authenticate with **any other method than `user`**, an access token will be printed to the console upon successful login. This token can be used to authenticate with the Infisical API and the CLI by passing it in the `--token` flag when applicable. - Use flag `--plain` along with `--silent` to print only the token in plain text when using a machine identity auth method. - + Use flag `--plain` along with `--silent` to print only the token in plain text when using a machine identity auth method. + - ### Flags + The login command supports a number of flags that you can use for different authentication methods. Below is a list of all the flags that can be used with the login command. @@ -52,6 +53,7 @@ The login command supports a number of flags that you can use for different auth The `client-id` flag can be substituted with the `INFISICAL_UNIVERSAL_AUTH_CLIENT_ID` environment variable. + ```bash @@ -63,6 +65,7 @@ The login command supports a number of flags that you can use for different auth The `client-secret` flag can be substituted with the `INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET` environment variable. + ```bash @@ -75,6 +78,7 @@ The login command supports a number of flags that you can use for different auth The `machine-identity-id` flag can be substituted with the `INFISICAL_MACHINE_IDENTITY_ID` environment variable. + ```bash @@ -88,6 +92,7 @@ The login command supports a number of flags that you can use for different auth The `service-account-token-path` flag can be substituted with the `INFISICAL_KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH` environment variable. + ```bash @@ -100,9 +105,23 @@ The login command supports a number of flags that you can use for different auth The `service-account-key-path` flag can be substituted with the `INFISICAL_GCP_IAM_SERVICE_ACCOUNT_KEY_FILE_PATH` environment variable. + + + ```bash + infisical login --service-account-token-path= # Optional Will default to '/var/run/secrets/kubernetes.io/serviceaccount/token'. + ``` + + #### Description + The JWT provided by an identity provider for OIDC authentication. + + + The `oidc-jwt` flag can be substituted with the `INFISICAL_OIDC_AUTH_JWT` environment variable. + + + ### Authentication Methods @@ -121,6 +140,7 @@ The Infisical CLI supports multiple authentication methods. Below are the availa Your machine identity client secret. + @@ -134,6 +154,7 @@ The Infisical CLI supports multiple authentication methods. Below are the availa infisical login --method=universal-auth --client-id= --client-secret= ``` + @@ -148,6 +169,7 @@ The Infisical CLI supports multiple authentication methods. Below are the availa Path to the Kubernetes service account token to use. Default: `/var/run/secrets/kubernetes.io/serviceaccount/token`. + @@ -162,6 +184,7 @@ The Infisical CLI supports multiple authentication methods. Below are the availa infisical login --method=kubernetes --machine-identity-id= --service-account-token-path= ``` + @@ -213,6 +236,7 @@ The Infisical CLI supports multiple authentication methods. Below are the availa ``` + The GCP IAM method is used to authenticate with Infisical with a GCP service account key. @@ -235,11 +259,12 @@ The Infisical CLI supports multiple authentication methods. Below are the availa Run the `login` command with the following flags to obtain an access token: - ```bash + ```bash infisical login --method=gcp-iam --machine-identity-id= --service-account-key-file-path= ``` + The AWS IAM method is used to authenticate with Infisical with an AWS IAM role while running in an AWS environment like EC2, Lambda, etc. @@ -264,10 +289,40 @@ The Infisical CLI supports multiple authentication methods. Below are the availa ``` + + + + The OIDC Auth method is used to authenticate with Infisical via identity tokens with OIDC. + + + + + Your machine identity ID. + + + The OIDC JWT from the identity provider. + + + + + + + To create an OIDC machine identity, follow the step by step guide outlined [here](/documentation/platform/identities/oidc-auth/general). + + + Run the `login` command with the following flags to obtain an access token: + + ```bash + infisical login --method=oidc-auth --machine-identity-id= --oidc-jwt= + ``` + + + ### Machine Identity Authentication Quick Start + In this example we'll be using the `universal-auth` method to login to obtain an Infisical access token, which we will then use to fetch secrets with. @@ -277,8 +332,8 @@ In this example we'll be using the `universal-auth` method to login to obtain an ``` Now that we've set the `INFISICAL_TOKEN` environment variable, we can use the CLI to interact with Infisical. The CLI will automatically check for the presence of the `INFISICAL_TOKEN` environment variable and use it for authentication. - - + + Alternatively, if you would rather use the `--token` flag to pass the token directly, you can do so by running the following command: ```bash @@ -297,6 +352,7 @@ In this example we'll be using the `universal-auth` method to login to obtain an The `--recursive`, and `--env` flag is optional and will fetch all secrets in subfolders. The default environment is `dev` if no `--env` flag is provided. + And that's it! Now you're ready to start using the Infisical CLI to interact with your secrets, with the use of Machine Identities.