Skip to content

Instantly share code, notes, and snippets.

@salrashid123
salrashid123 / csek_versioning.md
Last active January 24, 2025 14:34
GCS CSEK and object versioning

GCS CSEK with Object versioning

The following will upload a file into a bucket with object versioning.

The file will have a CSEK

Then encrypt it with another CSEK and recall the first version using its original CSEK

### create two cseks
@salrashid123
salrashid123 / pcrgen.go
Last active December 12, 2024 22:03
TPM Policy command parameter generation for PCR
package main
import (
"encoding/binary"
"encoding/hex"
"flag"
"io"
"log"
"net"
"os"
@salrashid123
salrashid123 / diy_sts.md
Last active November 24, 2024 14:15
GCP Authentication with custom STS Server

Simple DIY STS server Google Cloud Application Default Credential

or...how to use ADC and run your own STS token broker

An STS server will exchange one token for another. This protocol is used by GCP Workload Federation.

THis example runs your own STS server with GCP where the STS server accepts a source token, validates it and the returns a gcp access_token

For more information about STS servers, see

@salrashid123
salrashid123 / python_tpm_gcp.md
Last active November 24, 2024 11:54
GCP x509 Workload Federation in pyhton using mTLS and TPM based private key

GCP x509 Workload Federation in python using TPM based authentication and openssl

assume you have a workload federation trusted cert and PEM key (workload3.crt, workload3.key), the following will embed the key into the tpm. Workload federation will use the tpm-based key for mtls.

you can ofcourse create the key inside the tpm or securely import it. those options are described here

Setup TPM tools

@salrashid123
salrashid123 / python_tpm_tls.md
Last active November 21, 2024 21:56
python mtls with TPM based keys and openssl3 provider

Python mTLS client/server with TPM based key

sample client/server webapp in python using mtls where the client key is resident on a trusted platform module

Setup openssl

# on debian 12
@salrashid123
salrashid123 / subjectoken.go
Created November 15, 2024 13:45
Google WorkloadFederation SubjectTokenSupplier sample
/*
simple example of https://pkg.go.dev/golang.org/x/oauth2/google/externalaccount#SubjectTokenSupplier
also see https://github.com/salrashid123/gcp_aws_web_identity
*/
package main
import (
@salrashid123
salrashid123 / gcp_softhsm.md
Last active November 20, 2024 23:56
GCP Enterprise Cert Proxy with SoftHSM

GCP Enterprise Certificate Proxy with SoftHSM

setup of Google Proxies for Enterprise Certificates (GA) with SoftHSM

This sample will embed a device certificate and key into SoftHSM and then access softHSM for mTLS using the GCP proxy.

A default GCS client uses the enterprise proxy transparently to access gcp resources via mTLS


@salrashid123
salrashid123 / peer-metadata-parsing.md
Created November 10, 2024 14:44
Parsing `X-Envoy-Peer-Metadata`

Parsing the x-envoy-peer-metadata field.

eg, in istio outbound

{
  "args": {}, 
  "headers": {
    "Accept-Encoding": "gzip", 
    "Host": "httpbin.org", 
@salrashid123
salrashid123 / bq_keyset.md
Last active October 23, 2024 13:26
bq wrapped keyset

BQ wrapped keyset per row

generate wrapped key per user

bq query --nouse_legacy_sql "
DECLARE kms_resource_name STRING;
SET kms_resource_name = 'gcp-kms://projects/srashid-test2/locations/us/keyRings/bqkr/cryptoKeys/k1';
@salrashid123
salrashid123 / iteratesa.go
Created October 23, 2024 09:27
slowly iterate GCP service accounts in an org for last authentication time
package main
// gcloud auth application-default login
// export USER=`gcloud config get-value core/account`
// export PROJECT_ID=`gcloud config get-value core/project`
// export QUOTA_PROJECT=$PROJECT_ID
// export ORGANIZATION_ID="organizations/1111111"
// gcloud services enable policyanalyzer.googleapis.com
// gcloud projects add-iam-policy-binding --role=roles/serviceusage.serviceUsageConsumer --member=user:$USER $QUOTA_PROJECT