Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

Azure - New-AzureRmADServicePrincipal / New-AzureRmRoleAssignment 명령어

지난 글에서,

Azure - PowerShell로 Access control(IAM)에 새로운 계정 만드는 방법
; https://www.sysnet.pe.kr/2/0/11479

계정 생성 및 권한 부여를 다음과 같은 명령어로 요약할 수 있습니다.

PS C:> Login-AzureRmAccount

PS C:> $plainText = "TestPlainText"
PS C:> $secureString = ConvertTo-SecureString $plainText -AsPlainText -Force

PS C:> $sp = New-AzureRmADServicePrincipal -DisplayName "NewUser1" -Password $secureString

PS C:> New-AzureRmRoleAssignment -ServicePrincipalName $sp.ApplicationId -RoleDefinitionName Contributor

일단 New-AzureRmADServicePrincipal은,

New-AzureRmADServicePrincipal
; https://docs.microsoft.com/en-us/powershell/module/azurerm.resources/new-azurermadserviceprincipal?view=azurermps-5.7.0

"Creates a new azure active directory service principal."라는 설명에도 나오지만 Azure Active Directory에 사용자를 생성합니다. 그다음 New-AzureRmRoleAssignment는 Azure 리소스의 Access control에 권한을 부여하는 것입니다. 보시면, New-AzureRmRoleAssignment 명령어에 별도의 리소스 위치를 지정하지 않았으므로 해당 사용자는 구독 수준의 Access control에 Contributor role이 부여됩니다.

그런데 New-AzureRmADServicePrincipal 명령어의 결과를 확인할 수 있는 방법이 현재의 Azure Portal에서는 제공되지 않습니다. 즉, AAD에 생성된 계정은 Azure Portal의 AAD 메뉴에서는 볼 수 없고, 대신 New-AzureRmRoleAssignment로 Azure 리소스의 Access control에 "App" 타입으로 생성된 것을 확인할 수 있습니다.

그래도 분명히 해당 계정이 AAD에 생성되어 있는 것은 맞습니다. 왜냐하면 New-AzureRmRoleAssignment 명령을 실행하지 않은 상태에서 다음과 같이 다시 동일한 사용자 이름으로 New-AzureRmADServicePrincipal 명령을 내리면,

PS C:\WINDOWS\system32> $sp = New-AzureRmADServicePrincipal -DisplayName "NewUser1" -Password $secureString
New-AzureRmADServicePrincipal : Another object with the same value for property identifierUris already exists.
At line:1 char:7
+ $sp = New-AzureRmADServicePrincipal -DisplayName "NewUser1" -Password ...
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-AzureRmADServicePrincipal], Exception
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ActiveDirectory.NewAzureADServicePrincipalCommand

이미 등록된 유저라고 오류가 발생하기 때문입니다. 그렇다면, 문제는 해당 사용자를 어떻게 삭제하느냐입니다. "Azure Active Directory" 메뉴로 가도 목록에는 해당 사용자가 나타나지 않기 때문에 당연히 Azure Portal을 통해서는 삭제할 수 없습니다. 대신 PowerShell 명령어로 가능합니다.

이를 위해 Get-AzureRmADServicePrincipal 명령을 내려 ObjectId를 확인한 후,

PS C:\WINDOWS\system32> Get-AzureRmADServicePrincipal -SearchString "NewUser1"

