Skip to content

Instantly share code, notes, and snippets.

View tylertreat's full-sized avatar

Tyler Treat tylertreat

View GitHub Profile
@tylertreat
tylertreat / cache.py
Created April 29, 2014 21:05
Python Redis Cache
import cPickle
import logging
import redis
TIMEOUT = 60 * 60
_redis = None
@tylertreat
tylertreat / GCPAuthenticationInterceptor.java
Created January 25, 2019 16:45
Spring RestTemplate interceptor which can make HTTP requests to Google OIDC-authenticated resources using a service account
package com.realkinetic.gcp.spring.oidc;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.google.api.client.http.*;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonObjectParser;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.GenericData;
@tylertreat
tylertreat / server-a.yaml
Created December 29, 2021 03:09
Liftbridge configs
port: 9292
logging.level: debug
logging.recovery: true
#logging.raft: true
#logging.nats: true
data.dir: /tmp/liftbridge/server-a
nats.embedded: true
@tylertreat
tylertreat / graph_parser.py
Created June 17, 2021 23:15
Python script for parsing GCP flow log json from BigQuery and outputting DOT format for Graphviz
import json
import os
import sys
def parse(input_file_name, output_file_name):
with open(input_file_name) as f:
data = json.load(f)
vpcs = {}
@tylertreat
tylertreat / query.txt
Created June 17, 2021 23:12
BigQuery query for GCP flow logs graph visualization
SELECT
jsonPayload.CONNECTION.src_ip,
jsonPayload.CONNECTION.dest_ip,
jsonPayload.src_instance.region AS src_region,
jsonPayload.src_instance.zone AS src_zone,
jsonPayload.src_instance.vm_name AS src_vm,
jsonPayload.dest_instance.region AS dest_region,
jsonPayload.dest_instance.zone AS dest_zone,
jsonPayload.dest_instance.vm_name AS dest_vm,
jsonPayload.src_vpc.vpc_name AS src_vpc,
if __name__ == '__main__':
app = create_app()
server = SocketIOServer(
('0.0.0.0', 5000),
SharedDataMiddleware(app, {}),
policy_server=False)
server.serve_forever()
@tylertreat
tylertreat / GCPAuthenticationInterceptor.java
Created January 25, 2019 17:08
Method to exchange JWT for Google-signed OIDC token
private DecodedJWT getGoogleIdToken() throws IOException {
String jwt = getSignedJwt();
final GenericData tokenRequest = new GenericData()
.set("grant_type", JWT_BEARER_TOKEN_GRANT_TYPE)
.set("assertion", jwt);
final UrlEncodedContent content = new UrlEncodedContent(tokenRequest);
final HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
final HttpRequest request = requestFactory
@tylertreat
tylertreat / svc.yaml
Created June 19, 2020 22:07
GKE service with default BackendConfig
apiVersion: v1
kind: Service
metadata:
name: web
namespace: default
annotations:
beta.cloud.google.com/backend-config: '{"default": "config-default"}'
spec:
ports:
- port: 8080
@tylertreat
tylertreat / backend-config.yaml
Created June 19, 2020 21:57
GKE BackendConfig for enabling IAP
apiVersion: cloud.google.com/v1beta1
kind: BackendConfig
metadata:
name: config-default
namespace: default
spec:
iap:
enabled: true
oauthclientCredentials:
secretName: iap-oauth-client-id
@tylertreat
tylertreat / ingress.yaml
Created June 19, 2020 21:32
GKE ingress with static IP and managed certificate
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: basic-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: "web-static-ip"
networking.gke.io/managed-certificates: "iap-demo"
spec:
backend:
serviceName: web