Skip to content

Instantly share code, notes, and snippets.

View rlevchenko's full-sized avatar
🏠
Working from home

Roman Levchenko rlevchenko

🏠
Working from home
View GitHub Profile
@rlevchenko
rlevchenko / kafka-k8s-acls
Last active January 26, 2024 18:43
Kafka on Kubernetes: how to enable ACL
# New ENV variables for Kafka containers
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "false"
KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.authorizer.AclAuthorizer
KAFKA_SUPER_USERS: User:ANONYMOUS;User:admin
# Why ANONYMOUS? If KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND is set to false and ANONYMOUS user is not in super users list,
# kafka interconnection between brokers will fail.
# Kafka brokers use non-secured listener for communication (in my case) and do not require authentication.
# In contrast, external listener uses SASL.
@rlevchenko
rlevchenko / terraform: count and for_each
Last active January 22, 2024 14:03
Terraform: count and for_each examples
# Example with for_each
resource "aws_route53_record" "acm" {
for_each = {
for dvo in aws_acm_certificate.default.domain_validation_options : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
type = dvo.resource_record_type
}
}
@rlevchenko
rlevchenko / move-ch-data
Last active October 12, 2023 11:40
Move ClickHouse data to a new partition or device
# Create partition
lsblk # get dev name
fdisk /dev/sdb # use 8e type, other settings are default
lsblk # check
pvcreate /dev/sdb1 # create a volume
pvdisplay # check volumes
vgcreate clickhouse /dev/sdb1 # create a volume group
lvcreate --name data -l 100%FREE clickhouse # create a logical volume
mkfs.ext4 /dev/clickhouse/data # make ext4 fs
@rlevchenko
rlevchenko / tcpdump-examples
Last active September 1, 2023 09:58
Tcpdump Examples
# Capture events on specific interface and filter them by grepping request
tcpdump -i ens192 -s 0 -A -v -n | egrep -i -A 5 -B 5 "*request*"
# Capture HTTP GET and POST requests
tcpdump -i ens192 -s 0 -v -n | egrep -i "POST /|GET /|Host:"
# Capture ALL POST requests (using ASCII)
tcpdump -i ens192 -s 0 -A 'tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504F5354'
# Capture requests to 80 and 443 ports from 10.200.217.3 host
## Blog Post: https://rlevchenko.com/2022/12/19/python-coding-fizzbuzz-challenge/
import matplotlib.pyplot as plt
import colorama
from colorama import Fore, Back, Style
colorama.init()
def fizz_buzz(x,y):
"""Python version of popular Fizz Buzz task"""
fb = 0 ; b = 0; f = 0; rest = 0 # start values
function Get-FizzBuzz {
<#
.SYNOPSIS
Fizz Buzz function
.Description
The Fizz Buzz function to find numbers divisible by 3/5 or both
.PARAMETER Start
# decrypt archive backed up with pgp
cat $SECRET | gpg --quiet --batch --pinentry-mode loopback --passphrase-fd 0 --decrypt $SOURCE_BACKUP_FILE | tee $TARGET_FOLDER/env1-to-env2.gz
# drop the DB. why? just "--drop" does not drop collections that are not in the backup!
mongosh --quiet --host localhost:27017 \
-u username -p $PASSWORD --authenticationDatabase=db1 \
--eval 'use db1;' --eval 'db.dropDatabase();'
# Update Base64 version. Required.
apk add --no-cache --update coreutils=8.32-r2
# Encode
base64 -w 0 script.sql | vault kv put mysecrets/db script=-
# Decode
vault kv get -field=script mysecrets/db | base64 --decode --ignore-garbage > ./script.sql