ServicePrincipalNames : {http://NewUser1, 5c7c5d23-0449-4d8d-8cd8-81e75985c802}
ApplicationId         : 5c7c5d23-0449-4d8d-8cd8-81e75985c802
DisplayName           : NewUser1
Id                    : 927a257b-b08e-42c3-9d3d-e564e2b95795
Type                  : ServicePrincipal

Remove-AzureRmADServicePrincipal 명령으로 삭제할 수 있습니다.

PS C:\WINDOWS\system32> Remove-AzureRmADServicePrincipal -ObjectId 927a257b-b08e-42c3-9d3d-e564e2b95795

이후 다음의 명령어로 실제로 삭제되었는지 확인해 볼 수 있습니다.

Get-AzureRmADServicePrincipal -SearchString "NewUser1"

재미있는 것은, 분명히 AAD에서 삭제는 되었지만 이 상태에서 동일한 계정명으로 New-AzureRmADServicePrincipal 명령어를 실행하면 여전히 "Another object with the same value for property identifierUris already exists" 오류가 발생합니다.

이유는 간단합니다. New-AzureRmADServicePrincipal은 AAD에 사용자 계정과 함께 동일한 이름으로 Application을 생성해 두기 때문이라고 합니다.

Creation of user fails after deletion of user with same signInName
; https://stackoverflow.com/questions/39981988/creation-of-user-fails-after-deletion-of-user-with-same-signinname

그래서, Get-AzureRmADApplication 명령을 내리면 동일한 이름의 응용 프로그램 항목을 볼 수 있고 마찬가지로 출력된 ObjectId로 삭제해야 합니다.

PS C:\> Get-AzureRmADApplication

...[생략]...

DisplayName             : NewUser1
ObjectId                : 7cb013b8-945a-4bff-a445-79ab599c47e8
IdentifierUris          : {http://NewUser1}
HomePage                : http://NewUser1
Type                    : Application
ApplicationId           : 5c7c5d23-0449-4d8d-8cd8-81e75985c802
AvailableToOtherTenants : False
AppPermissions          : 
ReplyUrls               : {}

PS C:\> Remove-AzureRmADApplication -ObjectId 7cb013b8-945a-4bff-a445-79ab599c47e8

정리해 보면, New-AzureRmADServicePrincipal은 명령어 수행 시 다음과 같은 2가지 역할을 수행합니다.

  • AAD에 사용자 계정 등록
  • Application 등록




New-AzureRmADServicePrincipal/New-AzureRmRoleAssignment 명령어로 생성되는 3가지 항목 중에,

  1. AAD에 사용자 계정 등록
  2. Application 등록
  3. Azure 구독의 리소스에 AAD 사용자에 대한 Role

첫 번째 "AAD에 사용자 계정 등록" 확인은 Get-AzureRmADServicePrincipal 명령어로만 할 수 있습니다.

두 번째 "Application 등록"은 Azure Portal에서 "App registrations(앱 등록)"라는 메뉴를 통해 들어가야 하는데, 문제는 기본적으로 이 메뉴가 목록에 없다는 것입니다. 따라서 다음의 글에 설명한 데로,

Azure Portal에서 구독(Subscriptions) 메뉴가 보이지 않는 경우
; https://www.sysnet.pe.kr/2/0/11496

"모든 서비스"로 들어가 "보안 + ID" 범주의 "App registrations(앱 등록)" 메뉴를 선택해 둡니다. 그럼, 해당 메뉴를 통해 New-AzureRmADServicePrincipal 명령어로 생성한 Application 목록을 확인할 수 있습니다.

마지막으로 세 번째 "Azure 구독의 리소스에 AAD 사용자에 대한 Role" 역시 Azure Portal에서 해당 Azure 리소스에 들어가 "Access control" 메뉴를 통해 볼 수 있습니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 4/17/2018]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  69  70  71  [72]  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
11840정성태3/13/201911276오류 유형: 526. 윈도우 10 Ubuntu App 환경에서는 USB 외장 하드 접근 불가
11839정성태3/12/201914016디버깅 기술: 124. .NET Core 웹 앱을 호스팅하는 Azure App Services의 프로세스 메모리 덤프 및 windbg 분석 개요 [3]
11838정성태3/7/201916796.NET Framework: 811. (번역글) .NET Internals Cookbook Part 1 - Exceptions, filters and corrupted processes [1]파일 다운로드1
11837정성태3/6/201926402기타: 74. 도서: 시작하세요! C# 7.3 프로그래밍 [10]
11836정성태3/5/201914341오류 유형: 525. Visual Studio 2019 Preview 4/RC - C# 8.0 Missing compiler required member 'System.Range..ctor' [1]
11835정성태3/5/201914098.NET Framework: 810. C# 8.0의 Index/Range 연산자를 .NET Framework에서 사용하는 방법 및 비동기 스트림의 컴파일 방법 [3]파일 다운로드1
11834정성태3/4/201913008개발 환경 구성: 432. Visual Studio 없이 최신 C# (8.0) 컴파일러를 사용하는 방법
11833정성태3/4/201913754개발 환경 구성: 431. Visual Studio 2019 - CMake를 이용한 공유/실행(so/out) 리눅스 프로젝트 설정파일 다운로드1
11832정성태3/4/201910803오류 유형: 524. Visual Studio CMake - rsync: connection unexpectedly closed
11831정성태3/4/201910369오류 유형: 523. Visual Studio 2019 - 새 창으로 뜬 윈도우를 닫을 때 비정상 종료
11830정성태2/26/201910193오류 유형: 522. 이벤트 로그 - Error opening event log file State. Log will not be processed. Return code from OpenEventLog is 87.
11829정성태2/26/201912083개발 환경 구성: 430. 마이크로소프트의 CoreCLR 프로파일러 예제 빌드 방법 - 리눅스 환경 [1]
11828정성태2/26/201918467개발 환경 구성: 429. Component Services 관리자의 RuntimeBroker 설정이 2개 있는 경우 [8]
11827정성태2/26/201912387오류 유형: 521. Visual Studio - Could not start the 'rsync' command on the remote host, please install it using your system package manager.
11826정성태2/26/201912269오류 유형: 520. 우분투에 .NET Core SDK 설치 시 패키지 의존성 오류
11825정성태2/25/201917135개발 환경 구성: 428. Visual Studio 2019 - CMake를 이용한 리눅스 빌드 환경 설정 [1]
11824정성태2/25/201911930오류 유형: 519. The SNMP Service encountered an error while accessing the registry key SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration. [1]
11823정성태2/21/201913395오류 유형: 518. IIS 관리 콘솔이 뜨지 않는 문제
11822정성태2/20/201911543오류 유형: 517. docker에 설치한 MongoDB 서버로 연결이 안 되는 경우
11821정성태2/20/201912015오류 유형: 516. Visual Studio 2019 - This extension uses deprecated APIs and is at risk of not functioning in a future VS update. [1]
11820정성태2/20/201915133오류 유형: 515. 윈도우 10 1809 업데이트 후 "User Profiles Service" 1534 경고 발생
11819정성태2/20/201913806Windows: 158. 컴퓨터와 사용자의 SID(security identifier) 확인 방법
11818정성태2/20/201912717VS.NET IDE: 131. Visual Studio 2019 Preview의 닷넷 프로젝트 빌드가 20초 이상 걸리는 경우 [2]
11817정성태2/17/20199909오류 유형: 514. WinDbg Preview 실행 오류 - Error : DbgX.dll : WindowsDebugger.WindowsDebuggerException: Could not load dbgeng.dll
11816정성태2/17/201912404Windows: 157. 윈도우 스토어 앱(Microsoft Store App)을 명령행에서 직접 실행하는 방법
11815정성태2/14/201911294오류 유형: 513. Visual Studio 2019 - VSIX 설치 시 "The extension cannot be installed to this product due to prerequisites that cannot be resolved." 오류 발생
... 61  62  63  64  65  66  67  68  69  70  71  [72]  73  74  75  ...