Configurando perfis confiáveis para o complemento do OpenShift Data Foundation

Nuvem privada virtual Clusters clássicos

Você pode usar perfis confiáveis para ODF a fim de limitar o acesso que os pods em execução no seu cluster têm a outros recursos da sua conta ou do cluster. Para obter mais informações sobre perfis confiáveis, consulte Criando perfis confiáveis.

Ativando o complemento do OpenShift Data Foundation

  1. Efetue login na sua conta. If applicable, target the appropriate resource group. Configure o contexto para o seu cluster.

  2. Ative o complemento no seu cluster. Revise a Referência do parâmetro.

    Exemplo de comando:

    ibmcloud oc cluster addon enable openshift-data-foundation -c CLUSTER_NAME --version 4.X.X
    
  3. Verifique se o estado do complemento é normal e o status é ready.

    ibmcloud oc cluster addon ls --cluster CLUSTER-ID
    
  4. Verifique se o pod do agente de métricas está implementado e o status é Running.

    kubectl get pods -n kube-system | grep ibm-storage-metrics-agent
    

    Saída de exemplo:

    ibm-storage-metrics-agent-644cd95b5b-rh2gd        2/2     Running   0          7h42m
    

Configuração de perfis confiáveis para ODF

  1. Siga as etapas para criar um perfil confiável. Nas Condições para o perfil, certifique-se de especificar o acesso a seguir.

    • Permitir acesso quando Namespace for igual a kube-system
    • Satellite- Satellite Link Administrador, Leitor
    • Kubernetes Service Funções-Gerenciador, Editor
    • Funções de Serviço de Faturamento-Leitor, Operador.
  2. Depois de criar o perfil confiável, copie o ID da página Perfis confiáveis no console.

  3. Decida se você deseja usar o ID do perfil ou uma Chave de API no segredo do Kubernetes usado pelo complemento. É possível criar o segredo usando o ID ou a chave de API para o perfil confiável. Salve o texto a seguir e insira suas credenciais. É possível seguir as etapas para criar o segredo manualmente ou usar o shell script para criar automaticamente o segredo no cluster.

    Exemplo de credenciais com identidade de pod:

    IBMCLOUD_AUTHTYPE=pod-identity
    IBMCLOUD_PROFILEID=<TRUSTED-PROFILE-ID>
    

    Exemplo de credenciais com uma chave de API.

    IBMCLOUD_AUTHTYPE=iam
    IBMCLOUD_APIKEY=<API-KEY>
    
  4. Codifique as credenciais para base64.

    echo -n "IBMCLOUD_AUTHTYPE=<IAM-OR-POD-IDENTITY>
    IBMCLOUD_APIKEY=<API-KEY>" | base64
    
  5. Crie um segredo no cluster que contenha as credenciais para o perfil confiável. Salve o YAML a seguir em um arquivo chamado ibm-cloud-credentials.yaml. No campo ibm-credentials.env:, insira a chave de API codificada em base64 ou o ID do perfil confiável.

    apiVersion: v1
    data:
      ibm-credentials.env: # Trusted profile ID
    kind: Secret
    metadata:
      name: ibm-cloud-credentials
      namespace: kube-system
    type: Opaque
    
  6. Efetue login na sua conta. If applicable, target the appropriate resource group. Configure o contexto para o seu cluster.

  7. Crie o segredo em seu cluster.

    kubectl apply -f ibm-cloud-credentials.yaml
    
  8. Reinicie os pods do agente..

    kubectl delete pod <ibm-storage-metrics-agent> -n kube-system>
    

