> For the complete documentation index, see [llms.txt](https://vida03.gitbook.io/redteam/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vida03.gitbook.io/redteam/docker/defenses/apparmor.md).

# AppArmor

## Apresentação

**apparmor** é um módulo de segurança do linux que permite restringir certas atividades na máquina logado com tal usuário.

{% hint style="info" %}
AppArmor pode ser usado para o host linux também, assim como podemos implementar ele no nosso contêiner
{% endhint %}

## Implementation

**AppArmor profile** são os arquivos de configurações que o linux irá ler para aplicar as regras, você pode ver como esses arquivos podem ser criados [**aqui**](https://ubuntu.com/tutorials/beginning-apparmor-profile-development#3-generating-a-basic-profile)

```
#include <tunables/global>
profile apparmor-profile flags=(attach_disconnected,mediate_deleted) {
  #include <abstractions/base>
  file,
  network,
  capability,
  deny /tmp/** w,
  deny /etc/passwd rwklx,
}
```

No meu caso estarei utilizando essa regra para demonstração, o que ela faz:

* Não permite a criação de escrita no diretório /tmp/
* Não permite o acesso ao arquivo /etc/passwd

Primeiro vamos carregar o profile no sistema com o comando:

```
sudo apparmor_parser -r -W <APPARMOR_PROFILE_FILE>
```

Logo após podemos utilizar a flag **--security-opt** com o argumento indiciando que a opção de segurança será o **apparmor**

```
docker run -it --rm --security-opt apparmor=<APPARMOR_PROFILE_FILE> <IMAGE_NAME> sh
```

<figure><img src="/files/URrA9c7giCl6T3Nb4wh3" alt=""><figcaption></figcaption></figure>

## Conclusão

Conseguimos com o auxilío de módulos de segurança do kernel do linux implementar mais segurança para o nosso contêiner, utilizando regras para permitir certas execuções no contêiner.


---

# 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, and the optional `goal` query parameter:

```
GET https://vida03.gitbook.io/redteam/docker/defenses/apparmor.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
