diff --git a/cli/cmd/admin.go b/cli/cmd/admin.go index 8a2d7f006b..f56fea06eb 100644 --- a/cli/cmd/admin.go +++ b/cli/cmd/admin.go @@ -58,6 +58,27 @@ var _disable2faCmd = &cobra.Command{ }, } +var _disablePasskeyCmd = &cobra.Command{ + Use: "disable-passkey", + Short: "Disable passkey for a user", + RunE: func(cmd *cobra.Command, args []string) error { + recoverWithLog() + var flags = &model.AdminActionForUser{} + cmd.Flags().VisitAll(func(f *pflag.Flag) { + if f.Name == "admin-user" { + flags.AdminEmail = f.Value.String() + } + if f.Name == "user" { + flags.UserEmail = f.Value.String() + } + }) + if flags.UserEmail == "" { + return fmt.Errorf("user email is required") + } + return ctrl.DisablePasskeys(context.Background(), *flags) + }, +} + var _deleteUser = &cobra.Command{ Use: "delete-user", Short: "Delete a user", @@ -130,11 +151,13 @@ func init() { _listUsers.Flags().StringP("admin-user", "a", "", "The email of the admin user. ") _disable2faCmd.Flags().StringP("admin-user", "a", "", "The email of the admin user. ") _disable2faCmd.Flags().StringP("user", "u", "", "The email of the user to disable 2FA for. (required)") + _disablePasskeyCmd.Flags().StringP("admin-user", "a", "", "The email of the admin user. ") + _disablePasskeyCmd.Flags().StringP("user", "u", "", "The email of the user to disable passkey for. (required)") _deleteUser.Flags().StringP("admin-user", "a", "", "The email of the admin user. ") _deleteUser.Flags().StringP("user", "u", "", "The email of the user to delete. (required)") _updateFreeUserStorage.Flags().StringP("admin-user", "a", "", "The email of the admin user.") _updateFreeUserStorage.Flags().StringP("user", "u", "", "The email of the user to update subscription for. (required)") // add a flag with no value --no-limit _updateFreeUserStorage.Flags().String("no-limit", "True", "When true, sets 100TB as storage limit, and expiry to current date + 100 years") - _adminCmd.AddCommand(_userDetailsCmd, _disable2faCmd, _updateFreeUserStorage, _listUsers, _deleteUser) + _adminCmd.AddCommand(_userDetailsCmd, _disable2faCmd, _disablePasskeyCmd, _updateFreeUserStorage, _listUsers, _deleteUser) } diff --git a/cli/docs/generated/ente.md b/cli/docs/generated/ente.md index 4f85dd0980..c3f4a11338 100644 --- a/cli/docs/generated/ente.md +++ b/cli/docs/generated/ente.md @@ -25,4 +25,4 @@ ente [flags] * [ente export](ente_export.md) - Starts the export process * [ente version](ente_version.md) - Prints the current version -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_account.md b/cli/docs/generated/ente_account.md index 41c37b0547..d254b29685 100644 --- a/cli/docs/generated/ente_account.md +++ b/cli/docs/generated/ente_account.md @@ -16,4 +16,4 @@ Manage account settings * [ente account list](ente_account_list.md) - list configured accounts * [ente account update](ente_account_update.md) - Update an existing account's export directory -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_account_add.md b/cli/docs/generated/ente_account_add.md index 1e86ae12f7..26a314a9e3 100644 --- a/cli/docs/generated/ente_account_add.md +++ b/cli/docs/generated/ente_account_add.md @@ -20,4 +20,4 @@ ente account add [flags] * [ente account](ente_account.md) - Manage account settings -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_account_get-token.md b/cli/docs/generated/ente_account_get-token.md index 3d8814d7d1..40a21f1439 100644 --- a/cli/docs/generated/ente_account_get-token.md +++ b/cli/docs/generated/ente_account_get-token.md @@ -18,4 +18,4 @@ ente account get-token [flags] * [ente account](ente_account.md) - Manage account settings -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_account_list.md b/cli/docs/generated/ente_account_list.md index a7677eb855..3c9ded6737 100644 --- a/cli/docs/generated/ente_account_list.md +++ b/cli/docs/generated/ente_account_list.md @@ -16,4 +16,4 @@ ente account list [flags] * [ente account](ente_account.md) - Manage account settings -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_account_update.md b/cli/docs/generated/ente_account_update.md index 8d9c8d7e54..a1837529c3 100644 --- a/cli/docs/generated/ente_account_update.md +++ b/cli/docs/generated/ente_account_update.md @@ -19,4 +19,4 @@ ente account update [flags] * [ente account](ente_account.md) - Manage account settings -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_admin.md b/cli/docs/generated/ente_admin.md index 5ac72489d6..29f136f75b 100644 --- a/cli/docs/generated/ente_admin.md +++ b/cli/docs/generated/ente_admin.md @@ -17,8 +17,9 @@ Commands for admin actions like disable or enabling 2fa, bumping up the storage * [ente](ente.md) - CLI tool for exporting your photos from ente.io * [ente admin delete-user](ente_admin_delete-user.md) - Delete a user * [ente admin disable-2fa](ente_admin_disable-2fa.md) - Disable 2fa for a user +* [ente admin disable-passkey](ente_admin_disable-passkey.md) - Disable passkey for a user * [ente admin get-user-id](ente_admin_get-user-id.md) - Get user id * [ente admin list-users](ente_admin_list-users.md) - List all users * [ente admin update-subscription](ente_admin_update-subscription.md) - Update subscription for user -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_admin_delete-user.md b/cli/docs/generated/ente_admin_delete-user.md index a1d52a73d2..901430ff09 100644 --- a/cli/docs/generated/ente_admin_delete-user.md +++ b/cli/docs/generated/ente_admin_delete-user.md @@ -18,4 +18,4 @@ ente admin delete-user [flags] * [ente admin](ente_admin.md) - Commands for admin actions -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_admin_disable-2fa.md b/cli/docs/generated/ente_admin_disable-2fa.md index 23cd330800..40aedd38da 100644 --- a/cli/docs/generated/ente_admin_disable-2fa.md +++ b/cli/docs/generated/ente_admin_disable-2fa.md @@ -18,4 +18,4 @@ ente admin disable-2fa [flags] * [ente admin](ente_admin.md) - Commands for admin actions -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_admin_disable-passkey.md b/cli/docs/generated/ente_admin_disable-passkey.md new file mode 100644 index 0000000000..c315aeae04 --- /dev/null +++ b/cli/docs/generated/ente_admin_disable-passkey.md @@ -0,0 +1,21 @@ +## ente admin disable-passkey + +Disable passkey for a user + +``` +ente admin disable-passkey [flags] +``` + +### Options + +``` + -a, --admin-user string The email of the admin user. + -h, --help help for disable-passkey + -u, --user string The email of the user to disable passkey for. (required) +``` + +### SEE ALSO + +* [ente admin](ente_admin.md) - Commands for admin actions + +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_admin_get-user-id.md b/cli/docs/generated/ente_admin_get-user-id.md index 47d632abb6..3cbe42f2d7 100644 --- a/cli/docs/generated/ente_admin_get-user-id.md +++ b/cli/docs/generated/ente_admin_get-user-id.md @@ -18,4 +18,4 @@ ente admin get-user-id [flags] * [ente admin](ente_admin.md) - Commands for admin actions -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_admin_list-users.md b/cli/docs/generated/ente_admin_list-users.md index 635e8ec3cd..519dcaccd2 100644 --- a/cli/docs/generated/ente_admin_list-users.md +++ b/cli/docs/generated/ente_admin_list-users.md @@ -17,4 +17,4 @@ ente admin list-users [flags] * [ente admin](ente_admin.md) - Commands for admin actions -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_admin_update-subscription.md b/cli/docs/generated/ente_admin_update-subscription.md index d0fadcd2ba..341ccf5fe5 100644 --- a/cli/docs/generated/ente_admin_update-subscription.md +++ b/cli/docs/generated/ente_admin_update-subscription.md @@ -23,4 +23,4 @@ ente admin update-subscription [flags] * [ente admin](ente_admin.md) - Commands for admin actions -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_auth.md b/cli/docs/generated/ente_auth.md index e0e97d84fc..2fd67cb0f1 100644 --- a/cli/docs/generated/ente_auth.md +++ b/cli/docs/generated/ente_auth.md @@ -13,4 +13,4 @@ Authenticator commands * [ente](ente.md) - CLI tool for exporting your photos from ente.io * [ente auth decrypt](ente_auth_decrypt.md) - Decrypt authenticator export -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_auth_decrypt.md b/cli/docs/generated/ente_auth_decrypt.md index c9db6ea545..682ba1560e 100644 --- a/cli/docs/generated/ente_auth_decrypt.md +++ b/cli/docs/generated/ente_auth_decrypt.md @@ -16,4 +16,4 @@ ente auth decrypt [input] [output] [flags] * [ente auth](ente_auth.md) - Authenticator commands -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_export.md b/cli/docs/generated/ente_export.md index d809e06e46..e3f07bb3c3 100644 --- a/cli/docs/generated/ente_export.md +++ b/cli/docs/generated/ente_export.md @@ -16,4 +16,4 @@ ente export [flags] * [ente](ente.md) - CLI tool for exporting your photos from ente.io -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/docs/generated/ente_version.md b/cli/docs/generated/ente_version.md index 08f384b52f..e1a3d8163b 100644 --- a/cli/docs/generated/ente_version.md +++ b/cli/docs/generated/ente_version.md @@ -16,4 +16,4 @@ ente version [flags] * [ente](ente.md) - CLI tool for exporting your photos from ente.io -###### Auto generated by spf13/cobra on 6-May-2024 +###### Auto generated by spf13/cobra on 22-Jun-2024 diff --git a/cli/internal/api/admin.go b/cli/internal/api/admin.go index 9e0bcb90a7..3511876cd1 100644 --- a/cli/internal/api/admin.go +++ b/cli/internal/api/admin.go @@ -88,6 +88,29 @@ func (c *Client) Disable2Fa(ctx context.Context, userID int64) error { return nil } +func (c *Client) DisablePassKeyMFA(ctx context.Context, userID int64) error { + var res interface{} + + payload := map[string]interface{}{ + "userID": userID, + } + r, err := c.restClient.R(). + SetContext(ctx). + SetResult(&res). + SetBody(payload). + Post("/admin/user/disable-passkeys") + if err != nil { + return err + } + if r.IsError() { + return &ApiError{ + StatusCode: r.StatusCode(), + Message: r.String(), + } + } + return nil +} + func (c *Client) UpdateFreePlanSub(ctx context.Context, userDetails *models.UserDetails, storageInBytes int64, expiryTimeInMicro int64) error { var res interface{} if userDetails.Subscription.ProductID != "free" { diff --git a/cli/main.go b/cli/main.go index be14a8686c..5b65929aea 100644 --- a/cli/main.go +++ b/cli/main.go @@ -15,7 +15,7 @@ import ( "strings" ) -var AppVersion = "0.1.16" +var AppVersion = "0.1.17" func main() { cliDBPath, err := GetCLIConfigPath() diff --git a/cli/pkg/admin_actions.go b/cli/pkg/admin_actions.go index 0105cdc199..44af3c27a9 100644 --- a/cli/pkg/admin_actions.go +++ b/cli/pkg/admin_actions.go @@ -82,6 +82,27 @@ func (c *ClICtrl) Disable2FA(ctx context.Context, params model.AdminActionForUse return nil } +func (c *ClICtrl) DisablePasskeys(ctx context.Context, params model.AdminActionForUser) error { + accountCtx, err := c.buildAdminContext(ctx, params.AdminEmail) + if err != nil { + return err + } + userDetails, err := c.Client.GetUserIdFromEmail(accountCtx, params.UserEmail) + if err != nil { + return err + } + err = c.Client.DisablePassKeyMFA(accountCtx, userDetails.User.ID) + if err != nil { + if apiErr, ok := err.(*api.ApiError); ok && apiErr.StatusCode == 400 && strings.Contains(apiErr.Message, "Token is too old") { + fmt.Printf("Error: Old admin token, please re-authenticate using `ente account add` \n") + return nil + } + return err + } + fmt.Println("Successfully disabled passkey for user") + return nil +} + func (c *ClICtrl) UpdateFreeStorage(ctx context.Context, params model.AdminActionForUser, noLimit bool) error { accountCtx, err := c.buildAdminContext(ctx, params.AdminEmail) if err != nil { diff --git a/cli/pkg/store.go b/cli/pkg/store.go index aa866d5952..98121e80ac 100644 --- a/cli/pkg/store.go +++ b/cli/pkg/store.go @@ -12,9 +12,9 @@ import ( ) func GetDB(path string) (*bolt.DB, error) { - db, err := bolt.Open(path, 0600, &bolt.Options{Timeout: 1 * time.Second}) + db, err := bolt.Open(path, 0600, &bolt.Options{Timeout: 5 * time.Second}) if err != nil { - log.Fatal(err) + log.Fatal(fmt.Sprintf("Failed to open db %s ", path), err) } return db, err }