Crea modulo IAM

Il modulo IAM contiene la configurazione per i gruppi e i criteri. Definire ogni gruppo e criterio come risorsa nella configurazione e dichiarare le variabili richieste.

Informazioni su criteri e gruppi

Per controllare l'accesso degli utenti alle risorse della topologia, creare gruppi e assegnare i criteri per concedere le autorizzazioni richieste a ogni gruppo.

Nella tabella riportata di seguito sono elencati i gruppi e le autorizzazioni richiesti, in genere per un'architettura multilivello.

Raggruppa Autorizzazioni
DBAdmins
  • Leggere tutte le risorse della tenancy.
  • Gestire le risorse del database;
IAMAdminManagers
  • Gestire gli utenti.
  • Gestire i gruppi Administrators e NetSecAdmins.

Nota: Oracle crea il gruppo Administrators quando si esegue la sottoscrizione a Oracle Cloud. Gli utenti di questo gruppo dispongono dell'accesso completo a tutte le risorse della tenancy, inclusi la gestione di utenti e gruppi. Limita l'appartenenza a questo gruppo.

IAMManagers
  • Gestire gli utenti.
  • Gestire tutti i gruppi tranne Administrators e NetSecAdmins.
NetworkAdmins
  • Leggere tutte le risorse della tenancy.
  • Gestire tutte le risorse di rete, ad eccezione degli elenchi di sicurezza, dei gateway Internet, delle connessioni IPSec VPN e delle attrezzature del cliente.
NetSecAdmins
  • Leggere tutte le risorse della tenancy.
  • Gestione di elenchi di sicurezza, gateway Internet, attrezzature cliente, connessioni IPSec VPN e load balancer.
  • Utilizza tutte le risorse di rete virtuale.
ReadOnly Visualizzare e ispezionare la tenancy. Questo gruppo è destinato agli utenti che non devono creare o gestire risorse, ad esempio auditor e capacità.
StorageAdmins
  • Leggere tutte le risorse della tenancy.
  • Gestire le risorse per lo storage degli oggetti e i volumi a blocchi.
SysAdmins
  • Leggere tutte le risorse della tenancy.
  • Gestisci le risorse di computazione e storage.
  • Gestire i compartimenti.
  • Utilizzare load balancer, subnet e VNIC.

Definire i gruppi e i criteri

Creare i file di configurazione Terraform che definiscono i criteri e i gruppi Oracle Cloud Infrastructure Identity and Access Management richiesti.

