ARTICLES

Articles

A space for writing about engineering, security and operations.

What precautions should we take when using a mobile device in the corporate world ?

In principle, when we are in a company, we follow all the security approaches and guidelines imposed by the organization, which is more than expected. Examples include: standards for industry payments regulated within the corporation, such as PCI-DSS, or pre-established security policies in the case of large multinationals, such as ISO 27001.

These approaches range from clean desk policies, screen protections with passwords, biometrics on laptops, disabling the use of USB ports, anti-theft locks to secure devices to your desk, encryption of data stored in operating systems like Linux with LUKS or Windows with BitLocker, restrictions on penetration testing for security vulnerabilities using SELinux in open systems, the use of access cards and notifications of your activity when passing through internal security upon entering the company or restricted environments (e.g., reception, data centers, and sensitive departments like HR or Finance, which are restricted by function), restrictions on website usage or software installation (via proxies and web filters through firewalls), which prevent data leaks or espionage by security agencies, and, most importantly, confidentiality agreements regarding client information when we are hired.

This information can be disseminated within a company through instructions to employees via communication channels such as leadership, or through security policies contained in documentation or the intranet.

However, in the current world we live in, we are almost daily connected through a corporate or personal smartphone (BYOD — Bring Your Own Device). Many of these measures are neglected depending on the company’s culture and size.

Often, we overlook simple issues, and due to time and productivity concerns, we have corporate email, client documentation, phone numbers, or data stored in the cloud installed on our devices, which could potentially be leaked, for example.

For this reason, it becomes increasingly necessary to adopt protective measures with simple tools that, in the event of theft or misuse of your device, provide restrictive layers to prevent the improper circulation of data.

That’s why I think it’s worth considering the security of your smartphone or laptop with tools that align with the company’s internal policy and can be incorporated.

On the Electronic Frontier Foundation (EFF) website below, there are several tools and approaches that I found interesting:

  • Two-factor authentication (2FA) — Apps like Authy, Google Authenticator, and Microsoft Authenticator.
  • Signal app, a messenger similar to tools like Telegram and WhatsApp.
  • Data removal protection measures.
  • Password vaults: Apps for storing passwords with 2FA, such as KeePassXC (which supports cryptographic keys and a challenge when the password database is modified — it’s not natively 2FA), or LastPass with 2FA, which isn’t the EFF’s focus as it’s proprietary but offers free use with limitations.
  • Another free tool is a clone of TrueCrypt (used by Eike Batista to encrypt hard drive data) called VeraCrypt, an application that stores your data in a file that, when mounted, becomes a disk drive. In other words, if you want to store 100GB, you’ll have a file of that size, and when mounted, it becomes a drive with that capacity. This app, when used on a laptop, enables the creation of data containers that can only be opened with a master password — one that must never be forgotten! For those who prefer something native to Windows, the same can be done with BitLocker Virtual Hard Drive (VHD).

It’s also worth noting that there are U2F/FIDO keys (Universal 2nd Factor) that serve as a security measure against data leaks (e.g., Yubikey). These currently come in both USB and NFC versions for mobile devices.

Note that among these tools, there are ways to enhance security actions via VPNs, for example, as well as additional layers of protection like the TOR software — which has been targeted by police operations but can easily be restricted through the operating system, network, and, most importantly, compliance (validation) with the company’s internal policies.

As the EFF is an organization from the early days of the internet, it fights for digital privacy, free expression, and innovation, with a focus on ensuring self-protection against surveillance (they advocate for an internet free from corporate control). However, this doesn’t invalidate the tools discussed in the link below for beneficial use, because just as a tool can be misused, we can also protect corporate data with these same tools. When well-utilized and agreed upon in internal policies, they become extremely useful.

Useful tools: https://ssd.eff.org/pt-br/module-categories/guias-de-ferramentas

List of sites and whether they support 2FA: https://twofactorauth.org/#social

How to Perform a Secure Backup of a Linux Desktop to an AWS S3 Bucket

Step 1: Install and Configure the AWS CLI

If you don’t have the AWS CLI installed, use:

sudo apt update
sudo apt install awscli -y

Configure your credentials with aws configure:

aws configure

Step 2: Create a Secure S3 Bucket

Create a secure S3 bucket:

