Skip to content

Instantly share code, notes, and snippets.

View gswallow's full-sized avatar

Greg Swallow gswallow

  • Indianapolis, IN, USA
View GitHub Profile
@gswallow
gswallow / get-em.sh
Created October 11, 2023 19:56
quick and dirty inventory of EC2 instances in response to CVE-2023-38545
#!/bin/bash
myaccount=$(eval echo $(aws sts get-caller-identity --query 'Account'))
aws ec2 describe-instances --region us-east-1 --query 'Reservations[].Instances[].{"KeyName": KeyName, "ImageId": ImageId, "PrivateIpAddress": PrivateIpAddress, "Name": Tags[?Key == `Name`]|[0].Value, "Region": `us-east-1` }' --output text | tr -s '\t' '|' >> .$myaccount.csv.$$
aws ec2 describe-instances --region us-east-2 --query 'Reservations[].Instances[].{"KeyName": KeyName, "ImageId": ImageId, "930604620050PrivateIpAddress": PrivateIpAddress, "Name": Tags[?Key == `Name`]|[0].Value, "Region": `us-east-2` }' --output text | tr -s '\t' '|' >> .$myaccount.csv.$$
aws ec2 describe-instances --region us-west-1 --query 'Reservations[].Instances[].{"KeyName": KeyName, "ImageId": ImageId, "PrivateIpAddress": PrivateIpAddress, "Name": Tags[?Key == `Name`]|[0].Value, "Region": `us-west-1` }' --output text | tr -s '\t' '|' >> .$myaccount.csv.$$
aws ec2 describe-instances --region us-west-2 --query 'Reservations[].Instances[].{"KeyNa
@gswallow
gswallow / git.tf
Last active April 6, 2023 14:49
Git info for terraform states
terraform {
required_providers {
external = {
source = "hashicorp/external"
version = "~> 2"
}
}
}
data "external" "git_remote_url" {
@gswallow
gswallow / get-events-by-pod-name-fragment.sh
Last active February 2, 2023 21:24
Get events by pod name (or a fragment thereof)
#!/bin/bash
pod_name=$1
while true; do
kubectl get events --sort-by='.lastTimestamp' \
-ojson \
| jq -r '.items[] | select((.involvedObject.name | contains("'$pod_name'")) and (.involvedObject.kind=="Pod")) | "\(.lastTimestamp) [\(.count)] \(.message)"'
echo
echo "---------"
echo
"metrics": {
...
"disk": {
"measurement": [
"used_percent",
"inodes_free"
],
"metrics_collection_interval": 60,
"resources": [
"*"
@gswallow
gswallow / rdp.sh
Last active March 16, 2022 23:12
Microsoft RDP client for mac pisses me off
#!/bin/bash -e
host=$1; shift
uri="rdp://full%20address=s:$host"
# Redirect
uri="${uri}&redirectdrives=i:1"
uri="${uri}&redirectclipboard=i:1"
@gswallow
gswallow / k8s-create-ns.sh
Last active March 16, 2022 23:12
Creates a namespace and an admin-level account for that namespace.
#!/bin/bash
if [ "$(uname -s)" == "Darwin" ]; then
b64="base64 -D"
else
b64="base64"
fi
project_name=$1
#!/usr/bin/env python
import sys
import string
import datetime
import matplotlib.pyplot as plt
with open(sys.argv[1], 'r') as f:
metrics = f.readlines()
labels = metrics[2].split()[2:]
@gswallow
gswallow / Dockerfile
Created November 18, 2021 14:51
Janky Jenkins Docker Setup
FROM jenkins/jenkins:2.303.3-jdk11
USER root
RUN apt-get update && apt-get install -y lsb-release
RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc \
https://download.docker.com/linux/debian/gpg
RUN echo "deb [arch=$(dpkg --print-architecture) \
signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \
https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list
RUN apt-get update && apt-get install -y docker-ce-cli
Error: Error when reading or editing Resource xxx for IAM Member (role "serviceAccount:service-508170527894@container-engine-robot.iam.gserviceaccount.com", "roles/cloudkms.cryptoKeyEncrypterDecrypter"): Request "Delete IAM Members roles/cloudkms.cryptoKeyEncrypterDecrypter serviceAccount:service-508170527894@container-engine-robot.iam.gserviceaccount.com for \"project \\\"xxx\\\"\"" returned error: Batch request and retried single request "Delete IAM Members roles/cloudkms.cryptoKeyEncrypterDecrypter serviceAccount:service-508170527894@container-engine-robot.iam.gserviceaccount.com for \"project \\\"xxx\\\"\"" both failed. Final error: Error retrieving IAM policy for project "xxx": googleapi: Error 401: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
More details:
Reason: authError, Message: Invalid Credentials
@gswallow
gswallow / aws_billing_pdf.py
Created December 12, 2020 22:18
AWS: Generate a monthly-bill-by-account PDF
#!/usr/bin/env python
import boto3
import math
from io import BytesIO
from pdfdocument.document import PDFDocument
start_date='2020-11-01'
end_date='2020-12-01'