Completare la procedura riportata di seguito nella sottodirectory iam.

  1. Creare un file di testo denominato variables.tf e incollare il seguente codice nel file.
    Questo codice dichiara le variabili utilizzate nel modulo.
    variable "tenancy_ocid" {}
    variable "app_tag" {}
    variable "environment" {}
  2. Creare un file di testo denominato groups.tf e incollare il seguente codice nel file.
    resource "oci_identity_group" "db_admins" {
      description = "Group for users allowed to manage the databases in the tenancy."
      name        = "DBAdmins.grp"
    }
    resource "oci_identity_group" "iam_admin_managers" {
      description = "Group for users allowed to modify the Administrators and NetSecAdmins group."
      name        = "IAMAdminManagers.grp"
    }
    
    resource "oci_identity_group" "iam_managers" {
      description = "Group for users allowed to modify all users and groups except the Administrators and NetSecAdmin groups."
      name        = "IAMManagers.grp"
    }
    
    resource "oci_identity_group" "net_sec_admins" {
      description = "Administrators of the VCNs, but restricted from the following resources: vcns, subnets, route-tables, dhcp-options, drgs, drg-attachments, vnics, vnic-attachments"
      name        = "NetSecAdmins.grp"
    }
    
    resource "oci_identity_group" "network_admins" {
      description = "Administrators of the VCNs, but restricted from the following resources: security-lists, internet-gateways, cpes, ipsec-connections"
      name        = "NetworkAdmins.grp"
    }
    
    resource "oci_identity_group" "read_only" {
      description = "Groups for users allowed to view and inspect the tenancy configuration; for example, trainees"
      name        = "ReadOnly.grp"
    }
    
    resource "oci_identity_group" "storage_admins" {
      description = "Group for users allowed manage the Storage resources in the tenancy."
      name        = "StorageAdmins.grp"
    }
    
    resource "oci_identity_group" "sys_admins" {
      description = "Group for users allowed manage the Compute and Storage resources in the tenancy. Tenant administrators should be in this group."
      name        = "SysAdmins.grp"
    }
  3. Creare un file di testo denominato policies.tf e incollare il seguente codice nel file.
    resource "oci_identity_policy" "iam_admin_managers" {
      name           = "IAMAdminManagers.pl"
      description    = "IAMAdminManagers.pl"
      compartment_id = "${var.tenancy_ocid}"
    
      statements = [
        "ALLOW GROUP ${oci_identity_group.iam_admin_managers.name} to read users IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.iam_admin_managers.name} to read groups IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.iam_admin_managers.name} to manage users IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.iam_admin_managers.name} to manage groups IN TENANCY where target.group.name = 'Administrators'",
        "ALLOW GROUP ${oci_identity_group.iam_admin_managers.name} to manage groups IN TENANCY where target.group.name = '${oci_identity_group.net_sec_admins.name}'",
      ]
    }
    
    resource "oci_identity_policy" "iam_managers" {
      name           = "IAMManagers.pl"
      description    = "IAMManagers.pl"
      compartment_id = "${var.tenancy_ocid}"
    
      statements = [
        "ALLOW GROUP ${oci_identity_group.iam_managers.name} to read users IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.iam_managers.name} to read groups IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.iam_managers.name} to manage users IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.iam_managers.name} to manage groups IN TENANCY where all {target.group.name ! = 'Administrators', target.group.name ! = '${oci_identity_group.net_sec_admins.name}'}",
      ]
    }
    
    resource "oci_identity_policy" "sys_admins" {
      name           = "SysAdmins.pl"
      description    = "SysAdmins.pl"
      compartment_id = "${var.tenancy_ocid}"
    
      statements = [
        "ALLOW GROUP ${oci_identity_group.sys_admins.name} to manage instance-family IN TENANCY where all {target.compartment.name=/*/, target.compartment.name!=/${var.app_tag}_${var.environment}_networks/}",
        "ALLOW GROUP ${oci_identity_group.sys_admins.name} to manage object-family IN TENANCY where all {target.compartment.name=/*/, target.compartment.name!=/${var.app_tag}_${var.environment}_networks/}",
        "ALLOW GROUP ${oci_identity_group.sys_admins.name} to manage volume-family IN TENANCY where all {target.compartment.name=/*/ , target.compartment.name!=/${var.app_tag}_${var.environment}_networks/}",
        "ALLOW GROUP ${oci_identity_group.sys_admins.name} to use load-balancers IN TENANCY where all {target.compartment.name=/*/ , target.compartment.name!=/${var.app_tag}_${var.environment}_networks/}",
        "ALLOW GROUP ${oci_identity_group.sys_admins.name} to use subnets IN TENANCY where target.compartment.name=/${var.app_tag}_${var.environment}_networks/",
        "ALLOW GROUP ${oci_identity_group.sys_admins.name} to use vnics IN TENANCY where target.compartment.name=/${var.app_tag}_${var.environment}_networks/",
        "ALLOW GROUP ${oci_identity_group.sys_admins.name} to use vnic-attachments IN TENANCY where target.compartment.name=/${var.app_tag}_${var.environment}_networks/",
        "ALLOW GROUP ${oci_identity_group.sys_admins.name} to manage compartments in Tenancy where all {target.compartment.name=/*/ , target.compartment.name!=/${var.app_tag}_${var.environment}_networks/, target.compartment.name!=/Shared-Infra-Services/}",
        "ALLOW GROUP ${oci_identity_group.sys_admins.name} to read all-resources IN TENANCY",
      ]
    }
    
    resource "oci_identity_policy" "storage_admins" {
      name           = "StorageAdmins.pl"
      description    = "StorageAdmins.pl"
      compartment_id = "${var.tenancy_ocid}"
    
      statements = [
        "ALLOW GROUP ${oci_identity_group.storage_admins.name} to manage object-family IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.storage_admins.name} to manage volume-family IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.storage_admins.name} to read all-resources IN TENANCY",
      ]
    }
    
    resource "oci_identity_policy" "db_admins" {
      name           = "DBAdmins.pl"
      description    = "DBAdmins.pl"
      compartment_id = "${var.tenancy_ocid}"
    
      statements = [
        "ALLOW GROUP ${oci_identity_group.db_admins.name} manage database-family IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.db_admins.name} read all-resources IN TENANCY",
      ]
    }
    
    resource "oci_identity_policy" "network_admins" {
      name           = "NetworkAdmins.pl"
      description    = "NetworkAdmins.pl"
      compartment_id = "${var.tenancy_ocid}"
    
      statements = [
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to manage vcns IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to manage subnets IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to manage route-tables IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to manage dhcp-options IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to manage drgs IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to manage cross-connects IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to manage cross-connect-groups IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to manage virtual-circuits IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to manage vnics IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to manage vnic-attachments IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to manage load-balancers IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to use virtual-network-family IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.network_admins.name} to read all-resources IN TENANCY",
      ]
    }
    
    resource "oci_identity_policy" "net_sec_admins" {
      name           = "NetSecAdmins.pl"
      description    = "NetSecAdmins.pl"
      compartment_id = "${var.tenancy_ocid}"
    
      statements = [
        "ALLOW GROUP ${oci_identity_group.net_sec_admins.name} to manage security-lists IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.net_sec_admins.name} to manage internet-gateways IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.net_sec_admins.name} to manage cpes IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.net_sec_admins.name} to manage ipsec-connections IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.net_sec_admins.name} to use virtual-network-family IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.net_sec_admins.name} to manage load-balancers IN TENANCY",
        "ALLOW GROUP ${oci_identity_group.net_sec_admins.name} to read all-resources IN TENANCY",
      ]
    }
    
    resource "oci_identity_policy" "read_only" {
      name           = "ReadOnly.pl"
      description    = "ReadOnly.pl"
      compartment_id = "${var.tenancy_ocid}"
    
      statements = ["ALLOW GROUP ${oci_identity_group.read_only.name} to read all-resources IN TENANCY"]
    }
  4. Creare un file denominato iam_outputs.tf e incollare il seguente codice nel file.
    In questo codice, Terraform visualizza gli ID delle risorse dopo che sono state create.
    output "db_admins_id" {
      value = "${oci_identity_group.db_admins.id}"
    }
    
    output "iam_admin_managers_id" {
      value = "${oci_identity_group.iam_admin_managers.id}"
    }
    
    output "iam_managers_id" {
      value = "${oci_identity_group.iam_managers.id}"
    }
    
    output "net_sec_admins_id" {
      value = "${oci_identity_group.net_sec_admins.id}"
    }
    
    output "network_admins_id" {
      value = "${oci_identity_group.network_admins.id}"
    }
    
    output "read_only_id" {
      value = "${oci_identity_group.read_only.id}"
    }
    
    output "storage_admins_id" {
      value = "${oci_identity_group.storage_admins.id}"
    }
    
    output "sys_admins_id" {
      value = "${oci_identity_group.sys_admins.id}"
    }