aws s3api create-bucket --bucket my-secure-backup --region us-east-1

1. Block public access to the bucket:

aws s3api put-public-access-block \
  --bucket my-secure-backup \
  --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true

2. Enable automatic encryption:

aws s3api put-bucket-encryption \
  --bucket my-secure-backup \
  --server-side-encryption-configuration '{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}'

This ensures the bucket has no public access and the files are encrypted.

Step 3: Compress Important Directories

Compress the main directories before uploading to S3 (the backup file will include integrity verification via SHA256 hash):

sudo tar -czvf backup_linux.tar.gz /home /etc /var /root /usr/local /opt /srv
sha256sum backup_linux.tar.gz > backup_linux.sha256

Step 4: Perform a Secure Upload to S3

aws s3 cp backup_linux.tar.gz s3://my-secure-backup/

📌 Ensure the file is not public:

aws s3api put-object-acl --bucket my-secure-backup --key backup_linux.tar.gz --acl private

Step 5: Restore the Backup on a New System

Download the backup and restore the files with SHA256 integrity verification:

aws s3 cp s3://my-secure-backup/backup_linux.tar.gz .
sha256sum -c backup_linux.sha256 && sudo tar -xzvf backup_linux.tar.gz -C /

Step 6: Automation with Cron Job (Optional)

sudo crontab -e
0 3 * * * sudo tar -czvf /root/backup_linux.tar.gz /home /etc /var /root /usr/local /opt /srv && aws s3 cp /root/backup_linux.tar.gz s3://my-secure-backup/

🎯 Security Summary Implemented:

  • ✅ S3 bucket with public access blocked.
  • ✅ AES-256 encryption enabled on the bucket.
  • ✅ File uploads with private permissions.

Automated Script:

#!/bin/bash
# Secure backup of key Linux directories using AWS CLI and S3
# Author: Marlon Bastida
# Date: $(date +%Y-%m-%d)

# Variables
BUCKET_NAME="my-secure-backup"
BACKUP_FILE="/root/backup_linux_$(date +%Y%m%d).tar.gz"
REGION="us-east-1"

# Create a secure S3 bucket (only if it doesn’t already exist)
echo "Creating the secure S3 bucket (if necessary)..."
aws s3api create-bucket --bucket $BUCKET_NAME --region $REGION 2>/dev/null

# Block public access to the bucket
echo "Configuring bucket security..."
aws s3api put-public-access-block \
    --bucket $BUCKET_NAME \
    --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true

# Enable automatic encryption
aws s3api put-bucket-encryption \
    --bucket $BUCKET_NAME \
    --server-side-encryption-configuration '{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}'

# Compress directories
echo "Compressing directories..."
sudo tar -czvf $BACKUP_FILE /home /etc /var /root /usr/local /opt /srv

# Upload the file to S3
echo "Uploading the backup to S3..."
aws s3 cp $BACKUP_FILE s3://$BUCKET_NAME/

# Ensure the file has no public access
echo "Ensuring private permissions on the file..."
aws s3api put-object-acl --bucket $BUCKET_NAME --key $(basename $BACKUP_FILE) --acl private

echo "Backup completed successfully!"

# Add to cron for daily execution
if ! sudo crontab -l | grep -q "$BACKUP_FILE"; then
    echo "Automating the backup with cron..."
    (sudo crontab -l ; echo "0 3 * * * /bin/bash /root/backup_script.sh") | sudo crontab -
fi

echo "Automation completed!"

📌 How to Use the Script:

1. Save the script to a file, e.g., /root/backup_script.sh.

2. Grant execution permissions:

sudo chmod +x /root/backup_script.sh

3. Run it manually:

sudo /root/backup_script.sh

4. Verify the cron job was added:

sudo crontab -l

🎯 What the Script Does:

  • Creates a secure S3 bucket (if it doesn’t exist).
  • Blocks public access and enables AES-256 encryption.
  • Compresses the main directories.
  • Uploads to S3 with private permissions.
  • Sets up daily automation via cron at 3 AM.

Alternatively, you can use an Ansible playbook:

Ansible Playbook: backup_sec.yml

