자습서: Azure PowerShell을 사용하여 Azure 리소스에 대한 사용자 액세스 권한 부여

Azure RBAC(Azure 역할 기반 액세스 제어)는 Azure 리소스에 대한 액세스를 관리하는 방법입니다. 이 자습서에서는 Azure PowerShell을 사용하여 구독의 모든 항목을 보고 리소스 그룹의 모든 항목을 관리할 수 있는 액세스 권한을 사용자에게 부여합니다.

이 자습서에서는 다음을 하는 방법을 알아볼 수 있습니다.

  • 다른 범위에서 사용자에 대한 액세스 권한 부여
  • 액세스 권한 나열
  • 액세스 권한 제거

Azure 구독이 아직 없는 경우 시작하기 전에 체험 계정을 만듭니다.

참고 항목

Azure Az PowerShell 모듈을 사용하여 Azure와 상호 작용하는 것이 좋습니다. 시작하려면 Azure PowerShell 설치를 참조하세요. Az PowerShell 모듈로 마이그레이션하는 방법에 대한 자세한 내용은 Azure PowerShell을 AzureRM에서 Azure로 마이그레이션을 참조하세요.

필수 조건

이 자습서를 완료하려면 다음 항목이 필요합니다.

역할 할당

Azure RBAC에서 액세스 권한을 부여하기 위해 역할 할당을 만듭니다. 역할 할당은 보안 주체, 역할 정의, 범위의 세 가지 요소로 구성됩니다. 이 자습서에서는 다음과 같은 두 가지 역할 할당을 수행할 것입니다.

할당할 수 있습니다. 역할 정의 범위
사용자
(RBAC 자습서 사용자)
판독기 구독
사용자
(RBAC 자습서 사용자)
기여자 Resource group
(rbac-tutorial-resource-group)

Role assignments for a user

사용자 만들기

