# Simulando um Ambiente de Runbook

## Overview

### Criar um Registro de Aplicativo

Criamos um Registro de Aplicativo do Azure para simular o login no estilo de aplicativo no Microsoft Entra.

<figure><img src="/files/fe256ee68c11d5e284aa7d324ee27da3057ea507" alt=""><figcaption><p>Criar um Registro de Aplicativo</p></figcaption></figure>

### Conceder Permissões

Concederemos as mesmas permissões que a identidade gerenciada teria. Usaremos o mesmo [AppRoleGranter Toolkit](https://github.com/hcoberdalhoff/approle-and-directoryrole-granter) para esse propósito.

Substitua `{AppRegObjectId}` pelo ID do objeto do seu registro de aplicativo.

```powershell
git clone https://github.com/hcoberdalhoff/approle-and-directoryrole-granter.git
cd "approle-and-directoryrole-granter\RealmJoinVnext"
. .\AllInOne.ps1 -appRegObjectId "{AppRegObjectId}"
```

### Criar e enviar um certificado de desenvolvimento

Ver [aqui ](https://github.com/realmjoin/RealmJoin.RunbookHelper/blob/main/DevCertificates.ps1)para um exemplo de como criar um RunbookHelper Dev-Certificate. Substitua `{Variables}` de acordo.

O `{AppID}` refere-se ao App / Client ID do Application Regsitrations.

Se você não tiver um ID de assinatura específico, basta usar uma assinatura padrão do seu Tenant. (Na maioria dos casos, isso não importa.)

```powershell
New-SelfSignedCertificate -Subject 'CN=AzureRunAsConnection, OU={AppID}, DC={TenantID}, O={SubscriptionID}' `
    -CertStoreLocation "cert:\CurrentUser\My" -NotAfter (Get-Date).AddYears(10) -KeySpec Signature | `
    Export-Certificate -FilePath "AzureRunAsConnection.cer"
```

Você obterá um arquivo `AzureRunAsConnection.cer` que você envia para os segredos do Application Registration.

{% hint style="info" %}
Se você quiser atender a vários aplicativos / ambientes, pode substituir o padrão "AzureRunAsConnection" em`CN=AzureRunAsConnection` por um nome personalizado ao criar o certificado para esse ambiente.

Você pode então selecionar qual ambiente/certificado (por exemplo, "OtherEnv") conectar usando `Connect-RjRbGraph -AutomationConnectionName "OtherEnv"`

Dessa forma, você pode acessar vários ambientes a partir da mesma máquina.
{% endhint %}

<figure><img src="/files/500f70714135a3cfef6d68b93f97d467ee97e4a3" alt=""><figcaption><p>Upload do certificado</p></figcaption></figure>

### Utilização

Apenas use `Connect-RjRbGraph` para autenticar no aplicativo.

Certifique-se de remover certificados de desenvolvimento mais antigos usando mmc.exe do seu conjunto de certificados pessoais, se houver, para evitar conflitos/falhas de login.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.realmjoin.com/pt/dev-reference/simulating-a-runbook-environment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