---
- name: Secure Backup of Key Linux Directories to AWS S3
  hosts: localhost
  become: yes
  vars:
    bucket_name: "my-secure-backup"
    backup_file: "/root/backup_linux_{{ ansible_date_time.date }}.tar.gz"
    region: "us-east-1"
    directories_to_backup:
      - "/home"
      - "/etc"
      - "/var"
      - "/root"
      - "/usr/local"
      - "/opt"
      - "/srv"

  tasks:
    - name: Install AWS CLI (if not already installed)
      apt:
        name: awscli
        state: present
        update_cache: yes

    - name: Create the secure S3 bucket (if necessary)
      shell: |
        aws s3api create-bucket --bucket {{ bucket_name }} --region {{ region }} 2>/dev/null || echo "Bucket already exists"
      ignore_errors: yes

    - name: Block public access to the bucket
      aws_s3:
        bucket: "{{ bucket_name }}"
        region: "{{ region }}"
        acl: "private"
        state: "present"
        policy:
          Version: "2012-10-17"
          Statement:
            - Effect: "Deny"
              Principal: "*"
              Action: "s3:*"
              Resource:
                - "arn:aws:s3:::{{ bucket_name }}/*"
                - "arn:aws:s3:::{{ bucket_name }}"
              Condition:
                Bool:
                  aws:SecureTransport: "false"

    - name: Enable automatic encryption on the S3 bucket
      aws_s3_bucket:
        name: "{{ bucket_name }}"
        region: "{{ region }}"
        encryption:
          enabled: true
          encryption_algorithm: "AES256"

    - name: Compress directories for backup
      command: "tar -czvf {{ backup_file }} {{ item }}"
      with_items: "{{ directories_to_backup }}"

    - name: Generate SHA256 hash of the backup file
      command: "sha256sum {{ backup_file }} > {{ backup_file }}.sha256"

    - name: Upload the backup to S3
      s3:
        bucket: "{{ bucket_name }}"
        object: "{{ backup_file | basename }}"
        src: "{{ backup_file }}"
        acl: "private"
        mode: "put"

    - name: Ensure private permissions on the S3 file
      aws_s3:
        bucket: "{{ bucket_name }}"
        object: "{{ backup_file | basename }}"
        acl: "private"

    - name: Add cron job for daily backup
      cron:
        name: "Daily backup"
        minute: "0"
        hour: "3"
        job: "/usr/bin/tar -czvf /root/backup_linux_{{ ansible_date_time.date }}.tar.gz /home /etc /var /root /usr/local /opt /srv && /usr/bin/aws s3 cp /root/backup_linux_{{ ansible_date_time.date }}.tar.gz s3://{{ bucket_name }}/"
        state: present
        user: root

Playbook Explanation:

  • Install AWS CLI (if necessary): Ensures the AWS CLI is installed.
  • Create S3 Bucket: Attempts to create an S3 bucket with the specified name, ignoring errors if it already exists.
  • Block Public Access: Configures the S3 bucket to block public access and ensure data security.
  • Enable Automatic Encryption: Sets up the bucket to use AES-256 encryption.
  • Compress Directories: Uses the tar command to compress the specified directories.
  • Generate SHA256 Hash: Calculates the SHA256 hash of the compressed file for later verification.
  • Upload to S3: Uploads the compressed file to the S3 bucket with private permissions.
  • Automation with Cron: Configures a cron job to perform the backup daily at 3 AM.

How to Use:

1. Save the playbook: Save the content above in a YAML file, e.g., backup_sec.yml.

2. Run the playbook:

ansible-playbook backup_sec.yml

3. Verify Cron: The playbook also automatically sets up the cron job to ensure daily backups.

Creating a Kubernetes Lab with K3D on Windows 10\11 via WSL

Requirements:

  • Install Chocolatey
  • Install Windows Terminal
  • Install Visual Studio Code
  • Install Ubuntu 24.04.1 from the Microsoft Store
  • Install the latest stable PowerShell version 7.4.6 from GitHub
  • Install WSL 2
  • Install Docker Desktop
  • Install Kubectl

Project repository: https://github.com/mbastida43/appsimples.git

Installing Chocolatey via PowerShell:

Chocolatey website with the cmdlet for PowerShell
Chocolatey website with the cmdlet for PowerShell

Open a PowerShell terminal and run the following command:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Installing Chocolatey via PowerShell
Installing Chocolatey via PowerShell

