Good Starter Cloud Init Config

Do you want a good starter cloud init config? Here is an example: #cloud-config users: - name: user groups: users, admin sudo: ALL=(ALL) NOPASSWD:ALL shell: /bin/bash ssh_authorized_keys: - <update with public ssh key> chpasswd: list: | root:<secure-password-here> expire: False packages: - fail2ban - ufw package_update: true package_upgrade: true runcmd: - printf "[sshd]\nenabled = true\nbanaction = iptables-multiport" > /etc/fail2ban/jail.local - systemctl enable fail2ban - ufw default deny incoming - ufw default allow outgoing - ufw allow 2022/tcp - ufw enable - sed -i -e '/^\(#\|\)PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config - sed -i -e '/^\(#\|\)Port 22/s/^.*$/Port 2022/' /etc/ssh/sshd_config - sed -i -e '/^\(#\|\)PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config - sed -i -e '/^\(#\|\)KbdInteractiveAuthentication/s/^.*$/KbdInteractiveAuthentication no/' /etc/ssh/sshd_config - sed -i -e '/^\(#\|\)ChallengeResponseAuthentication/s/^.*$/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config - sed -i -e '/^\(#\|\)MaxAuthTries/s/^.*$/MaxAuthTries 2/' /etc/ssh/sshd_config - sed -i -e '/^\(#\|\)AllowTcpForwarding/s/^.*$/AllowTcpForwarding no/' /etc/ssh/sshd_config - sed -i -e '/^\(#\|\)X11Forwarding/s/^.*$/X11Forwarding no/' /etc/ssh/sshd_config - sed -i -e '/^\(#\|\)AllowAgentForwarding/s/^.*$/AllowAgentForwarding no/' /etc/ssh/sshd_config - sed -i -e '/^\(#\|\)AuthorizedKeysFile/s/^.*$/AuthorizedKeysFile .ssh\/authorized_keys/' /etc/ssh/sshd_config - sed -i '$a AllowUsers user' /etc/ssh/sshd_config - systemctl enable ssh - reboot What does it do? ...

October 1, 2024 · 2 min · Alex Popescu

Running a CLI Before Your Main App In Docker

Do you ever want to run a CLI before your main app in Docker? Here is a complicated way to do just that. We need a folder named success_flag that will contain a flag for the main app to know when the cli has finished running. First, we delete any existing success flag that remains: base: build: . container_name: base volumes: - ./success_flag:/success_flag command: bash -c "rm -f /success_flag/cli_success" restart: "no" Second, let’s run the database layer, in this case Postgres (but it can be any database engine). ...

September 19, 2024 · 2 min · Alex Popescu

Linux Login Update Notifier Script With Python

Introduction Do you ever want to get a notification with the number of updates required when logging into XFCE in debian/ubuntu like systems ? There is a simple python script that can do just that. It uses notify-send command and paired with the magic command that returns the update count, we get the next python script: #!/usr/bin/env python3 import os import subprocess # Run the apt-get command and grep the output command = 'apt-get --simulate upgrade | grep "upgraded.*newly installed"' output = subprocess.getoutput(command) # If there's output, send it as a notification, otherwise send a default message if output: os.system(f'notify-send "Upgrade Check" "{output}"') else: os.system('notify-send "Upgrade Check" "No upgrades available or no packages to be installed."') # Check if the file /var/run/reboot-required exists reboot_file = '/var/run/reboot-required' if os.path.exists(reboot_file): os.system('notify-send "System Update" "Reboot is required to complete updates."') All you need is to make it executable: ...

August 29, 2024 · 2 min · Alex Popescu

Environment variables at build time with Docker

Introduction Do you need a certain environment variable at build time in Docker as opposed to runtime? There is an easy way to achieve this. Use Docker build arguments in combination with environment variables. An example of this is below of a React JS docker build that needs the environment variable REACT_APP_BACKEND_API and build time in the command npm run build. # Declare the build argument in the global scope ARG REACT_APP_BACKEND_API_ARG=TEST # Use an official Node runtime as a parent image FROM node:20-alpine # Set the working directory WORKDIR /app # Copy package.json and package-lock.json COPY package*.json ./ # Install the dependencies RUN npm install # Copy the rest of the application code COPY . . # Consume the build argument in the build stage ARG REACT_APP_BACKEND_API_ARG ENV REACT_APP_BACKEND_API=${REACT_APP_BACKEND_API_ARG} RUN echo $REACT_APP_BACKEND_API # Build the React app # WE need the env variable to be available at BUILD TIME RUN npm run build # Serve the app using serve RUN npm install -g serve # Expose the port the app runs on EXPOSE 3000 # Command to run the app CMD ["serve", "-s", "build", "-l", "3000"] The trick is to declare a build argument REACT_APP_BACKEND_API_ARG, use it in a stage and set the value of the required environment variable (in this case REACT_APP_BACKEND_API_ARG) to the argument value (${REACT_APP_BACKEND_API_ARG}) ...

August 1, 2024 · 2 min · Alex Popescu

Build Go with AIX

