github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/docs/cli/auth.md (about)

     1  ---
     2  layout: post
     3  title: AUTH
     4  permalink: /docs/cli/auth
     5  redirect_from:
     6   - /cli/auth.md/
     7   - /docs/cli/auth.md/
     8  ---
     9  
    10  For quick getting-started (local-playground) session _and_ in-depth overview, please refer to:
    11  
    12  * [AIS AuthN documentation](/docs/authn.md).
    13  
    14  ## Table of contents
    15  
    16  - [User Account and Access management](#user-account-and-access-management)
    17  - [Token management](#token-management)
    18    - [Generate a token for CLI](#generate-a-token-for-cli)
    19    - [Generate a token to a file](#generate-a-token-to-a-file)
    20    - [Revoke a token](#revoke-a-token)
    21  - [Command List](#command-list)
    22    - [Register new user](#register-new-user)
    23    - [Update user](#update-user)
    24    - [Unregister existing user](#unregister-existing-user)
    25    - [List registered users](#list-registered-users)
    26    - [Add a new role](#add-a-new-role)
    27    - [List existing roles](#list-existing-roles)
    28    - [Log in to AIS cluster](#log-in-to-ais-cluster)
    29    - [Log out](#log-out)
    30    - [Register new cluster](#register-new-cluster)
    31    - [Update existing cluster](#update-existing-cluster)
    32    - [Unregister existing cluster](#unregister-existing-cluster)
    33    - [List registered clusters](#list-registered-clusters)
    34    - [Show AuthN server configuration](#show-authn-server-configuration)
    35    - [Change AuthN server configuration](#change-authn-server-configuration)
    36  
    37  ## User Account and Access management
    38  
    39  [AuthN](/docs/authn.md) is an AIS authorization server that can be deployed to manage user access to one or more AIS clusters.
    40  
    41  All commands (except `logout`) send requests to AuthN URL defined in the AIS CLI configuration file.
    42  Configuration can be overridden with environment variable `AIS_AUTHN_URL`, e.g., `AIS_AUTHN_URL=http://10.0.0.20:52001 ais auth add ...`.
    43  
    44  The CLI provides an easy way to manage users, and to grant and revoke access permissions.
    45  Only users with `Admin` role can manage the AuthN server.
    46  
    47  Every request to AuthN, except `login` and `logout`, requires a token.
    48  The token is generated by the server after the user successfully logs in.
    49  CLI automatically saves the received token to user's configuration directory and attaches it to every request.
    50  
    51  When a token is revoked, AuthN notifies [registered clusters](#list-registered-clusters), so that they update their blacklists.
    52  
    53  ## Token management
    54  
    55  ### Generate a token for CLI
    56  
    57  After successful login, the CLI saves the generated token to the user's configuration directory for future use and automatically passes it with every request to AuthN.
    58  For convenience, the CLI prints out the generated token so it can be copied and used with other clients.
    59  
    60  ```console
    61  $ ais auth login -p admin admin
    62  Token(/home/ubuntu/.config/ais/cli/auth.token):
    63  ```
    64  
    65  ### Generate a token to a file
    66  
    67  The CLI supports loading a token from a custom location.
    68  One possible usage is imitating the Linux `sudo` command:
    69      1. A user logs into the AIStore cluster as an Admin and saves the token to some location.
    70      2. The user logs into AIStore as a regular user with default options. (A regular user's requests would then use that last generated token for all requests).
    71      3. When elevated privileges are needed, the user can *specify the path to the admin token*.
    72  
    73  ```console
    74  $ # Generate a token and save it to a given location
    75  $ ais auth login -p admin --file ./admin.token admin
    76  Token saved to ./admin.token
    77  
    78  $ # Log in as a regular user
    79  $ ais auth login -p pass user
    80  Token(/home/ubuntu/.config/ais/cli/auth.token)
    81  
    82  $ # Create bucket as a regular user
    83  $ ais create ais://bck1
    84  
    85  $ # Removing a user requires admin's token, pass a path to the token to CLI
    86  $ AIS_AUTHN_TOKEN_FILE=./admin.token ais auth rm user tmpUser1
    87  ```
    88  
    89  ### Revoke a token
    90  
    91  When a user's token is compromised, the token should be revoked:
    92  
    93  ```console
    94  $ # Pass the token in the command line
    95  $ ais auth rm token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6dHJ1Z...
    96  
    97  $ # Read the token from a file created by AIS CLI
    98  $ ais auth rm token -f /home/user/user.token
    99  ```
   100  
   101  ## Command List
   102  
   103  ### Register new user
   104  
   105  `ais auth add user [-p USER_PASS] USER_NAME [ROLE [ROLE...]]`
   106  
   107  Register a user and assign a list of roles to the user.
   108  
   109  If the list of roles is not provided, the new user does not have any permissions.
   110  
   111  Bucket access does not necessarily require creating a role. Instead, `admin` can **register a user with an empty role and grant permissions to the required buckets**.
   112  
   113  #### Examples
   114  
   115  ```console
   116  $ ais auth add user -p password user1
   117  $ ais auth add user -p password user2 PowerUser
   118  $ ais auth show user
   119  NAME    ROLES
   120  admin   Admin
   121  user1   -
   122  user2   PowerUser
   123  ```
   124  
   125  ### Update user
   126  
   127  `ais auth update user [-p USER_PASS] USER_NAME [ROLE [ROLE...]]`
   128  
   129  Updates user password and list of roles. If the role list is omitted, the current
   130  user role remains unchanged.
   131  Changing the role for the built-in account `admin` is forbidden.
   132  
   133  ### Unregister existing user
   134  
   135  `ais auth rm user USER_NAME`
   136  
   137  Remove an existing user. The built-in account `admin` cannot be removed.
   138  
   139  ### List registered users
   140  
   141  `ais auth show user [USER [-v]]`
   142  
   143  Displays the list of registered users.
   144  
   145  ```console
   146  $ ais auth show user
   147  NAME    ROLES
   148  admin   Admin
   149  user1   Guest-clu1,Guest-clu2
   150  user2   PowerUser-clu1
   151  ```
   152  
   153  By default, the user is displayed in short mode.
   154  Option `-v` prints detailed info:
   155  
   156  ```console
   157  $ ais auth show user user1
   158  NAME    ROLES
   159  user1   Guest-clu
   160  
   161  $ ais auth show user user1 -v
   162  Name            test
   163  Roles           Guest-local
   164  CLUSTER ID      ALIAS   PERMISSIONS
   165  k5zAzdhbr       clu     GET,HEAD-OBJECT,HEAD-BUCKET,LIST-OBJECTS
   166  ```
   167  
   168  ### Add a new role
   169  
   170  `ais auth add role ROLE_ID PERMISSION [PERMISSION...] [--flags]`
   171  
   172  Creates a role and grants the list of permissions to the role.
   173  
   174  | Flag | Description | Argument |
   175  | --- | --- | --- |
   176  | `--cluster` | Grants permissions to access and operate on a cluster (scope: cluster) | Cluster ID or alias |
   177  | `--bucket` | Grants permissions to access and operate on a specific bucket (scope: bucket) | Bucket URI (provider and bucket name), e.g. `ais://imagenet` |
   178  
   179  If only `--cluster` is defined, the permissions are used as default ones to access *every* bucket in the cluster.
   180  
   181  **Note**:
   182  
   183  * Flag `--bucket` always requires `--cluster` to be defined.
   184  * `PERMISSION` can be a single compound permission (one of `ro`, `rw`, `su`) or a specific access permission.
   185  
   186  Examples:
   187  
   188  ```console
   189  # Create a role with read-write access to all buckets in the cluster
   190  $ ais auth add role rwRole --cluster clusterOne rw
   191  $ ais auth show role rwRole -v
   192  Role            rwRole
   193  Description
   194  CLUSTER ID      ALIAS        PERMISSIONS
   195  k5zAzdhbr       clusterOne   GET,HEAD-OBJECT,PUT,APPEND,DELETE-OBJECT,MOVE-OBJECT,HEAD-BUCKET,LIST-OBJECTS
   196  
   197  # Grant specific permission to a cluster-level role
   198  $ ais auth add role specRole clusterOne GET HEAD-BUCKET LIST-OBJECT
   199  $ ais auth show role specRole -v
   200  Role            specRole
   201  Description
   202  CLUSTER ID      ALIAS        PERMISSIONS
   203  k5zAzdhbr       clusterOne   GET,HEAD-BUCKET,LIST-OBJECTS
   204  ```
   205  
   206  ### List existing roles
   207  
   208  `ais auth show role [ROLE]`
   209  
   210  Displays existing roles in alphabetical order.
   211  
   212  Flags:
   213  
   214  | Flag | Type | Description |
   215  | --- | --- | --- |
   216  | `-v` | `bool` | Enables verbose mode. In short mode only role names and their descriptions are displayed. In verbose mode, details about cluster and bucket permissions are shown as well. When `ROLE` is set, verbose mode enables automatically |
   217  | `--cluster` | `string` | Comman-separated list of cluster IDs. Only roles that grants permissions to these clusters or buckets of these clusters are shown |
   218  
   219  Note: some roles include "global" permissions - it is roles which are not bound to all clusters.
   220  You can create such role by omitting `--cluster` flag while adding or updating a role.
   221  To list "global" roles, pass a **list** which contains an empty cluster ID.
   222  List that contains olny "global" cluster ID is `","`. E.g, `ais auth show role --cluster=,`.
   223  
   224  ```console
   225  $ ais auth show role
   226  ROLE            DESCRIPTION
   227  Admin           AuthN administrator
   228  BucketOwner     Full access to buckets
   229  Guest           Read-only access to buckets
   230  PowerUser       Full access to cluster
   231  ```
   232  
   233  By default, the role is displayed in short mode.
   234  Option `-v` prints detailed info:
   235  
   236  ```console
   237  $ ais auth show role
   238  ROLE            DESCRIPTION
   239  Guest-clu       Read-only access to buckets of cluster k5zAzdhbr[local]
   240  
   241  $ ais auth show role -v
   242  Role            Guest-local
   243  Description     Read-only access to buckets of cluster k5zAzdhbr[local]
   244  CLUSTER ID      ALIAS   PERMISSIONS
   245  k5zAzdhbr       local   GET,HEAD-OBJECT,HEAD-BUCKET,LIST-OBJECTS
   246  ```
   247  
   248  Show all, global, and a single cluster roles:
   249  
   250  ```console
   251  $ ais auth show role -v
   252  Role              Admin
   253  Description       AuthN administrator
   254  
   255  Role              role1
   256  Description
   257  CLUSTER ID        ALIAS    PERMISSIONS
   258                             GET,HEAD-OBJECT,HEAD-BUCKET,LIST-OBJECTS,LIST-BUCKETS
   259  
   260  Role              role2
   261  Description
   262  CLUSTER ID        ALIAS    PERMISSIONS
   263  wRF7CDVbN         clu-tst  GET,HEAD-OBJECT,HEAD-BUCKET,LIST- OBJECTS,LIST-BUCKETS
   264  
   265  Role              role3
   266  Description
   267  CLUSTER ID        ALIAS    PERMISSIONS
   268  wRF7CDVbN         clu-tst  GET,HEAD-OBJECT,LIST-OBJECTS
   269  
   270  $ ais auth show role --cluster=clu-tst
   271  ROLE      DESCRIPTION
   272  role2
   273  role3
   274  
   275  $ ais auth show role --cluster=,
   276  ROLE      DESCRIPTION
   277  role1
   278  ```
   279  
   280  ### Log in to AIS cluster
   281  
   282  `ais auth login [-p USER_PASS] USER_NAME [--expire EXPIRATION_TIME]`
   283  
   284  Issue a token for a user.
   285  After successful login, the user's token is saved to CLI configuration directory (typically `~/.config/ais/cli/`) under `auth.token` filename.
   286  
   287  Subsequent `ais` commands automatically load and use the token for requests to the AIS cluster.
   288  The saved token can be used by other applications, like `curl`.
   289  Please see [AuthN documentation](/docs/authn.md) for how to use AuthN API directly.
   290  
   291  By default, the AuthN token expiration is 24 hours.
   292  Use option `-e` or `--expire` to generate a token with custom expiration time.
   293  
   294  ```console
   295  $ # Generate a token that expires in 5 hours
   296  $ ais auth login -p password username -e 5h
   297  
   298  $ # Generate a token that never expires
   299  $ ais auth login -p password username -e 0
   300  ```
   301  
   302  ### Log out
   303  
   304  `ais auth logout`
   305  
   306  Delete the user's token from a local machine. The token is not revoked, so it can be used by any application until it expires.
   307  To forbid using the token from any application, the token must be revoked manually in addition to logging out.
   308  
   309  ### Register new cluster
   310  
   311  `ais auth add cluster [ALIAS] [URL...]`
   312  
   313  If URL is omitted, CLI registers a cluster using its URL from CLI configuration or `AIS_ENDPOINT` variable.
   314  When the URL list is defined, CLI tries to connect the cluster using the first URL from the list.
   315  
   316  Register the cluster and assign the list of URLs for sending notifications.
   317  A user may assign an alias to the cluster for convenience: AuthN commands accepts both cluster ID and alias in requests.
   318  Alias must be a unique name.  Alias is an arbitrary name, but it should not start with `http`.
   319  In this case, CLI treats the alias as the URL.
   320  
   321  On successful cluster registration, AuthN automatically creates a few predefined unique roles for the cluster: with full access,
   322  read-write access to all its buckets, and read-only access to the cluster.
   323  Please note that the role names include cluster's alias if it was defined. If the alias is omitted, AuthN adds cluster ID to a role name.
   324  
   325  See full example in [List registered clusters](#list-registered-clusters).
   326  
   327  ### Update existing cluster
   328  
   329  `ais auth update cluster CLUSTER_ID [ALIAS] URL [URL...]`
   330  
   331  Replaces the list of URLs or changes alias for an existing cluster.
   332  
   333  ### Unregister existing cluster
   334  
   335  `ais auth rm cluster CLUSTER_ID`
   336  
   337  Remove the existing cluster from the notification list.
   338  
   339  ### List registered clusters
   340  
   341  `ais auth show cluster`
   342  
   343  Display the list of the cluster that subscribe to AuthN notifications.
   344  
   345  ```console
   346  # register a cluster without an alias
   347  $ ais auth add cluster http://172.0.10.10 http://10.0.10.10
   348  
   349  # register a cluster with an alias and default URL
   350  $ ais auth add cluster srv1
   351  
   352  # check the list of the clusters
   353  $ ais auth show cluster
   354  CLUSTER ID      ALIAS   URLs
   355  2xs35th89               http://172.0.10.10,http://10.0.10.10
   356  78df35690       srv1    http://172.0.10.50
   357  
   358  # check the list of generated roles. Note that for convenience,
   359  # the role description includes both ID and alias if appropriate
   360  $ ais auth show role
   361  ROLE                    DESCRIPTION
   362  Admin                   AuthN administrator
   363  BucketOwner-2xs35th89   Full access to buckets of cluster 2xs35th89
   364  BucketOwner-srv1        Full access to buckets of cluster 78df35690[srv1]
   365  ClusterOwner-2xs35th89  Full access to cluster 2xs35th89
   366  ClusterOwner-srv1       Full access to cluster 78df35690[srv1]
   367  Guest-2xs35th89         Read-only access to buckets of cluster 2xs35th89
   368  Guest-srv1              Read-only access to buckets of cluster 78df35690[srv1]
   369  ```
   370  
   371  ### Show AuthN server configuration
   372  
   373  `ais auth show config [--json | PREFIX]`
   374  
   375  Display the AuthN server configuration in tabular or JSON format.
   376  In tabular output, the prefix filters only properties which names start with it.
   377  
   378  ```console
   379  $ ais auth show config auth.e
   380  PROPERTY                 VALUE
   381  auth.expiration_time     5h
   382  
   383  $ ais auth show config --json
   384  {
   385      "path": "/home/ubuntu/.authn/authn.json",
   386      "confdir": "/home/ubuntu/.authn",
   387      "log": {
   388          "dir": "/tmp/ais/authn/log",
   389          "level": "3"
   390      },
   391      "net": {
   392          "http": {
   393              "port": 52001,
   394              "use_https": false,
   395              "server_crt": "server.crt",
   396              "server_key": "server.key"
   397          }
   398      },
   399      "auth": {
   400          "secret": "aBitLongSecretKey",
   401          "expiration_time": "5h"
   402      },
   403      "timeout": {
   404          "default_timeout": "30s"
   405      }
   406  }
   407  
   408  ```
   409  
   410  ### Change AuthN server configuration
   411  
   412  `ais auth set config PROP VALUE [PROP VALUE...]`
   413  
   414  Update AuthN server configuration.
   415  The command allows updating options that can be changed without AuthN server restart.
   416  New property values can be defined either in `PROPERTY VALUE` or `PROPERTY=VALUE` form.
   417  
   418  ```console
   419  $ ais auth set config auth.
   420  auth.expiration_time  auth.secret
   421  
   422  $ ais auth set config auth.expiration_time 4h
   423  $ ais auth show config auth.e
   424  PROPERTY                 VALUE
   425  auth.expiration_time     4h
   426  ```
   427  
   428  Do not forget to update the secret on all clusters if you change AuthN secret.
   429  Otherwise, new tokens will be rejected by AIS clusters.