Installing Windows Terminal:

Install it from the Microsoft Store, or in a PowerShell tab using winget (the default package manager) or Chocolatey:

Windows Terminal on Winget
Windows Terminal on Winget
winget install -e --id Microsoft.WindowsTerminal
Installing Windows Terminal with winget
Installing Windows Terminal with winget
choco install microsoft-windows-terminal

Installing Visual Studio Code

Known as vscode (Microsoft’s editor), install it using the executable, or in a PowerShell tab with winget (the default package manager) or Chocolatey:

Visual Studio Code on Winget
Visual Studio Code on Winget
winget install -e --id Microsoft.VisualStudioCode
Installing VS Code with Winget
Installing VS Code with Winget
choco install vscode

Installing Ubuntu 24.04 LTS

If you prefer, install it in a PowerShell tab with the following command:

wsl --install -d Ubuntu-24.04
Ubuntu 24.04 installation progress bar
Ubuntu 24.04 installation progress bar
Ubuntu installation and initial setup in WSL
Ubuntu installation and initial setup in WSL
Microsoft Store with Ubuntu 24.04.1 LTS
Microsoft Store with Ubuntu 24.04.1 LTS

Configuring WSL

Open Windows Terminal as Administrator with PowerShell and run the following commands. In a PowerShell tab, run this to enable WSL:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

To upgrade to WSL 2, you must be running Windows 10…

  • For x64 systems: version 1903 or later, with build 18362.1049 or later.
  • For ARM64 systems: version 2004 or later, with build 19041 or later.

Enable the virtual machine feature:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

List the installed distributions:

wsl --list --verbose
  NAME              STATE      VERSION
* Ubuntu-24.04      Stopped    2
  Ubuntu-20.04      Stopped    2
  Fedora            Stopped    2
  Ubuntu-22.04      Stopped    2
  docker-desktop    Stopped    2

Set the default distribution:

wsl --setdefault Ubuntu-24.04

Set WSL 2 as the default:

wsl --set-default-version 2

Installing Docker Desktop:

If you prefer, install using the executable, or open a PowerShell tab and install with winget (the default package manager) or Chocolatey:

Docker Desktop on Winget
Docker Desktop on Winget
winget install -e --id Docker.DockerDesktop
choco install docker-desktop
Use WSL 2 and add a desktop shortcut
Use WSL 2 and add a desktop shortcut
Installation…
Installation…

Configure the current distribution in the settings highlighted in yellow:

Docker Desktop settings
Docker Desktop settings

Select the distribution you want to use under Resources, WSL integration, to use Docker:

Docker Desktop resources
Docker Desktop resources

You could also install Docker Desktop via PowerShell with the following command:

Install Docker Desktop via PowerShell in Windows Terminal from the Downloads folder, where you downloaded Docker Desktop:

Start-Process Docker Desktop - Wait install

Check the Docker version with:

docker version
Shows the Docker version
Shows the Docker version

Installing Kubectl:

Open Windows Terminal in Ubuntu 24.04 and run:

Install kubectl from the repository,

Update the apt index and required packages:

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg

Download the public signing keys for the repositories:

# Se a pasta `/etc/apt/keyrings` não existir, ela deve ser criada antes
# sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
sudo chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg
# permitir que programas APT sem acesso privilegiado leiam este keyring

Add the Kubernetes apt repository:

echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.32/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo chmod 644 /etc/apt/sources.list.d/kubernetes.list
# ajuda ferramentas tais como command-not-found a funcionar corretamente

Update the apt repository index and install kubectl:

sudo apt-get update
sudo apt-get install -y kubectl

Installing a K3D cluster

Install K3D using a script, then verify the installation:

wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
k3d
K3D installation and execution test
K3D installation and execution test

This creates a cluster with 3 control planes, 3 worker nodes and a load balancer exposing external port 8080 to internal container port 30000 on the load balancer:

k3d cluster create meucluster --servers 3 --agents 3 -p "8080:30000@loadbalancer"
Creating the K3D cluster with 3 control planes, 3 worker nodes and a load balancer
Creating the K3D cluster with 3 control planes, 3 worker nodes and a load balancer

List cluster information:

kubectl cluster-info

And list the cluster components:

