Rafael SZP Blog

website·Indexed 29 days ago

https://rafaelszp.github.io/

A technical blog featuring tutorials and guides on OpenSSL certificate generation, Docker and BuildKit, Kubernetes (kubectl), Java 8 design patterns, Arch Linux configuration, and various command-line utilities for SSH, LDAP, and Maven.

Tokens
23.4K
Snippets
188
Records
199
Agent score
75%

What's inside Rafael SZP Blog

  1. Overview of Amazon ECS and Fargate

    Amazon ECS (Elastic Container Service) is an AWS container orchestration service that uses Docker to run applications. When using the AWS Fargate launch type, it is considered a Cloud Native deployment model because it removes the need to manage the underlying infrastructure. ECS integrates natively with IAM for access control and CloudWatch for metrics, logs, and monitoring.
  2. Retrieve logged-in user information from Keycloak

    To get information about the currently authenticated user in Keycloak, perform a GET request to the OpenID Connect userinfo endpoint. You must include the user's access token in the Authorization header as a Bearer token.
    GET http://{SERVER_URL}/auth/realms/{realm}/protocol/openid-connect/userinfo
    Authorization: Bearer {token}
  3. Disable automatic HTTPS redirection in Firefox

    To prevent Firefox from automatically redirecting HTTP requests to HTTPS (HTTPS-First mode and HSTS preloading), modify the following preferences in the about:config editor. After applying these settings, it is recommended to clear all browsing data to remove cached redirects.
    network.stricttransportsecurity.preloadlist = false
    browser.fixup.fallback-to-https = false
    dom.security.https_first = false
    dom.security.https_first_pbm = false
  4. Perform maintenance on a Kubernetes master node

    To safely perform system updates or patches on a Kubernetes master node, follow these steps: 1. Back up the ETCD database to prevent data loss. 2. Drain the node to evict pods. 3. Apply system updates and reboot. 4. Uncordon the node to allow pods to be scheduled on it again.
    # 1. Backup ETCD
    ETCDCTL_API=3 etcdctl --endpoints=https://[127.0.0.1]:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt \
         --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key \
         snapshot save /tmp/snapshot-pre-boot.db
    
    # 2. Drain the node
    kubectl drain <master01>
    
    # [Perform System update | patches and reboot]
    
    # 3. Uncordon the node
    kubectl uncordon <master01>
  5. Publish a third-party Maven JAR to AWS CodeArtifact

    To publish a third-party JAR file to a private AWS CodeArtifact repository, you must first configure your Maven settings.xml to handle authentication using an environment variable for the auth token, and then use the mvn deploy:deploy-file command to upload the artifact.
    # 1. Configure settings.xml
    # Add this to your ~/.m2/settings.xml
    <settings>
        <servers>
            <server>
                <id>codeartifact</id>
                <username>aws</username>
                <password>${env.CODEARTIFACT_AUTH_TOKEN}</password>
            </server>
        </servers>
    </settings>
    
    # 2. Execute the deploy command
    mvn deploy:deploy-file \
    -DgroupId=commons-cli          \
    -DartifactId=commons-cli       \
    -Dversion=1.4                  \
    -Dfile=./commons-cli-1.4.jar   \
    -Dpackaging=jar                \
    -DrepositoryId=codeartifact    \
    -Durl=https://my_domain-111122223333.d.codeartifact.region.amazonaws.com/maven/repo-name/
  6. Change the IP address of a Kubernetes Worker node

    To change the IP address of a worker node, reset the node's local Kubernetes state and update the kubelet configuration to use the new node IP before re-joining the cluster.
    # Reset the worker node
    yes | kubeadm reset
    
    # Set the new IP and update kubelet configuration
    export K8S_NODE_IP=<NEW_IP>
    echo "KUBELET_EXTRA_ARGS="--node-ip=$K8S_NODE_IP"" > /etc/sysconfig/kubelet
    
    # On the Control Plane, generate a new join command
    kubeadm token create --print-join-command
  7. Implement a Focus Mode for Dunst notifications on Linux

    You can create a focus mode that temporarily disables Dunst notifications by sending SIGUSR1 to stop notifications and scheduling a SIGUSR2 signal via the at command to re-enable them after a set duration. This requires the at package, the atd daemon running, and dunst as the active notification daemon.
    #!/bin/sh
    
    SIGNAL=$1
    
    if [ -z $SIGNAL ]; then
      echo "Signal must be provided: on|off"
      exit -127
    fi
    
    if [ $SIGNAL == "on" ]; then
      # Remove any existing scheduled focus-mode tasks
      atrm $(atq -qf | cut -f1) 2> /dev/null || echo $status
      notify-send --urgency=low --expire-time=1000 --category=FOCUS "Focus mode on" "Focus mode Started"
      sleep 1
      # Disable Dunst notifications
      killall -SIGUSR1 dunst 
      # Schedule Dunst to be re-enabled in 50 minutes
      echo "killall -SIGUSR2 dunst" | at -q f now +50 minutes
    else 
      # Manually re-enable Dunst notifications
      killall -SIGUSR2 dunst
      atrm $(atq -qf | cut -f1) 2>/dev/null || echo $status
      notify-send --urgency=low --expire-time=3000 --category=FOCUS "Focus mode off" "Focus mode ended"
    fi
    atq
  8. Disable IPv6 transition technologies to prevent IP leakage on Windows

    To prevent IP address leakage, disable ISATAP, Teredo, and 6to4 transition technologies using the netsh command and disable IPv6 components via the Windows Registry.
    # Disable ISATAP
    netsh int ipv6 isatap set state disabled
    
    # Disable Teredo
    netsh int teredo set state disabled 
    
    # Disable 6to4
    netsh interface ipv6 6to4 set state state=disabled undoonstop=disabled 
    
    # Disable IPv6 components via Registry
    reg add "HKLM\System\CurrentControlSet\Services\Tcpip6\Parameters" /v "DisabledComponents" /t REG_DWORD /d "255" /f
  9. Schedule ECS Tasks using EventBridge or On-Demand

    There are two primary ways to trigger tasks outside of a continuous service:

    • Regular Scheduling: Use Amazon EventBridge to trigger tasks at specific times. Ensure EventBridge has the necessary IAM permissions to execute the tasks.
    • On-Demand Execution: Run tasks as standalone instances without a service scheduler. This is ideal for testing or one-off executions. Note: Depending on the network mode, you must provide the desired VPC details.