역할을 할당하려면 사용자, 그룹 또는 서비스 주체가 필요합니다. 사용자가 아직 없는 경우 만들 수 있습니다.

  1. Azure Cloud Shell에서 암호 복잡성 요구 사항을 준수하는 암호를 만듭니다.

    $PasswordProfile = @{ Password = "<Password>" }
    
  2. New-MgUser 명령을 사용하여 기본 새 사용자를 만듭니다.

    New-MgUser -DisplayName "RBAC Tutorial User" -PasswordProfile $PasswordProfile `
       -UserPrincipalName "rbacuser@example.com" -AccountEnabled:$true -MailNickName "rbacuser"
    
    DisplayName        Id                                   Mail UserPrincipalName
    -----------        --                                   ---- -----------------
    RBAC Tutorial User 11111111-1111-1111-1111-111111111111      rbacuser@example.com
    

리소스 그룹 만들기

리소스 그룹을 사용하여 리소스 그룹 범위에서 역할을 할당하는 방법을 보여줍니다.

  1. Get-AzLocation 명령을 사용하여 지역 위치 목록을 가져옵니다.

    Get-AzLocation | select Location
    
  2. 가까운 위치를 선택하고 변수에 할당합니다.

    $location = "westus"
    
  3. New-AzResourceGroup 명령을 사용하여 새 리소스 그룹을 만듭니다.

    New-AzResourceGroup -Name "rbac-tutorial-resource-group" -Location $location
    
    ResourceGroupName : rbac-tutorial-resource-group
    Location          : westus
    ProvisioningState : Succeeded
    Tags              :
    ResourceId        : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rbac-tutorial-resource-group
    

액세스 허가

사용자에게 액세스 권한을 부여하려면 New-AzRoleAssignment 명령을 사용하여 역할을 할당합니다. 보안 주체, 역할 정의 및 범위를 지정해야 합니다.

  1. Get-AzSubscription 명령을 사용하여 구독 ID를 가져옵니다.

    Get-AzSubscription
    
    Name     : Pay-As-You-Go
    Id       : 00000000-0000-0000-0000-000000000000
    TenantId : 22222222-2222-2222-2222-222222222222
    State    : Enabled
    
  2. 구독 범위를 변수에 저장합니다.

    $subScope = "/subscriptions/00000000-0000-0000-0000-000000000000"
    
  3. 구독 범위에서 사용자에게 읽기 권한자 역할을 할당합니다.

    New-AzRoleAssignment -SignInName rbacuser@example.com `
      -RoleDefinitionName "Reader" `
      -Scope $subScope
    
    RoleAssignmentId   : /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleAssignments/44444444-4444-4444-4444-444444444444
    Scope              : /subscriptions/00000000-0000-0000-0000-000000000000
    DisplayName        : RBAC Tutorial User
    SignInName         : rbacuser@example.com
    RoleDefinitionName : Reader
    RoleDefinitionId   : acdd72a7-3385-48ef-bd42-f606fba81ae7
    ObjectId           : 11111111-1111-1111-1111-111111111111
    ObjectType         : User
    CanDelegate        : False
    
  4. 리소스 그룹 범위에서 사용자에게 기여자 역할을 할당합니다.

    New-AzRoleAssignment -SignInName rbacuser@example.com `
      -RoleDefinitionName "Contributor" `
      -ResourceGroupName "rbac-tutorial-resource-group"
    
    RoleAssignmentId   : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rbac-tutorial-resource-group/providers/Microsoft.Authorization/roleAssignments/33333333-3333-3333-3333-333333333333
    Scope              : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rbac-tutorial-resource-group
    DisplayName        : RBAC Tutorial User
    SignInName         : rbacuser@example.com
    RoleDefinitionName : Contributor
    RoleDefinitionId   : b24988ac-6180-42a0-ab88-20f7382dd24c
    ObjectId           : 11111111-1111-1111-1111-111111111111
    ObjectType         : User
    CanDelegate        : False
    

액세스 권한 나열

  1. 구독에 대한 액세스를 확인하려면 Get-AzRoleAssignment 명령을 사용하여 역할 할당을 나열합니다.

    Get-AzRoleAssignment -SignInName rbacuser@example.com -Scope $subScope
    
    RoleAssignmentId   : /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleAssignments/22222222-2222-2222-2222-222222222222
    Scope              : /subscriptions/00000000-0000-0000-0000-000000000000
    DisplayName        : RBAC Tutorial User
    SignInName         : rbacuser@example.com
    RoleDefinitionName : Reader
    RoleDefinitionId   : acdd72a7-3385-48ef-bd42-f606fba81ae7
    ObjectId           : 11111111-1111-1111-1111-111111111111
    ObjectType         : User
    CanDelegate        : False
    

    출력에서 읽기 권한자 역할이 구독 범위의 RBAC 자습서 사용자에게 할당된 것을 볼 수 있습니다.

  2. 리소스 그룹에 대한 액세스 권한을 확인하려면 Get-AzRoleAssignment 명령을 사용하여 역할 할당을 나열합니다.

    Get-AzRoleAssignment -SignInName rbacuser@example.com -ResourceGroupName "rbac-tutorial-resource-group"
    
    RoleAssignmentId   : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rbac-tutorial-resource-group/providers/Microsoft.Authorization/roleAssignments/33333333-3333-3333-3333-333333333333
    Scope              : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rbac-tutorial-resource-group
    DisplayName        : RBAC Tutorial User
    SignInName         : rbacuser@example.com
    RoleDefinitionName : Contributor
    RoleDefinitionId   : b24988ac-6180-42a0-ab88-20f7382dd24c
    ObjectId           : 11111111-1111-1111-1111-111111111111
    ObjectType         : User
    CanDelegate        : False
    
    RoleAssignmentId   : /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleAssignments/22222222-2222-2222-2222-222222222222
    Scope              : /subscriptions/00000000-0000-0000-0000-000000000000
    DisplayName        : RBAC Tutorial User
    SignInName         : rbacuser@example.com
    RoleDefinitionName : Reader
    RoleDefinitionId   : acdd72a7-3385-48ef-bd42-f606fba81ae7
    ObjectId           : 11111111-1111-1111-1111-111111111111
    ObjectType         : User
    CanDelegate        : False
    

    출력에서 기여자 역할과 읽기 권한자 역할이 모두 RBAC 자습서 사용자에게 할당된 것을 볼 수 있습니다. 기여자 역할은 rbac-tutorial-resource-group 범위에 있으며 읽기 권한자 역할은 구독 범위에서 상속됩니다.

(선택 사항) Azure Portal을 사용하여 액세스 나열

  1. Azure Portal에서 역할 할당이 어떻게 표시되는지 확인하려면 구독에 대한 액세스 제어(IAM) 블레이드를 확인합니다.

    Role assignments for a user at subscription scope

  2. 리소스 그룹에 대한 액세스 제어(IAM) 블레이드를 봅니다.

    Role assignments for a user at resource group scope

액세스 권한 제거

사용자, 그룹 및 애플리케이션에 대한 액세스를 제거하려면 Remove-AzRoleAssignment를 사용하여 역할 할당을 제거합니다.

  1. 다음 명령을 사용하여 리소스 그룹 범위에서 사용자에 대한 기여자 역할 할당을 제거합니다.

    Remove-AzRoleAssignment -SignInName rbacuser@example.com `
      -RoleDefinitionName "Contributor" `
      -ResourceGroupName "rbac-tutorial-resource-group"
    
  2. 다음 명령을 사용하여 구독 범위에서 사용자에 대한 읽기 권한자 역할 할당을 제거합니다.

    Remove-AzRoleAssignment -SignInName rbacuser@example.com `
      -RoleDefinitionName "Reader" `
      -Scope $subScope
    

리소스 정리

이 자습서에서 만든 리소스를 클린 리소스 그룹 및 사용자를 삭제합니다.

  1. Remove-AzResourceGroup 명령을 사용하여 리소스 그룹을 제거합니다.

    Remove-AzResourceGroup -Name "rbac-tutorial-resource-group"
    
    Confirm
    Are you sure you want to remove resource group 'rbac-tutorial-resource-group'
    [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):
    
  2. 확인하라는 메시지가 표시되면 Y를 입력합니다. 삭제하는 데 몇 초 정도 걸립니다.

  3. Remove-MgUser 명령을 사용하여 사용자를 삭제합니다.

    $User = Get-MgUser -Filter "DisplayName eq 'RBAC Tutorial User'"
    Remove-MgUser -UserId $User.Id
    

다음 단계