k3d cluster list
Creates the cluster, displays information and lists its components
Creates the cluster, displays information and lists its components
docker container ls
Lists the cluster containers
Lists the cluster containers

Creating an application for the cluster

Create the index.html file with the commands below (if you do not have the nano editor, run:

apt install nano
touch index.html
nano index.html
Creating and editing index.html
Creating and editing index.html

The index.html file:

<!DOCTYPE html>
<html lang="pt-br">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Selecione uma cor</title>
 <style>
  body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    margin: 0;
    background-color: #f4f4f4;
  }
  .button {
    margin: 10px;
    padding: 20px;
    font-size: 20px;
    cursor: pointer;
    border: none;
    border-radius: 5px;
    transition: all 0.3s;
  }
  .red { background-color: red; color: white; }
  .green { background-color: green; color: white; }
  .blue { background-color: blue; color: white; }
  h2 {
    font-size: 24px;
    font-weight: bold;
    color: #333;
  }
 </style>
</head>
<body>
 <h1>Selecione uma cor</h1>
 <button class="button red" onclick="showColor('Red')">Red</button>
 <button class="button green" onclick="showColor('Green')">Green</button>
 <button class="button blue" onclick="showColor('Blue')">Blue</button>
 <h2 id="colorOutput">Escolha uma cor clicando nos botões acima.</h2>
 <script>
  function showColor(color) {
    // Exibir o nome da cor escolhida no elemento com o id "colorOutput"
    document.getElementById('colorOutput').innerText = 'Você escolheu a cor: ' + color;
  }
 </script>
</body>
</html>

Create an nginx web server to run the application on port 8080. To do this, create the image using the following Dockerfile:

# Dockerfile
FROM nginx:alpine

# Copiar o arquivo HTML para o diretório de conteúdo do Nginx
COPY index.html /usr/share/nginx/html/index.html

# Expor a porta 8080
EXPOSE 8080

In the same directory as the Dockerfile and index.html, run the command below to build the Docker image:

docker build -t marlonbastida/cor-app .
Building the image
Building the image

Create the deploy.yaml file for the Kubernetes cluster with a deployment and service:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cor-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cor-app
  template:
    metadata:
      labels:
        app: cor-app
    spec:
      containers:
      - name: cor-app
        image: marlonbastida/cor-app:latest
        ports:
        - containerPort: 80 # Porta padrão do Nginx dentro do container
---
apiVersion: v1
kind: Service
metadata:
  name: cor-app-service
spec:
  selector:
    app: cor-app
  ports:
    - protocol: TCP
      port: 8080      # Porta exposta externamente pelo LoadBalancer
      targetPort: 80  # Porta do container (padrão Nginx)
      nodePort: 30000 # Porta mapeada no Node interno do cluster
  type: NodePort

Import the image into the cluster:

k3d image import cor-app:latest -c meucluster
Importing the image into the Kubernetes cluster
Importing the image into the Kubernetes cluster

Apply the YAML manifest file, deploy.yaml, to the Kubernetes (K3D) cluster:

kubectl apply -f deploy.yaml
Applying the deployment file
Applying the deployment file

Check the service:

kubectl get svc cor-app-service
kubectl get deployments
kubectl get pods
kubectl get services
kubectl get all
Lists services, pods, deployments, all
Lists services, pods, deployments, all

Once finished, open http://localhost:8080 in your browser and the application will appear:

Color selection application in the browser
Color selection application in the browser

Limit the memory used by the VMmem process in C:\Users\usuario\.wslconfig on Windows (if it is slow). If the file does not exist, create it and divide your memory by 2, for example 16GB -> 8GB, or adjust it to an amount that improves performance:

[wsl2]
memory=8GB # Limits VM memory in WSL 2 up to 3GB
processors=4 # Makes the WSL 2 VM use two virtual processors]

Sources:

Source: https://documentation.ubuntu.com/wsl/en/latest/guides/install-ubuntu-wsl2/

Source: https://chocolatey.org/install

Source: https://learn.microsoft.com/en-us/windows/wsl/install-manual

Source: https://learn.microsoft.com/en-us/windows/wsl/installs

Source: https://docs.docker.com/desktop/setup/install/windows-install/

Source: https://k3d.io/stable/#releases


If you enjoyed my articles and would like to see more, and are able to contribute, leave the amount you wish below