Criando automaticamente um segredo por meio do uso de um Shell script

  1. Siga as etapas para criar um perfil confiável. Nas Condições para o perfil, certifique-se de especificar o acesso a seguir.

    • Permitir acesso quando Namespace for igual a kube-system
    • Satellite- Satellite Link Administrador, Leitor
    • Kubernetes Service Funções-Gerenciador, Editor
    • Funções de Serviço de Faturamento-Leitor, Operador.
  2. Salve o script a seguir em um arquivo chamado generate-secret.sh.

    IBMCLOUD_AUTHTYPE=
    SECRET=
    error() {
        if [[ $? != 0 ]]; then
            echo "$1"; exit 1
        fi
    }
    #validate_arguments validates the arguments provided to the script
    validate_arguments() {
        if [[ "$#" -eq 1 ]]; then
        if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
            usage; exit 1
        fi
        fi
            #number of arguments provided to the script must be 2
        if [[ "$#" -ne 2 ]]; then
            echo "Invalid number of arguments provided"
            usage; exit 1
        fi
        #1st argument must be 'iam' or 'pod-identity'
        if [[ "$1" != "iam" ]] && [[ "$1" != "pod-identity" ]]; then
            echo "Provide a valid auth-type"
            usage; exit 1
        fi
        IBMCLOUD_AUTHTYPE=$1
        SECRET=$2
    }
    #usage - prints the usage for execution of script
    usage() {
        echo "USAGE:
        bash generate-secret.sh <auth-type> <apikey/profile-id>
        auth-type: auth-type should be either iam or pod-identity. Provide iam to use api
    key, pod-identity to use trusted profile"
    }
    #main
    main() {
        validate_arguments "$@"
        auth_type="IBMCLOUD_AUTHTYPE=$IBMCLOUD_AUTHTYPE"
        secret=
        if [[ "$IBMCLOUD_AUTHTYPE" == "iam" ]]; then
            secret="IBMCLOUD_APIKEY=$SECRET"
        else
            secret="IBMCLOUD_PROFILEID=$SECRET"
        fi
        encodedValue=$(echo -e "$auth_type\n$secret" | base64)
        #on certain os, base64 encoding introduces newline, removing the same here.
        encodedValue=${encodedValue//$'\n'/}
        #fetch the agent pod name
        agentPodName=$(kubectl get pods -n kube-system | grep ibm-storage-metrics-agent | awk '{print $1}')
        error "$(date +"%b %d %G %H:%M:%S"):  Unable to fetch ODF agent pod."
        if [[ "$agentPodName" == "" ]]; then
            echo "$(date +"%b %d %G %H:%M:%S"):  Error - ibm-storage-metrics-agent pod
    not found"
            exit 1
        fi
        echo "apiVersion: v1
    data:
    ibm-credentials.env: $encodedValue
    kind: Secret
    metadata:
    name: ibm-cloud-credentials
    namespace: kube-system
    type: Opaque" > ibm-cloud-credentials.yaml
        #create the k8s secret
        kubectl apply -f ibm-cloud-credentials.yaml &> /dev/null
        error "$(date +"%b %d %G %H:%M:%S"):  Error creating ibm-cloud-credentials
    secret."
        echo "$(date +"%b %d %G %H:%M:%S"):  Created ibm-cloud-credentials secret"
        #restart the ODF agent pod
        echo "$(date +"%b %d %G %H:%M:%S"):  Restarting $agentPodName pod"
        kubectl delete pod "$agentPodName" -n kube-system &> /dev/null
        error "$(date +"%b %d %G %H:%M:%S"):  Error restarting $agentPodName pod in
    kube-system namespace."
        agentPodStatus=
        for i in {1..12}
        do
            sleep 5
            agentPodStatus=$(kubectl get pods -n kube-system | grep ibm-storage-metrics-agent | awk '{print $3}')
            if [[ "$agentPodStatus" == "Running" ]]; then
                echo "$(date +"%b %d %G %H:%M:%S"):  $i: ODF billing agent is now using
    ibm-cloud-credentials secret"
                rm ibm-cloud-credentials.yaml
                error "Error deleting ibm-cloud-credentials.yaml."
                exit 0
            fi
        done
        error "$(date +"%b %d %G %H:%M:%S"):  Error - ibm-storage-metrics-agent is in
    $agentPodStatus state"
    }
    main "$@"
    
  3. Execute o script generate-secret.sh e especifique iam ou pod-identity como o IBMCLOUD_AUTHTYPE e seu PROFILE-ID ou API-KEY.

    Exemplo de comando para executar generate-secret.sh usando pod-identity com seu ID de perfil confiável.

    sh ./generate-secret.sh pod-identity PROFILE-ID
    

    Exemplo de comando para executar generate-secret.sh usando iam com uma chave de API.

    sh ./generate-secret.sh iam API-KEY
    
  4. Reinicie os pods do agente..

    oc delete pod <ibm-storage-metrics-agent> -n kube-sysem
    
  5. Obtenha os logs do pod do agente para verificar se o driver está usando as credenciais corretas, procurando por “ secret type ” na saída. Por exemplo, "secret-used":"ibm-cloud-credentials","type":"pod-identity".

    oc logs ibm-storage-metrics-agent-xxx -c storage-secret-sidecar -n kube-system