Introduction Did you ever wanted to program go in AIX ? Now you can. Installing GoLang on AIX First, add /opt/freeware/bin to the beginning of the current PATH. For example: export PATH=/opt/freeware/bin:$PATH Next install Go on AIX (and increase /opt and /var sizes if needed): chfs -a size=+512M /opt chfs -a size=+260M /var dnf install golang Create a sample program Next, let’s create a sample Go Hello World program: package main import "fmt" func main() { fmt.Println("hello world") } Building and running the program First, lets’s initialize the main module ...

July 19, 2024 · 1 min · Alex Popescu

Ubuntu Desktop with XRDP: A Quick Guide

Introduction Have you ever wanted to install Ubuntu Desktop and configure it with XRDP? Here’s a short guide to get you through it. Step 1: Installing Ubuntu Desktop Let’s start by installing Ubuntu Desktop. Just run this command: sudo apt -y install ubuntu-desktop Grab a coffee while your terminal goes wild with text. It takes some time for the packages to install. Step 2: Installing XRDP Next, install XRDP to allow remote access: ...

June 15, 2024 · 1 min · Alex Popescu

Azure AD Authentication for C# WebAPI with Swagger

Introduction Have you ever wanted to add Azure AD authentication to a C# WebApi project for .NET 8? Now you can. The Code First, let’s create a new WebAPI project: dotnet new webapi --use-controllers Next, add the required package: dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer Next, we need to add the Azure AD settings in appsettings.json: "AzureAd": { "Instance": "https://login.microsoftonline.com/", "TenantId": "yyyy", "ClientId": "xxxxx" } Replace yyyy with the correct TenantId and xxxxx with the correct Azure SPN Client Id. ...

April 23, 2024 · 2 min · Alex Popescu

Automated Fake Database Population with Python

Introduction In this article, we’ll explore a Python script that leverages mimesis library to populate an (Azure) SQL database with fake data. The Code import logging import random import pandas as pd import pymssql import sqlalchemy from dotenv import dotenv_values from mimesis import Address, Datetime, Person from mimesis.enums import Gender from sqlalchemy import create_engine # Load environment variables config = dotenv_values(".env") # Configure logging to both console and file logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s") rootLogger = logging.getLogger() rootLogger.setLevel(logging.INFO) consoleHandler = logging.StreamHandler() consoleHandler.setFormatter(logFormatter) rootLogger.addHandler(consoleHandler) def create_rows_mimesis(num=1): gender = random.choice([Gender.FEMALE, Gender.MALE]) output = [{"first_name": person.first_name(gender), "last_name": person.last_name(gender), "address": address.address(), "email": person.email(), "city": address.city(), "state": address.state(), "date_time": datetime.datetime(), "randomdata": random.randint(1000, 2000) } for x in range(num)] return output try: # Create SQLAlchemy engine engine = create_engine(config["CONNECTION_STRING"]) # Connect to the database with engine.connect() as conn: logging.info(f"Connected to database: {engine}") # Initialize mimesis objects person = Person('en') address = Address() datetime = Datetime() num_rows = int(config["ROWS"]) rows_per_batch=int(config["INSERT_LIMIT"]) logging.info(f"Generating {num_rows} rows") if num_rows > rows_per_batch: for i in range(0, num_rows, rows_per_batch): batch_df = pd.DataFrame(create_rows_mimesis(min(1000, num_rows - i))) batch_df.to_sql(config["TABLE_NAME"], engine, method='multi', index=False, if_exists='append') logging.info(f"Inserted {min(1000, num_rows - i)} rows into table: {config['TABLE_NAME']}") else: df = pd.DataFrame(create_rows_mimesis(num_rows)) df.to_sql(config["TABLE_NAME"], engine, method='multi', index=False, if_exists='replace') logging.info(f"Inserted {num_rows} rows into table: {config['TABLE_NAME']}") conn.commit() except Exception as e: logging.error(f"An error occurred: {str(e)}") logging.info("Database connection closed.") The packages needed are: ...

March 17, 2024 · 3 min · Alex Popescu

Install NewRelic on JBoss EAP 7

Introduction This tutorial provides a step-by-step guide on installing NewRelic APM on Jboss EAP 7 in standalone mode Download NewRelic Download the current new relic APM from the website, or using the next powershell command: Invoke-WebRequest -Uri https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip -OutFile newrelic-java.zip Configuring Jboss Create a folder named lib in JBOSS_HOME folder, and a new folder named endorsed in the lib folder. In case you are wondering, the JBOSS_HOME is the folder that has Jboss installed, and the folder with the bin/docs/etc folders. ...

February 22, 2024 · 2 min · Alex Popescu

Securing Quarkus Backend App with IBM App ID

Introduction This tutorial provides a step-by-step guide on securing a Quarkus backend application using IBM App ID. Configure IBM App ID Login to IBM Cloud and create an App ID instance using the lite (free) plan. Then create an application as a regular web app. Next, create a test user using Cloud Directory -> Users menu. Configure Quarkus First, update Maven pom.xml : <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-oidc</artifactId> </dependency> Next, find the client ID/secret/login URL in IBM App id application details: ...

December 30, 2023 · 3 min · Alex Popescu