> For the complete documentation index, see [llms.txt](https://docs.realmjoin.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.realmjoin.com/pt/dev-reference/simulating-a-runbook-environment.md).

# Simular um ambiente de Runbook

## Visão geral

### Criar um registo de aplicação

Criamos um registo de aplicação Azure para simular o início de sessão do tipo aplicação no Microsoft Entra.

<figure><img src="/files/fe256ee68c11d5e284aa7d324ee27da3057ea507" alt=""><figcaption><p>Criar um registo de aplicação</p></figcaption></figure>

### Conceder permissões

Vamos conceder as mesmas permissões que a identidade gerida teria. Vamos usar o mesmo [AppRoleGranter Toolkit](https://github.com/hcoberdalhoff/approle-and-directoryrole-granter) para esse fim.

Substitua `{AppRegObjectId}` pelo ID de objeto do seu registo de aplicação.

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

### Criar e carregar um certificado de desenvolvimento

Veja [aqui ](https://github.com/realmjoin/RealmJoin.RunbookHelper/blob/main/DevCertificates.ps1)para um exemplo de como criar um certificado de desenvolvimento do RunbookHelper. Substitua `{Variables}` em conformidade.

O `{AppID}` refere-se ao App / ID do cliente dos Registos de Aplicações.

Se não tiver um ID de subscrição específico, use simplesmente uma subscrição predefinida 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 ficheiro `AzureRunAsConnection.cer` que carrega para os segredos do registo de aplicação.

{% hint style="info" %}
Se quiser servir várias apps / ambientes, pode substituir o "AzureRunAsConnection" predefinido em`CN=AzureRunAsConnection` por um nome personalizado ao criar o certificado para esse ambiente.

Pode então selecionar qual o ambiente/certificado (por exemplo, "OtherEnv") para ligar usando `Connect-RjRbGraph -AutomationConnectionName "OtherEnv"`

Desta forma, pode aceder a vários ambientes a partir da mesma máquina.
{% endhint %}

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

### Utilização

Basta usar `Connect-RjRbGraph` para autenticar na app.

Certifique-se de remover certificados de desenvolvimento mais antigos usando o mmc.exe dos seus certificados pessoais, se existirem, para evitar conflitos/falhas de início de sessão.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.
