Skip to content

Instantly share code, notes, and snippets.

@upodroid
Last active February 12, 2020 12:28
Show Gist options
  • Save upodroid/f1fdca150918131f7d2fea0453c89729 to your computer and use it in GitHub Desktop.
Save upodroid/f1fdca150918131f7d2fea0453c89729 to your computer and use it in GitHub Desktop.
Useful gcloud snippets

Useful snippets

gcloud / kubernetes

$(gcloud info --format='value(config.project)') Quick way to get project vars

logs in cli gcloud logging read "SOME FILTER" --project SOME-PROJECT --format json | jq 'reverse[] | .textPayload ' --raw-output -j

Give yourself cluster admin role

kubectl create clusterrolebinding "cluster-admin-$(whoami)" \
  --clusterrole=cluster-admin \
  --user="$(gcloud config get-value core/account)"

Portforwarding RDP or anything else via SSH

ssh -L 33899:[SERVER_IP]:3389 [BASTION-HOST]

Utility pods

DB DEBUG

kubectl run psqlclient --rm --tty -i --image bitnami/postgresql --command -- psql --host postgres-proxy -U [USER] --password [PASSWORD]

GDM Checklist

PKI + OpenSSL

Find subjects of all CAs

awk -v cmd='openssl x509 -noout -subject' '
    /BEGIN/{close(cmd)};{print | cmd}' < /etc/ssl/certs/ca-certificates.crt 

Display Contents of a Cert

openssl x509 -in [CERT] -text -noout

Cert gen + Sign

openssl ecparam -out privatekey.key -name prime256v1 -genkey
openssl req -new -x509 -days 365 -key ca.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=Acme Root CA" -out ca.crt

openssl req -newkey rsa:2048 -nodes -keyout server.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=[HOSTNAME]" -out server.csr
openssl x509 -req -extfile <(printf "subjectAltName=DNS:[HOSTNAME]") -days 365 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt

Travis CI

Google Service Account Generation, paste the output to an Env variable and select don't display it.

base64 --wrap=0 FILENAME.json

Chmod issues in Git

git update-index --chmod=+x [PATH]

GCP SSH Button IP Source Ranges:

dig +qr +short txt `dig +short TXT _spf.google.com | grep -oE 'include:\S*' | cut -d':' -f2 | xargs` | grep -oE 'ip[46]:\S*' | sort | uniq`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment