In the previous chapter we took a look at using OpenStack through the dashboard. Let's try to follow the same steps now, but through the use of the CLI.

CLI Overview

In the most recent versions, OpenStackClient project provides a unified command-line client, which enables you to access the project API through easy-to-use commands, although the commands for each single service still remain valid (for example, the Compute service provides a nova command-line client). Anyway, you can use the unified openstack command for the most of OpenStack services. Internally, each command uses cURL command-line tools, which embed API requests. OpenStack APIs are RESTful APIs, and use the HTTP protocol. For more information, see OpenStackClient document.

Install the OpenStack client

The first step is to install the client on your VM. Below is an example of installation on CentOS7, but for more details, refer to the official documentation.

OpenStack Client
# Install the prerequisite software
$ sudo yum install python3 python3-devel python3-pip python3-setuptools
$ sudo pip3 install --upgrade setuptools
$ sudo pip3 install --upgrade pip
# Install the OpenStack client
$ pip3 install python-openstackclient
# Verify correct installation
$ openstack --version
  openstack 5.7.0

Uso oidc-agent

Per prima cosa va installato il pacchetto oidc-agent. Vedi https://indigo-dc.gitbook.io/oidc-agent/

Prerequisiti: avere  un account su IAM con opportuni ruoli per accedere a Cloud@CNAF, conoscere l'ID e la regione del progetto con cui si vuole interagire

Una volta installato va configurato l'agent:

[dmichelotto@tb-cloud-ui ~]$ eval $(oidc-agent-service use)
[dmichelotto@tb-cloud-ui ~]$ oidc-gen

Con il secondo comando va specificato l'url dell'IAM che si intende utilizzare, dopo di ciò si verrà redirizionati ad una pagina web per fare il login su IAM, alla fine dell'operazione verrà chiesta una password per criptare la configurazione di questo IAM che verrà richiesta ad ogni nuovo login sulla vostra shell tramite il comando oidc-add nome_breve_iam.

Alla fine di questa operazione si potrà richiedere un token IAM da poter usare per l'autenticazione su Cloud@CNAF.

[dmichelotto@tb-cloud-ui ~]$ oidc-token nome_breve_iam
eyJraWQiOiJ.....

Ora verificato che si riesce ad ottenere un token si può procedere con la configurazione del client openstack

Nella propria home creare il seguente file

[dmichelotto@tb-cloud-ui ~]$ cat iam_openrc.sh
export OS_REGION_NAME="sdds"
export OS_INTERFACE=public
export OS_IDENTITY_API_VERSION=3
export OS_AUTH_TYPE="v3oidcaccesstoken"
export OS_IDENTITY_PROVIDER="cnaf"
export OS_PROTOCOL="openid"
export OS_AUTH_URL=https://cloud-api-pub.cr.cnaf.infn.it:5000/v3/
export OS_PROJECT_ID=01XXXXXXXXXXXXXXXXXXXX19
export OS_PROJECT_DOMAIN_ID="default"
export OS_ACCESS_TOKEN=$(oidc-token nome_breve_iam)

Attenzione ad inserire correttamente i valori dei campi OS_PROJECT_DOMAIN_ID, OS_REGION_NAME in modo che rispecchino le vostre autorizzazioni di accesso alle risorse Cloud@CNAF, e il campo OS_ACCESS_TOKEN nel quale va specificato l'esatto nome breve iam configurato in precedenza. Inoltre, OS_IDENTITY_PROVIDER deve rispecchiare l'Id del provider definito in keystone (openstack provider list), se non lo si conosce chiedere agli amministratori di Cloud@CNAF.

[dmichelotto@tb-cloud-ui ~]$ source iam_openrc.sh
[dmichelotto@tb-cloud-ui ~]$ openstack token issue
+------------+--------------------------+
| Field | Value |
+------------+--------------------------+
| expires | 2020-05-27T11:04:12+0000 |
| id | gAAAAAB..... |
| project_id | 016XXXXXXXXXXXXXXXXXX19 |
| user_id | a84XXXXXXXXXXXXXXXXXX6e |
+------------+--------------------------+

Application Credentials

Once the client has been downloaded, we need to download the login credentials from OpenStack. Let's connect to the dashboard and click on the tab Identity -> Application Credentials. Create an application credential, assigning a name and an expiration date, and download the generated openrc file. Upload it to your VM and, before launching any OpenStack client command, execute the command source <openrc-file>.

The source command will have to be re-executed at each new access on the VM.

Per prima cosa vanno create delle credenziali applicazione.

Per creare le credenziali da dashboard accedere all seguente URL dopo aver effettuato il login https://cloud-dashboard.cr.cnaf.infn.it/dashboard/identity/application_credentials/

Da qui si creano delle nuove credenziali tramite il pulsante in alto a destra "Create Application Credential"


Inserire opportunamente il nome per identificare le credenziali e il ruolo, se si desidera si può inserire una scadenza delle credenziali. Se si lascia il secret vuoto verrà creato in automatico.

Una volta create le credenziali scricare l'openrc file.

Una volta scaricato il file fare source del file e verificare il funzionamento dei client

[dmichelotto@cloud-ui ~]$ source app-cred-myapp-openrc.sh
[dmichelotto@cloud-ui ~]$ openstack token issue
+------------+--------------------------+
| Field | Value |
+------------+--------------------------+
| expires | 2020-05-27T11:04:12+0000 |
| id | gAAAAAB..... |
| project_id | 016XXXXXXXXXXXXXXXXXX19 |
| user_id | a84XXXXXXXXXXXXXXXXXX6e |
+------------+--------------------------+
  • No labels